0% found this document useful (0 votes)
25 views6 pages

Office

Uploaded by

vasu18ch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views6 pages

Office

Uploaded by

vasu18ch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

**

Welcome to the MySQL monitor. Commands end with ; or \g.


Your MySQL connection id is 10
Server version: 5.5.46 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create table emp (empid int,ename varchar(20),doj int,city


varchar(20),salary int,comm int, deptno int);
ERROR 1046 (3D000): No database selected
mysql> create database office;
ERROR 1007 (HY000): Can't create database 'office'; database exists
mysql> use office;
Database changed
mysql> select*from emp;
+-------+--------+------------+---------+--------+------+--------+
| empid | ename | doj | city | salary | comm | status |
+-------+--------+------------+---------+--------+------+--------+
| 1011 | shivam | 2012-05-26 | delhi | 40800 | NULL | NULL |
| 1013 | Dhruv | 2010-07-22 | Kolkata | 54000 | 2400 | NULL |
| 1014 | Shreya | 2015-10-20 | Delhi | 34800 | 1200 | NULL |
| 1015 | Mansi | 2014-02-05 | Chennai | 43200 | NULL | NULL |
| 1017 | Shilpa | 2012-04-12 | Mumbai | 30000 | NULL | NULL |
| 1018 | Rohit | 2016-11-15 | Delhi | 56400 | 1400 | NULL |
| 1019 | Paul | 2014-06-08 | Chennai | 52800 | NULL | NULL |
| 1020 | Gloria | 2015-03-18 | Delhi | 72000 | 0 | NULL |
+-------+--------+------------+---------+--------+------+--------+
8 rows in set (0.00 sec)

mysql> drop table emp;


Query OK, 0 rows affected (0.00 sec)

mysql> create table emp (empid int,ename varchar(20),doj int,city


varchar(20),salary int,comm int, deptno int);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into emp values("1011",shivam,"2012-05-26",delhi,34000,n


ull,"10");
ERROR 1054 (42S22): Unknown column 'shivam' in 'field list'
mysql> insert into emp values(1011,"shivam","2012-05-26","delhi",34000
,null,10);
ERROR 1265 (01000): Data truncated for column 'doj' at row 1
mysql> insert into emp values(1011,"shivam","2012-05-26","delhi",34000,null,10);
ERROR 1265 (01000): Data truncated for column 'doj' at row 1
mysql> drop table emo;
ERROR 1051 (42S02): Unknown table 'emo'
mysql> drop table emp;
Query OK, 0 rows affected (0.00 sec)

mysql> create table emp (empid int,ename varchar(20),doj date,city var


char(20),salary int,comm int, deptno int);
Query OK, 0 rows affected (0.01 sec)
mysql> insert into emp values(1011,"shivam","2012-05-26","delhi",34000
,null,10);
Query OK, 1 row affected (0.00 sec)

mysql> insert into emp values(1012,"Kartik","2014-01-31","Mumbai",48000,null,30);


Query OK, 1 row affected (0.00 sec)

mysql> insert into emp values(1013,"Dhruv","2010-07-22","Kolkata",45000,2400,20);


Query OK, 1 row affected (0.00 sec)

mysql> insert into emp values(1014,"Shreya","2015-10-20","Delhi",29000,1200,20);


Query OK, 1 row affected (0.00 sec)

mysql> insert into emp values(1015,"Mansi","2014-02-05","Chennai",36000,null,10);


Query OK, 1 row affected (0.00 sec)

mysql> insert into emp values(1016,"Manoj","2016-12-01","Kolkata",51000,0,30);


Query OK, 1 row affected (0.00 sec)

mysql> insert into emp values(1017,"Shilpa","2012-04-12","Mumbai",25000,null,30);


Query OK, 1 row affected (0.00 sec)

mysql> insert into emp values(1018,"Rohit","2016-11-15","Delhi",47000,1400,10);


Query OK, 1 row affected (0.00 sec)

mysql> insert into emp values(1019,"Paul","2014-06-08","Chennai",42000,null,20);


Query OK, 1 row affected (0.00 sec)

mysql> insert into emp values(1020,"Gloria","2015-03-18","Delhi",60000,0,10);


Query OK, 1 row affected (0.00 sec)

mysql> select*from emp;


