Advance DBMS

QUERY LANGUAGE

Practical – 01

Name – Tarun Joshi

Student ID – 23711144

Course – MCA.

Semester – II.

Date – 20-Feb-2024.

Objective – Demonstrate the command in Data Definition Language (Create Drop, Alter, Rename, Truncate, Backup).

mysql> create table students(id int, Name varchar(20), course varchar(10));

mysql> describe students;

+--------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+--------+-------------+------+-----+---------+-------+

| id | int | YES | | NULL | |

| Name | varchar(20) | YES | | NULL | |

| course | varchar(10) | YES | | NULL | |

+--------+-------------+------+-----+---------+-------+

mysql> alter table students add Age int;

mysql> insert into students values(1,'Bhavesh','MCA',20);

mysql> insert into students values(2,'Neha','MCA',21);

mysql> insert into students values(3,'Laxman','MCA',22);

mysql> insert into students values(4,'Hema','MCA',22);

mysql> select * from students;

+------+---------+--------+------+

| id | Name | course | Age |

+------+---------+--------+------+

| 1 | Bhavesh | MCA | 20 |

| 2 | Neha | MCA | 21 |

| 3 | Laxman | MCA | 22 |

| 4 | Hema | MCA | 22 |

+------+---------+--------+------+

mysql> alter table students modify column id int not null unique;

mysql> alter table students modify column id int not null unique;

mysql> describe students;

+--------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+--------+-------------+------+-----+---------+-------+

| id | int | NO | PRI | NULL | |

| Name | varchar(20) | YES | | NULL | |

| course | varchar(10) | YES | | NULL | |

| Age | int | YES | | NULL | |

+--------+-------------+------+-----+---------+-------+

mysql> select * from students where Age='22';

+----+--------+--------+------+

| id | Name | course | Age |

+----+--------+--------+------+

| 3 | Laxman | MCA | 22 |

| 4 | Hema | MCA | 22 |

+----+--------+--------+------+

2 rows in set (0.00 sec)

mysql> select * from students where Age>21;

+----+--------+--------+------+

| id | Name | course | Age |

+----+--------+--------+------+

| 3 | Laxman | MCA | 22 |

| 4 | Hema | MCA | 22 |

| 5 | Lax | MCA | 23 |

| 6 | Abhi | MCA | 24 |

| 7 | Naman | MBA | 25 |

+----+--------+--------+------+

5 rows in set (0.00 sec)

mysql> select * from students where Age<21;

+----+---------+--------+------+

| id | Name | course | Age |

+----+---------+--------+------+

| 1 | Bhavesh | MCA | 20 |

+----+---------+--------+------+

1 row in set (0.00 sec)

mysql> select * from students where Age<>23;

+----+---------+--------+------+

| id | Name | course | Age |

+----+---------+--------+------+

| 1 | Bhavesh | MCA | 20 |

| 2 | Neha | MCA | 21 |

| 3 | Laxman | MCA | 22 |

| 4 | Hema | MCA | 22 |

| 6 | Abhi | MCA | 24 |

| 7 | Naman | MBA | 25 |

+----+---------+--------+------+

PRACTICAL – 7

Name:Tarun Joshi

Course: MCA

Student ID:2371114

Objective:- Write SQL queries using logical operations and operators

Code:-

AND Operator-

SELECT * FROM employees WHERE City = "Mumbai" AND Designation = "Project Manager";

E_IDNameSalaryCityDesignationDate_of_JoiningAge
1Sakshi Kumari50000MumbaiProject Manager2021-06-2024
10Mayuri Patel60000MumbaiProject Manager2020-10-0224

2. SQL BETWEEN Operator

SELECT * FROM employees WHERE Salary BETWEEN 50000 AND 90000;

E_IDNameSalaryCityDesignationDate_of_JoiningAge
1Sakshi Kumari50000MumbaiProject Manager2021-06-2024
2Tejaswini Naik75000DelhiSystem Engineer2019-12-2423
4Anushka Tripathi90000MumbaiSoftware Tester2021-06-1324
6Rutuja Deshmukh60000BangaloreManager2019-07-1726
7Swara Baviskar55000JaipurSystem Engineer2021-10-1024
9Swati Kumari50000PuneSoftware Tester2021-01-0125
10Mayuri Patel60000MumbaiProject Manager2020-10-0224
12Shivani Wagh50500DelhiSoftware Developer2016-09-1025
13Kiran Maheshwari50000NashikHR2013-12-1223

3. SQL OR Operator-

SELECT * FROM employees WHERE Designation = "System Engineer" OR City = "Mumbai";

E_IDNameSalaryCityDesignationDate_of_JoiningAge
1Sakshi Kumari50000MumbaiProject Manager2021-06-2024
2Tejaswini Naik75000DelhiSystem Engineer2019-12-2423
4Anushka Tripathi90000MumbaippSoftware Tester2021-06-1324
7Swara Baviskar55000JaipurSystem Engineer2021-10-1024
10Mayuri Patel60000MumbaiProject Manager2020-10-0224

4. SQL IN Operator-

SELECT * FROM employees WHERE City IN ("Mumbai", "Bangalore", "Pune");

