Mysql Commands
Mysql Commands
create table student( student_id int, name varchar (20), major varchar(20),primary
key (student_id);
describe student;
drop table_name;
start------------------------->>>>>>>>>>>>>>>>
mysql> select count(emp_id) from employee where sex='F' and birthday > '1973-04-
22';
mysql> update student set percentage = (case id when 3 then 456 when 4 then 78 end)
where id in(3,4);
* arithmatic function *
mysql> select id,name,(percentage +5) as PERCENTAGE from student;
mysql> select id,name,(percentage * 5) as PERCENTAGE from student;
mysql> select pi(),floor(4.5),round(4.6),ceil(6.7),abs(78.34)gives absolute value;
mysql> select pi(),sqrt(16);
mysql> select round(rand() *10);
mysql> select floor(7 + rand()*100);
* string function *
mysql> select name,id,character_length(name) as characters from student;
mysql> select id ,concat(name,percentage) as name from student;
mysql> select concat_ws(' ','hem','raj','lak','hara') as name ;
mysql> select ltrim(' hemraj ') as name ;
+-------------------------------+
| name |
+-------------------------------+
| hemraj |
+-------------------------------+
mysql> select instr('yahoo jaba java','jav') as name;
+------+
| name |
+------+
| 12 |
+------+
mysql> select left ("yahoo baba",3) as name;
+------+
| name |
+------+
| yah |
+------+
mysql> select format(3.454332,4) as digit;
+--------+
| digit |
+--------+
| 3.4543 |
+--------+
----------------------Alter commands-----------------------
mysql> alter table student add grade varchar(10);{ to add new column}
mysql> alter table student_data add grade varchar(10) AFTER STUDENT_NAME;
mysql> alter table student drop column grade ;{to drop the existed column}
mysql> alter table student modify name char(20);{ modify column datatype}
mysql> alter table student_data add unique(id);
mysql> alter table student change name STUDENT_NAME VARCHAR(20);{RANAME COLUMN
NAME}
mysql> ALTER TABLE STUDENT RENAME STUDENT_DATA;{TO CHANGE THE TABLE NAME}