+-------+--------+------------+---------+--------+------+--------+
| empid | ename | doj | city | salary | comm | deptno |
+-------+--------+------------+---------+--------+------+--------+
| 1011 | shivam | 2012-05-26 | delhi | 34000 | NULL | 10 |
| 1012 | Kartik | 2014-01-31 | Mumbai | 48000 | NULL | 30 |
| 1013 | Dhruv | 2010-07-22 | Kolkata | 45000 | 2400 | 20 |
| 1014 | Shreya | 2015-10-20 | Delhi | 29000 | 1200 | 20 |
| 1015 | Mansi | 2014-02-05 | Chennai | 36000 | NULL | 10 |
| 1016 | Manoj | 2016-12-01 | Kolkata | 51000 | 0 | 30 |
| 1017 | Shilpa | 2012-04-12 | Mumbai | 25000 | NULL | 30 |
| 1018 | Rohit | 2016-11-15 | Delhi | 47000 | 1400 | 10 |
| 1019 | Paul | 2014-06-08 | Chennai | 42000 | NULL | 20 |
| 1020 | Gloria | 2015-03-18 | Delhi | 60000 | 0 | 10 |
+-------+--------+------------+---------+--------+------+--------+
10 rows in set (0.00 sec)

mysql> alter table emp add status char(20);


Query OK, 10 rows affected (0.01 sec)
Records: 10 Duplicates: 0 Warnings: 0

mysql> select*from emp;


+-------+--------+------------+---------+--------+------+--------+--------+
| empid | ename | doj | city | salary | comm | deptno | status |
+-------+--------+------------+---------+--------+------+--------+--------+
| 1011 | shivam | 2012-05-26 | delhi | 34000 | NULL | 10 | NULL |
| 1012 | Kartik | 2014-01-31 | Mumbai | 48000 | NULL | 30 | NULL |
| 1013 | Dhruv | 2010-07-22 | Kolkata | 45000 | 2400 | 20 | NULL |
| 1014 | Shreya | 2015-10-20 | Delhi | 29000 | 1200 | 20 | NULL |
| 1015 | Mansi | 2014-02-05 | Chennai | 36000 | NULL | 10 | NULL |
| 1016 | Manoj | 2016-12-01 | Kolkata | 51000 | 0 | 30 | NULL |
| 1017 | Shilpa | 2012-04-12 | Mumbai | 25000 | NULL | 30 | NULL |
| 1018 | Rohit | 2016-11-15 | Delhi | 47000 | 1400 | 10 | NULL |
| 1019 | Paul | 2014-06-08 | Chennai | 42000 | NULL | 20 | NULL |
| 1020 | Gloria | 2015-03-18 | Delhi | 60000 | 0 | 10 | NULL |
+-------+--------+------------+---------+--------+------+--------+--------+
10 rows in set (0.00 sec)

mysql> update emp set salary=44000;


Query OK, 10 rows affected (0.00 sec)
Rows matched: 10 Changed: 10 Warnings: 0

mysql> select*from emp;


+-------+--------+------------+---------+--------+------+--------+--------+
| empid | ename | doj | city | salary | comm | deptno | status |
+-------+--------+------------+---------+--------+------+--------+--------+
| 1011 | shivam | 2012-05-26 | delhi | 44000 | NULL | 10 | NULL |
| 1012 | Kartik | 2014-01-31 | Mumbai | 44000 | NULL | 30 | NULL |
| 1013 | Dhruv | 2010-07-22 | Kolkata | 44000 | 2400 | 20 | NULL |
| 1014 | Shreya | 2015-10-20 | Delhi | 44000 | 1200 | 20 | NULL |
| 1015 | Mansi | 2014-02-05 | Chennai | 44000 | NULL | 10 | NULL |
| 1016 | Manoj | 2016-12-01 | Kolkata | 44000 | 0 | 30 | NULL |
| 1017 | Shilpa | 2012-04-12 | Mumbai | 44000 | NULL | 30 | NULL |
| 1018 | Rohit | 2016-11-15 | Delhi | 44000 | 1400 | 10 | NULL |
| 1019 | Paul | 2014-06-08 | Chennai | 44000 | NULL | 20 | NULL |
| 1020 | Gloria | 2015-03-18 | Delhi | 44000 | 0 | 10 | NULL |
+-------+--------+------------+---------+--------+------+--------+--------+
10 rows in set (0.00 sec)

mysql> drop table emp;


Query OK, 0 rows affected (0.01 sec)