E_IDNameSalaryCityDesignationDate_of_JoiningAge
1Sakshi Kumari50000MumbaiProject Manager2021-06-2024
4Anushka Tripathi90000MumbaiSoftware Tester2021-06-1324
5Rucha Jagtap45000BangaloreProject Manager2020-08-0923
6Rutuja Deshmukh60000BangaloreManager2019-07-1726
8Sana Sheik45000PuneSoftware Engineer2020-09-1026
9Swati Kumari50000PuneSoftware Tester2021-01-0125
10Mayuri Patel60000MumbaiProject Manager2020-10-0224
15Mohini Shah38000PuneSoftware Developer2019-03-0520

5. SQL NOT Operator-

SELECT * FROM employees WHERE NOT Designation = "Project Manager";

E_IDNameSalaryCityDesignationDate_of_JoiningAge
2Tejaswini NaikPractical – 0175000DelhiSystem Engineer2019-12-2423
3Anuja Sharma40000JaipurManager2021-08-1526
4Anushka Tripathi90000MumbaiSoftware Tester2021-06-1324
6Rutuja Deshmukh60000BangaloreManager2019-07-1726
7Swara Baviskar55000JaipurSystem Engineer2021-10-1024

PRACTICAL – 5

Name: Tarun Joshi

Course: MCA

Student ID:23711144

Objective:- Write a query to understand the concept for Rollback,Commit and Check points

Code:-

RollBack:-

select* from Emp1;

+----------+--------+---------+

| emp_name | salary | dept_id |

+----------+--------+---------+

| Pradeep | 25000 | 301 |

| Yogesh | 30000 | 302 |

| Anchl | 20000 | 304 |

+----------+--------+---------+

DELETE FROM Emp1 WHERE dept_id = 301;

ROLLBACK;

select * from Emp1;

+----------+--------+---------+

| emp_name | salary | dept_id |

+----------+--------+---------+

| Pradeep | 25000 | 301 |

| Yogesh | 30000 | 302 |

| Anchl | 20000 | 304 |

+----------+--------+---------+

COMMIT;

DELETE FROM Emp1 WHERE dept_id = 304;

select * from Emp1;

+----------+--------+---------+

| emp_name | salary | dept_id |

+----------+--------+---------+

| Pradeep | 25000 | 301 |

| Yogesh | 30000 | 302 |

| Anchl | 20000 | 304 |

+----------+--------+---------+

PRACTICAL – 9

Name: Tarun Joshi

Course: MCA

Student ID:23711144

Objective:- Demonstrate the aggregate function (AVG , MIN, MAX , SUM , COUNT etc).

Code:-

MAX:-

select max(sallary) from student;

+--------------+

| max(sallary) |

+--------------+

| 530000 |

+--------------+

Average:-

select avg(sallary) from student;

+--------------+

| avg(sallary) |

+--------------+

| 264166.6667 |

Sum:-

select sum(sallary) from student;

+--------------+

| sum(sallary) |

+--------------+

| 1585000 |

Count:-

select count(ID) from student;

+-----------+

| count(ID) |

+-----------+

| 6 |

Min:-

select min(sallary) from student;

+--------------+

| min(sallary) |

+--------------+

| 25000 |

PRACTICAL – 11

Name: TarunJoshi

Course: MCA

Student ID:23711144

Objective:- Demonstrate the Union ,Intersection and Difference in tables.

Code:-

Union:-

SELECT * FROM First UNION

SELECT * FROM Second;

IDNAME
1Yogesh
2Akanksha
3tarun
4Pradeep
5Nimisha

Inersection:-

SELECT * FROM First INTERSECT

SELECT * FROM Second;

IDNAME
3tarun

Minus:-

SELECT column_name FROM table1

MINUS

SELECT column_name FROM table2;

IDNAME
1Yogesh
2Akanksha

PRACTICAL – 12

Name: Tarun Joshi

Course: MCA

Student ID:23711144

Objective:- Demonstrate the Inner join,Left outer join ,Right outer join

Code:-

Inner JOIN:-

select * from stu inner join enroll on stu.id\=enroll.id;

+----+---------+------+------+------+--------+

| id | name | age | id | cid | course |

+----+---------+------+------+------+--------+

| 1 | nimi | 22 | 1 | 1 | mca |

| 3 | yogesh | 23 | 3 | 2 | bca |

| 4 | pradeep | 24 | 4 | 1 | mca |

+----+---------+------+------+------+--------+

Left Outer join:-

select * from stu left outer join enroll on stu.id\=enroll.id;

+----+----------+------+------+------+--------+

| id | name | age | id | cid | course |

+----+----------+------+------+------+--------+

| 1 | tarun| 22 | 1 | 1 | mca |

| 2 | akanksha | 22 | NULL | NULL | NULL |

| 3 | yogesh | 23 | 3 | 2 | bca |

| 4 | pradeep | 24 | 4 | 1 | mca |

+------+---------+------+------+------+--------+

Right outer join:-

select * from stu right outer join enroll on stu.id\=enroll.id;

+------+---------+------+------+------+--------+

| id | name | age | id | cid | course |

+------+---------+------+------+------+--------+

| 1 | tarun| 22 | 1 | 1 | mca |

| 3 | yogesh | 23 | 3 | 2 | bca |

| 4 | pradeep | 24 | 4 | 1 | mca |

+------+---------+------+------+------+--------+