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

Cse3a 80 Assgn02

Uploaded by

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

Cse3a 80 Assgn02

Uploaded by

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

CSE3A_80_ASSGN02

mysql> show databases;


+--------------------+
| Database |
+--------------------+
| information_schema |
| cse3A |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.18 sec)

mysql> use cse3A;


Database changed
mysql> create table employee(emp_id int,f_name varchar(20) NOT NULL,l_name
varchar(20),job_type varchar(20),salary int NOT NULL,dept varchar(10),commission
int,manager_id int,PRIMARY KEY(emp_id));
Query OK, 0 rows affected (0.02 sec)

mysql> use cse3A;


Database changed
mysql> show columns from employee;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| emp_id | int(11) | NO | PRI | NULL | |
| f_name | varchar(20) | NO | | NULL | |
| l_name | varchar(20) | YES | | NULL | |
| job_type | varchar(20) | YES | | NULL | |
| salary | int(11) | NO | | NULL | |
| dept | varchar(10) | YES | | NULL | |
| commission | int(11) | YES | | NULL | |
| manager_id | int(11) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
8 rows in set (0.03 sec)

mysql> alter table employee add date_of_joining date;


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

mysql> show columns from employee;


+-----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+-------+
| emp_id | int(11) | NO | PRI | NULL | |
| f_name | varchar(20) | NO | | NULL | |
| l_name | varchar(20) | YES | | NULL | |
| job_type | varchar(20) | YES | | NULL | |
| salary | int(11) | NO | | NULL | |
| dept | varchar(10) | YES | | NULL | |
| commission | int(11) | YES | | NULL | |
| manager_id | int(11) | YES | | NULL | |
| date_of_joining | date | YES | | NULL | |
+-----------------+-------------+------+-----+---------+-------+
9 rows in set (0.00 sec)

mysql> create table department(d_name varchar(20),d_loc varchar(10),HOD_id int,PRIMARY


KEY(d_name));
Query OK, 0 rows affected (0.07 sec)

mysql> show columns from department;


+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| d_name | varchar(20) | NO | PRI | NULL | |
| d_loc | varchar(10) | YES | | NULL | |
| HOD_id | int(11) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

mysql> create table location(loc_id int,city int,contact_no int);


Query OK, 0 rows affected (0.02 sec)

mysql> show columns from location;


+------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------+------+-----+---------+-------+
| loc_id | int(11) | YES | | NULL | |
| city | int(11) | YES | | NULL | |
| contact_no | int(11) | YES | | NULL | |
+------------+---------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> alter table location drop column contact_no;


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

mysql> show columns from location;


+--------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+---------+------+-----+---------+-------+
| loc_id | int(11) | YES | | NULL | |
| city | int(11) | YES | | NULL | |
+--------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> alter table location change column city address varchar(20);


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

mysql> show columns from location;


+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| loc_id | int(11) | YES | | NULL | |
| address | varchar(20) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> alter table location rename to loc;


Query OK, 0 rows affected (0.01 sec)

mysql> insert into loc values(1,'Kolkata');


Query OK, 1 row affected (0.11 sec)

mysql> insert into loc values(2,'Mumbai');


Query OK, 1 row affected (0.00 sec)

mysql> select * from loc;


+--------+---------+
| loc_id | address |
+--------+---------+
| 1 | Kolkata |
| 2 | Mumbai |
+--------+---------+
2 rows in set (0.00 sec)

mysql> truncate table loc;


Query OK, 0 rows affected (0.13 sec)

mysql> show tables;


+-----------------+
| Tables_in_cse3A |
+-----------------+
| department |
| employee |
| loc |
+-----------------+
3 rows in set (0.00 sec)

mysql> drop table loc;


Query OK, 0 rows affected (0.08 sec)

mysql> show tables;


+-----------------+
| Tables_in_cse3A |
+-----------------+
| department |
| employee |
+-----------------+
2 rows in set (0.00 sec)

mysql> insert into department values('Sales','Kol',4);


Query OK, 1 row affected (0.13 sec)

mysql> insert into department values('Accounts','Delhi',6);


Query OK, 1 row affected (0.01 sec)

mysql> insert into department values('Production','Kol',1);