mysql> create table emp (empid int,ename varchar(20),doj date,city


varchar(20),salary int,comm int, deptno int);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into emp values(1011,"Shivam","2012-05-26","Delhi",34000,null,10);


Query OK, 1 row affected (0.00 sec)

mysql> insert into emp values(1012,"Kartik","2014-01-31","Mumbai",48000,null,30);


Query OK, 1 row affected (0.00 sec)

mysql> insert into emp values(1013,"Dhruv","2010-07-22","Kolkata",45000,2400,20);


Query OK, 1 row affected (0.00 sec)

mysql> insert into emp values(1014,"Shreya","2015-10-20","Delhi",29000,1200,20);


Query OK, 1 row affected (0.00 sec)

mysql> insert into emp values(1015,"Mansi","2014-02-05","Chennai",36000,null,10);


Query OK, 1 row affected (0.00 sec)

mysql> insert into emp values(1016,"Manoj","2016-12-01","Kolkata",51000,0,30);


Query OK, 1 row affected (0.00 sec)

mysql> insert into emp values(1017,"Shilpa","2012-04-12","Mumbai",25000,null,30);


Query OK, 1 row affected (0.00 sec)
mysql> insert into emp values(1018,"Rohit","2016-11-15","Delhi",47000,1400,10);
Query OK, 1 row affected (0.00 sec)

mysql> insert into emp values(1019,"Paul","2014-06-08","Chennai",42000,null,20);


Query OK, 1 row affected (0.00 sec)

mysql> insert into emp values(1020,"Gloria","2015-03-18","Delhi",60000,0,10);


Query OK, 1 row affected (0.00 sec)

mysql> select*from emp;


+-------+--------+------------+---------+--------+------+--------+
| empid | ename | doj | city | salary | comm | deptno |
+-------+--------+------------+---------+--------+------+--------+
| 1011 | Shivam | 2012-05-26 | Delhi | 34000 | NULL | 10 |
| 1012 | Kartik | 2014-01-31 | Mumbai | 48000 | NULL | 30 |
| 1013 | Dhruv | 2010-07-22 | Kolkata | 45000 | 2400 | 20 |
| 1014 | Shreya | 2015-10-20 | Delhi | 29000 | 1200 | 20 |
| 1015 | Mansi | 2014-02-05 | Chennai | 36000 | NULL | 10 |
| 1016 | Manoj | 2016-12-01 | Kolkata | 51000 | 0 | 30 |
| 1017 | Shilpa | 2012-04-12 | Mumbai | 25000 | NULL | 30 |
| 1018 | Rohit | 2016-11-15 | Delhi | 47000 | 1400 | 10 |
| 1019 | Paul | 2014-06-08 | Chennai | 42000 | NULL | 20 |
| 1020 | Gloria | 2015-03-18 | Delhi | 60000 | 0 | 10 |
+-------+--------+------------+---------+--------+------+--------+
10 rows in set (0.00 sec)

mysql> update emp set salary=44000 where ename="paul";


Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> delete from emp where empid=1011,1016;


ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '1016' at
line 1
mysql> delete from emp where empid=1011 or empid=1016;
Query OK, 2 rows affected (0.00 sec)

