0% found this document useful (0 votes)
66 views19 pages

Dbms Sachin

1) The document describes SQL queries performed on databases and tables created in MySQL. It creates databases, tables for departments, courses, and instructors with various fields. 2) Data is inserted into the tables and queries are run to select, update, and view the data. 3) Tables are related to each other using primary and foreign keys on common fields like department name.

Uploaded by

Pushpak Rai
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)
66 views19 pages

Dbms Sachin

1) The document describes SQL queries performed on databases and tables created in MySQL. It creates databases, tables for departments, courses, and instructors with various fields. 2) Data is inserted into the tables and queries are run to select, update, and view the data. 3) Tables are related to each other using primary and foreign keys on common fields like department name.

Uploaded by

Pushpak Rai
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/ 19

PRACTICAL NO : 01

Name : Sachin bhivsan Bediskar


Roll NO : 75
PRN NO : 2151711245511
Branch : Computer
Class : TY.Betch

mysql> show databases;


+--------------------+
| Database |
+--------------------+
| dbms |
| information_schema |
| mydb |
| mysql |
| newdb |
| performance_schema |
| priya |
| studinfo |
| sys |
+--------------------+
9 rows in set (0.78 sec)

mysql> use priya;


Database changed
mysql> create table dept_k
-> (dept_name varchar(10),
-> dept_building varchar(10),
-> dept_budget numeric(12,2),
-> primary key(dept_name));
Query OK, 0 rows affected (0.11 sec)
mysql> insert into dept_k
-> values('cs','A',30000);
Query OK, 1 row affected (0.06 sec)

mysql> insert into dept_k values('IT','B',31000);


Query OK, 1 row affected (0.02 sec)

mysql> insert into dept_k


-> values('ME','C',40000);
Query OK, 1 row affected (0.05 sec)

mysql> insert into dept_k


-> values('EE','D',35000);
Query OK, 1 row affected (0.05 sec)
mysql> describe dept_k;
+---------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------------+------+-----+---------+-------+
| dept_name | varchar(10) | NO | PRI | NULL | |
| dept_building | varchar(10) | YES | | NULL | |
| deot_budget | decimal(12,2) | YES | | NULL | |
+---------------+---------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> select * from dept_k;


+-----------+---------------+-------------+
| dept_name | dept_building | dept_budget |
+-----------+---------------+-------------+
| cs |A | 3000.00 |
| EE |D | 3500.00 |
| IT |B | 4000.00 |
+-----------+---------------+-------------+
3 rows in set (0.00 sec)

mysql> insert into dept_k values('ME','C',4000);


Query OK, 1 row affected (0.02 sec)

mysql> select * from dept_k;


+-----------+---------------+-------------+
| dept_name | dept_building | dept_budget |
+-----------+---------------+-------------+
| cs |A | 3000.00 |
| EE |D | 3500.00 |
| IT |B | 4000.00 |
| ME |C | 4000.00 |
+-----------+---------------+-------------+
4 rows in set (0.00 sec)
mysql> create table cource_k ( C_id varchar(10), C_title varchar(10), dept_name
varchar(10), Credits numeric (12,3), primary key(C_id),foreign key(dept_name) references
dept_k(dept_name));
Query OK, 0 rows affected (0.02 sec)
mysql> insert into cource_k values('C111','c_Lang','CS',4),('C112','c++_Lang','IT',5),
('M113','Java','ME',4), ('E114', 'EDEME','EE',3);
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> describe cource_k;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| c_id | varchar(10) | NO | PRI | NULL | |
| c_title | varchar(20) | YES | | NULL | |
| dept_name | varchar(10) | YES | MUL | NULL | |
| credits | int | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.05 sec)
mysql> Select * from cource_k;
+------+----------+-----------+---------+
| c_id | c_title | dept_name | credits |
+------+----------+-----------+---------+
| C112 | c++_Lang | IT | 5|
| E114 | EDEME | EE | 3|
| M113 | Java | ME | 4|
+------+----------+-----------+---------+
3 rows in set (0.00 sec)

mysql> select dept_name from dept_k;


+-----------+
| dept_name |
+-----------+
| cs |
| EE |
| IT |
| ME |
+-----------+
4 rows in set (0.00 sec)

mysql> insert into dept_k values('Civil','C',50000);


Query OK, 1 row affected (0.02 sec)

mysql> insert into dept_k values('Electrical','A',55000);


Query OK, 1 row affected (0.02 sec)

mysql> select*from dept_k;


+------------+---------------+-------------+
| dept_name | dept_building | deot_budget |
+------------+---------------+-------------+
| Civil |C | 50000.00 |
| cs |A | 3000.00 |
| EE |D | 3500.00 |
| Electrical | A | 55000.00 |
| IT |B | 4000.00 |
| ME |C | 4000.00 |
+------------+---------------+-------------+
6 rows in set (0.00 sec)