Query OK, 1 row affected (0.00 sec)

mysql> insert into department values('Marketing','Kol',2);


Query OK, 1 row affected (0.00 sec)

mysql> insert into department values('R & D','Marketing',8);


Query OK, 1 row affected (0.00 sec)

mysql> select * from department;


+------------+-----------+--------+
| d_name | d_loc | HOD_id |
+------------+-----------+--------+
| Accounts | Delhi | 6|
| Marketing | Kol | 2|
| Production | Kol | 1|
| R & D | Marketing | 8|
| Sales | Kol | 4|
+------------+-----------+--------+
5 rows in set (0.00 sec)

mysql> select d_name,d_loc from department;


+------------+-----------+
| d_name | d_loc |
+------------+-----------+
| Accounts | Delhi |
| Marketing | Kol |
| Production | Kol |
| R & D | Marketing |
| Sales | Kol |
+------------+-----------+
5 rows in set (0.00 sec)

mysql> insert into employee values(1,'Aamir','Khan','Salesman',15000,5000,'Marketing',2,'2013-01-


11');
Query OK, 1 row affected (0.05 sec)

mysql> insert into employee


values(2,'Arun','Khan','Manager',90000,NULL,'Production',NULL,'1998-01-04');
Query OK, 1 row affected (0.05 sec)

mysql> insert into employee


values(3,'Barun','Kumar','Manager',80000,NULL,'Marketing',NULL,'1998-02-04');
Query OK, 1 row affected (0.02 sec)

mysql> select * from employee; +--------+--------+--------


+----------+--------+------------+------------+------------+-----------------+
| emp_id | f_name | l_name | job_type | salary | commission | dept | manager_id | date_of_joining
|
+--------+--------+--------+----------+--------+------------+------------+------------+-----------------+
| 1 | Aamir | Khan | Salesman | 15000 | 5000 | Marketing | 2 | 2013-01-11 |
| 2 | Arun | Khan | Manager | 90000 | NULL | Production | NULL | 1998-01-04 |
| 3 | Barun | Kumar | Manager | 80000 | NULL | Marketing | NULL | 1998-02-04 |
+--------+--------+--------+----------+--------+------------+------------+------------+-----------------+
3 rows in set (0.01 sec)

mysql> select f_name,l_name,salary,salary+1000 from employee;


+--------+--------+--------+-------------+
| f_name | l_name | salary | salary+1000 |
+--------+--------+--------+-------------+
| Aamir | Khan | 15000 | 16000 |
| Arun | Khan | 90000 | 91000 |
| Barun | Kumar | 80000 | 81000 |
+--------+--------+--------+-------------+
3 rows in set (0.00 sec)

mysql> select f_name as NAME,salary*12 as ANNSAL from employee;


+-------+--------+
| NAME | ANNSAL |
+-------+--------+
| Aamir | 180000 |
| Arun | 1080000 |
| Barun | 960000 |
+-------+--------+
3 rows in set (0.00 sec)

mysql> select l_name as LasT,salary+100 as NewSal from employee;


+-------+--------+
| LasT | NewSal |
+-------+--------+
| Khan | 15100 |
| Khan | 90100 |
| Kumar | 80100 |
+-------+--------+
3 rows in set (0.00 sec)

mysql> select emp_id,f_name,l_name,job_type,salary from employee order by salary desc limit 1;


+--------+--------+--------+----------+--------+
| emp_id | f_name | l_name | job_type | salary |
+--------+--------+--------+----------+--------+
| 2 | Arun | Khan | Manager | 90000 |
+--------+--------+--------+----------+--------+
1 row in set (0.00 sec)

mysql> select emp_id,f_name,l_name,job_type,salary from employee order by salary asc limit 1;


+--------+--------+--------+----------+--------+
| emp_id | f_name | l_name | job_type | salary |
+--------+--------+--------+----------+--------+
| 1 | Aamir | Khan | Salesman | 15000 |
+--------+--------+--------+----------+--------+
1 row in set (0.00 sec)

mysql> select avg(salary) from employee;


+-------------+
| avg(salary) |
+-------------+
| 61666.6667 |
+-------------+
1 row in set (0.00 sec)

You might also like