mysql> update emp set salary=salary+(salary*20/1000;


ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '' at
line 1
mysql> update emp set salary=salary+(salary*20/1000);
Query OK, 8 rows affected (0.00 sec)
Rows matched: 8 Changed: 8 Warnings: 0

mysql> select*from emp where comm>0;


+-------+--------+------------+---------+--------+------+--------+
| empid | ename | doj | city | salary | comm | deptno |
+-------+--------+------------+---------+--------+------+--------+
| 1013 | Dhruv | 2010-07-22 | Kolkata | 45900 | 2400 | 20 |
| 1014 | Shreya | 2015-10-20 | Delhi | 29580 | 1200 | 20 |
| 1018 | Rohit | 2016-11-15 | Delhi | 47940 | 1400 | 10 |
+-------+--------+------------+---------+--------+------+--------+
3 rows in set (0.00 sec)

mysql> select*from emp where doj="2014-01-01",doj="2014-12-31";


ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'doj="2014-12-31"' at line 1
mysql> select*from emp where doj<"2014-01-01" and doj>"2014-12-31";
Empty set (0.00 sec)

mysql> select*from emp where doj>="2014-01-01" and doj<="2014-12-31";


+-------+--------+------------+---------+--------+------+--------+
| empid | ename | doj | city | salary | comm | deptno |
+-------+--------+------------+---------+--------+------+--------+
| 1012 | Kartik | 2014-01-31 | Mumbai | 48960 | NULL | 30 |
| 1015 | Mansi | 2014-02-05 | Chennai | 36720 | NULL | 10 |
| 1019 | Paul | 2014-06-08 | Chennai | 44880 | NULL | 20 |
+-------+--------+------------+---------+--------+------+--------+
3 rows in set (0.00 sec)

mysql> select ename,salary where ename like %i_;


ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'where
ename like %i_' at line 1
mysql> select ename,salary where ename like "%i_";
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'where
ename like "%i_"' at line 1
mysql> select ename,salary where ename like "%i_";
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'where
ename like "%i_"' at line 1
mysql> select ename,salary from emp where ename like "%i_";
+--------+--------+
| ename | salary |
+--------+--------+
| Kartik | 48960 |
| Rohit | 47940 |
| Gloria | 61200 |
+--------+--------+
3 rows in set (0.00 sec)

mysql> select distinct city from emp;


+---------+
| city |
+---------+
| Mumbai |
| Kolkata |
| Delhi |
| Chennai |
+---------+
4 rows in set (0.00 sec)

mysql> select*from emp where deptno=10 or deptno=30;


+-------+--------+------------+---------+--------+------+--------+
| empid | ename | doj | city | salary | comm | deptno |
+-------+--------+------------+---------+--------+------+--------+
| 1012 | Kartik | 2014-01-31 | Mumbai | 48960 | NULL | 30 |
| 1015 | Mansi | 2014-02-05 | Chennai | 36720 | NULL | 10 |
| 1017 | Shilpa | 2012-04-12 | Mumbai | 25500 | NULL | 30 |
| 1018 | Rohit | 2016-11-15 | Delhi | 47940 | 1400 | 10 |
| 1020 | Gloria | 2015-03-18 | Delhi | 61200 | 0 | 10 |
+-------+--------+------------+---------+--------+------+--------+
5 rows in set (0.00 sec)

mysql> select*from emp where city="delhi" and salary>40000;


+-------+--------+------------+-------+--------+------+--------+
| empid | ename | doj | city | salary | comm | deptno |
+-------+--------+------------+-------+--------+------+--------+
| 1018 | Rohit | 2016-11-15 | Delhi | 47940 | 1400 | 10 |
| 1020 | Gloria | 2015-03-18 | Delhi | 61200 | 0 | 10 |
+-------+--------+------------+-------+--------+------+--------+
2 rows in set (0.00 sec)

mysql> select ename,city fromemp where city!="mumbai";


ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'where
city!="mumbai"' at line 1
mysql> select ename,city from emp where city!="mumbai";
+--------+---------+
| ename | city |
+--------+---------+
| Dhruv | Kolkata |
| Shreya | Delhi |
| Mansi | Chennai |
| Rohit | Delhi |
| Paul | Chennai |
| Gloria | Delhi |
+--------+---------+
6 rows in set (0.00 sec)

mysql> select*from emp order by doj;


+-------+--------+------------+---------+--------+------+--------+
| empid | ename | doj | city | salary | comm | deptno |
+-------+--------+------------+---------+--------+------+--------+
| 1013 | Dhruv | 2010-07-22 | Kolkata | 45900 | 2400 | 20 |
| 1017 | Shilpa | 2012-04-12 | Mumbai | 25500 | NULL | 30 |
| 1012 | Kartik | 2014-01-31 | Mumbai | 48960 | NULL | 30 |
| 1015 | Mansi | 2014-02-05 | Chennai | 36720 | NULL | 10 |
| 1019 | Paul | 2014-06-08 | Chennai | 44880 | NULL | 20 |
| 1020 | Gloria | 2015-03-18 | Delhi | 61200 | 0 | 10 |
| 1014 | Shreya | 2015-10-20 | Delhi | 29580 | 1200 | 20 |
| 1018 | Rohit | 2016-11-15 | Delhi | 47940 | 1400 | 10 |
+-------+--------+------------+---------+--------+------+--------+
8 rows in set (0.00 sec)

mysql> alter table emp drop deptno;


Query OK, 8 rows affected (0.01 sec)
Records: 8 Duplicates: 0 Warnings: 0

You might also like