mysql> create table instructor_k(I_id varchar(10),I_name varchar(10),dept_name v


archar(10),Salary numeric(10,2),primary key(I_id),foreign key(dept_name) referen
ces dept_k(dept_name));
Query OK, 0 rows affected (0.12 sec)
mysql> describe instructor_k;
+-----------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------------+------+-----+---------+-------+
| I_id | varchar(10) | NO | PRI | NULL | |
| I_name | varchar(10) | YES | | NULL | |
| dept_name | varchar(10) | YES | MUL | NULL | |
| Salary | decimal(10,2) | YES | | NULL | |
+-----------+---------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> insert into instructor_k


-> values('K1','Pari','CS',50000),('S1','Rani','IT',51000),('A1','Janvi','ME
',40000),('A2','Anu','EE',45000);
Query OK, 4 rows affected (0.03 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> select*from instructor_k;


+------+--------+-----------+----------+
| I_id | I_name | dept_name | Salary |
+------+--------+-----------+----------+
| A1 | Janvi | ME | 40000.00 |
| A2 | Anu | EE | 45000.00 |
| K1 | Pari | CS | 50000.00 |
| S1 | Rani | IT | 51000.00 |
+------+--------+-----------+----------+
4 rows in set (0.00 sec)
mysql> select I_name from instructor_k;
+--------+
| I_name |
+--------+
| Janvi |
| Anu |
| Pari |
| Rani |
+--------+
4 rows in set (0.00 sec)

mysql> select I_id,I_name,dept_name,Salary*1.1 from instructor_k;


+------+--------+-----------+------------+
| I_id | I_name | dept_name | Salary*1.1 |
+------+--------+-----------+------------+
| A1 | Janvi | ME | 44000.000 |
| A2 | Anu | EE | 49500.000 |
| K1 | Pari | CS | 55000.000 |
| S1 | Rani | IT | 56100.000 |
+------+--------+-----------+------------+
4 rows in set (0.07 sec)

mysql> select I_name from instructor_k where dept_name='CS' and Salary>20000;


+--------+
| I_name |
+--------+
| Pari |
+--------+
1 row in set (0.03 sec)
PRACTICAL NO : 02
Name : Sachin Bhivsan Bediskar
Roll NO : 75
PRN NO:2151711245511
Branch:Computer
Class:TY.Betch

mysql> create database mysql;


Query OK, 1 row affected (0.05 sec)

mysql>
mysql> use mysql;
Database changed
mysql> create table dept_k
-> (dept_name varchar(10),
-> dept_building varchar(10),
-> dept_budget numeric(12,2),
-> primary key(dept_name));
Query OK, 0 rows affected (0.11 sec)

mysql> insert into dept_k


-> values('cs','A',30000);
Query OK, 1 row affected (0.06 sec)

mysql> insert into dept_k values('IT','B',31000);


Query OK, 1 row affected (0.02 sec)

mysql> insert into dept_k


-> values('ME','C',40000);
Query OK, 1 row affected (0.05 sec)

mysql> insert into dept_k


-> values('EE','D',35000);
Query OK, 1 row affected (0.05 sec)

mysql> select * from dept_k;


+-----------+---------------+-------------+
| dept_name | dept_building | dept_budget |
+-----------+---------------+-------------+
| cs |A | 30000.00 |
| EE |D | 35000.00 |
| IT |B | 31000.00 |
| ME |C | 40000.00 |
+-----------+---------------+-------------+
4 rows in set (0.00 sec)

mysql> update dept_k


-> set dept_building='Z'
-> where dept_name='CS';
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> update dept_k


-> set dept_budget=50000
-> where dept_name='CS';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from dept_k;
+-----------+---------------+-------------+
| dept_name | dept_building | dept_budget |
+-----------+---------------+-------------+
| cs |Z | 50000.00 |
| EE |D | 35000.00 |
| IT |B | 31000.00 |
| ME |C | 40000.00 |
+-----------+---------------+-------------+
4 rows in set (0.00 sec)
mysql> drop table cource_k;
Query OK, 0 rows affected (0.03 sec)
mysql> show tables;
+----------------+
| Tables_in_dbms |
+----------------+
| dept_k |
| instructor_k |
+----------------+
2 rows in set (0.00 sec)

mysql> create table cource_k (C_id varchar(10), C_title varchar(10), dept_name varchar(10),
Credits numeric(12,3), Primary key(C_id), Foreign key(dept_name) references
dept_k(dept_name));
Query OK, 0 rows affected (0.03 sec)

mysql> insert into cource_k values('C111', 'C_lang', 'CS',4), ('C112', 'C++_lang', 'IT',5),
('M113', 'Java', 'ME',4), ('E114', 'EDEME', 'EE',3);
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> show tables;
+----------------+
| Tables_in_dbms |
+----------------+
| cource_k |
| dept_k |
| instructor_k |
+----------------+
3 rows in set (0.00 sec)

mysql> select * from cource_k;


+------+----------+-----------+---------+
| C_id | C_title | dept_name | Credits |
+------+----------+-----------+---------+
| C111 | C_lang | CS | 4.000 |
| C112 | C++_lang | IT | 5.000 |
| E114 | EDEME | EE | 3.000 |
| M113 | Java | ME | 4.000 |
+------+----------+-----------+---------+
4 rows in set (0.00 sec)

mysql> select * from dept_k;


+------------+---------------+-------------+
| dept_name | dept_building | dept_budget |
+------------+---------------+-------------+
| Civil |c | 50000.00 |
| CS |Z | 50000.00 |
| EE |D | 35000.00 |
| Electrical | A | 55000.00 |
| IT |B | 31000.00 |
| ME |C | 40000.00 |
+------------+---------------+-------------+
6 rows in set (0.00 sec)
mysql> select distinct dept_building from dept_k;
+---------------+
| dept_building |
+---------------+
|c |
|Z |
|D |
|A |
|B |
+---------------+
5 rows in set (0.00 sec)
mysql> select distinct dept_name from dept_k;
+------------+
| dept_name |
+------------+
| Civil |
| CS |
| EE |
| Electrical |
| IT |
| ME |
+------------+
6 rows in set (0.00 sec)
mysql> show tables;
+----------------+
| Tables_in_dbms |
+----------------+
| cource_k |
| dept_k |
| instructor_k |
+----------------+
3 rows in set (0.00 sec)
mysql> select * from cource_k;
+------+----------+-----------+---------+
| C_id | C_title | dept_name | Credits |
+------+----------+-----------+---------+
| C111 | C_lang | CS | 4.000 |
| C112 | C++_lang | IT | 5.000 |
| E114 | EDEME | EE | 3.000 |
| M113 | Java | ME | 4.000 |
+------+----------+-----------+---------+
4 rows in set (0.00 sec)

mysql> truncate table cource_k;


Query OK, 0 rows affected (0.04 sec)

mysql> show tables;


+----------------+
| Tables_in_dbms |
+----------------+
| cource_k |
| dept_k |
| instructor_k |
+----------------+
3 rows in set (0.00 sec)

mysql> select * from cource_k;


Empty set (0.00 sec)
mysql>
Practical No : 3

Name : Sachin Bhivsan Bediskar


Roll No : 75
PRN NO : 2151711245511
Branch : Computer
Class : TY.Betch

mysql> show tables;


+----------------+
| Tables_in_dbms |
+----------------+
| cource_k |
| dept_k |
| instructor_k |
+----------------+
3 rows in set (0.00 sec)
mysql> select * from dept_k;
+------------+---------------+-------------+
| dept_name | dept_building | dept_budget |
+------------+---------------+-------------+
| Civil | c | 50000.00 |
| CS | Z | 50000.00 |
| EE | D | 35000.00 |
| Electrical | A | 55000.00 |
| IT | B | 31000.00 |
| ME | C | 40000.00 |
+------------+---------------+-------------+
6 rows in set (0.00 sec)
mysql> select * from instructor_k ;
+------+------------+-----------+-----------+
| I_id | I_name | dept_name | Salary |
+------+------------+-----------+-----------+
| A1 | Sanjeevani | CS | 100000.00 |
| A2 | Muskaan | EE | 45000.00 |
| K1 | Ankita | ME | 40000.00 |
| S1 | Prerana | IT | 50000.00 |
+------+------------+-----------+-----------+
4 rows in set (0.00 sec)
mysql> select dept_name, avg(salary) as avg_salary from instructor_k group by dept_name;
+-----------+---------------+
| dept_name | avg_salary |
+-----------+---------------+
| CS | 100000.000000 |
| EE | 45000.000000 |
| IT | 50000.000000 |
| ME | 40000.000000 |
+-----------+---------------+
4 rows in set (0.01 sec)
mysql> select dept_name, avg(salary) as avg_salary from instructor_k group by dept_name
having
avg(salary)>40000;
+-----------+---------------+
| dept_name | avg_salary |
+-----------+---------------+
| CS | 100000.000000 |
| EE | 45000.000000 |
| IT | 50000.000000 |
+-----------+---------------+
3 rows in set (0.00 sec)
mysql> select avg(salary) from instructor_k where dept_name='CS';
+---------------+
| avg(salary) |
+---------------+
| 100000.000000 |
+---------------+
1 row in set (0.00 sec)
mysql> select max(salary) from instructor_k;
+-------------+
| max(salary) |
+-------------+
| 100000.00 |
+-------------+
1 row in set (0.00 sec)
mysql> select min(Salary) from instructor_k;
+-------------+
| min(Salary) |
+-------------+
| 40000.00 |
+-------------+
1 row in set (0.00 sec)
mysql> select count(I_id) from instructor_k;
+-------------+
| count(I_id) |
+-------------+
|4|
+-------------+
1 row in set (0.01 sec)
mysql> select sum(Salary) from instructor_k;
+-------------+
| sum(Salary) |
+-------------+
| 235000.00 |
+-------------+
1 row in set (0.00 sec)
mysql>

You might also like