0% found this document useful (0 votes)
39 views7 pages

Practical 3 DBMS

This document shows SQL commands used to create and query tables in a MySQL database. Tables are created for departments and instructors, then data is inserted and various SELECT queries are run to retrieve and aggregate data from the tables.

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)
39 views7 pages

Practical 3 DBMS

This document shows SQL commands used to create and query tables in a MySQL database. Tables are created for departments and instructors, then data is inserted and various SELECT queries are run to retrieve and aggregate data from the tables.

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/ 7

Sanjeevani Chhotu Shivde.

PRACTICAL NO: 3

Enter password: ***********

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

Your MySQL connection id is 14

Server version: 8.0.30 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> show databases;

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

| Database |

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

| dbms |

| information_schema |

| mysql |

| performance_schema |
| scs |

| sys |

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

6 rows in set (0.00 sec)

mysql> use scs;

Database changed

mysql> show tables;

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

| Tables_in_scs |

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

| cource_k |

| dept_k |

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

2 rows in set (0.00 sec)

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> create table instructor_k( I_id varchar(10), i_name varchar(10), dept_nam

e varchar(10), Salary numeric(10,2), primary key(I_id), foreign key(dept_name)re

ferences dept_k(dept_name));

Query OK, 0 rows affected (0.33 sec)

mysql> insert into instructor_k values('k1', 'Sanjevani', 'CS', 100000);

Query OK, 1 row affected (0.15 sec)

mysql> insert into instructor_k values('k1', 'Pratiksha', 'IT', 50000);

ERROR 1062 (23000): Duplicate entry 'k1' for key 'instructor_k.PRIMARY'

mysql> insert into instructor_k values('s1', 'Pratiksha', 'IT', 50000);

Query OK, 1 row affected (0.05 sec)

mysql> insert into instructor_k values('a1', 'Prerana', 'ME', 51000);

Query OK, 1 row affected (0.06 sec)

mysql> insert into instructor_k values('a2', 'Ankita', 'EE', 45000);

Query OK, 1 row affected (0.06 sec)


mysql> select * from instructor_k;

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

| I_id | i_name | dept_name | Salary |

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

| a1 | Prerana | ME | 51000.00 |

| a2 | Ankita | EE | 45000.00 |

| k1 | Sanjevani | CS | 100000.00 |

| s1 | Pratiksha | IT | 50000.00 |

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

4 rows in set (0.00 sec)

mysql> select dept_name, avg(salary) as avg_salary from instructor_k group by de

pt_name;

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

| dept_name | avg_salary |

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

| CS | 100000.000000 |

| EE | 45000.000000 |

| IT | 50000.000000 |

| ME | 51000.000000 |

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

4 rows in set (0.37 sec)


mysql> select dept_name, avg(salary)as avg_salary from instructor_k group by dep

t_name having avg(salary)>40000;

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

| dept_name | avg_salary |

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

| CS | 100000.000000 |

| EE | 45000.000000 |

| IT | 50000.000000 |

| ME | 51000.000000 |

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

4 rows in set (0.03 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.02 sec)

mysql> select * from instructor_k ORDER BY SALARY;

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

| I_id | i_name | dept_name | Salary |

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

| a2 | Ankita | EE | 45000.00 |

| s1 | Pratiksha | IT | 50000.00 |

| a1 | Prerana | ME | 51000.00 |

| k1 | Sanjevani | CS | 100000.00 |

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

4 rows in set (0.00 sec)

mysql> select * from instructor_k ORDER BY I_id;

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

| I_id | i_name | dept_name | Salary |

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

| a1 | Prerana | ME | 51000.00 |

| a2 | Ankita | EE | 45000.00 |

| k1 | Sanjevani | CS | 100000.00 |
| s1 | Pratiksha | IT | 50000.00 |

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

4 rows in set (0.00 sec)

mysql>

You might also like