0% found this document useful (0 votes)
13 views12 pages

20BCS030 - Mateen Khan - Dbms p9

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

20BCS030 - Mateen Khan - Dbms p9

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

NAME = MATEEN KHAN

SUBJECT = DBMS LAB = 9

mysql> SHOW DATABASES;


+--------------------+
| Database |
+--------------------+
| client_master |
| company |
| deptname |
| employee |
| information_schema |
| mysql |
| performance_schema |
| product |
| products |
| sakila |
| sales |
| sys |
| vender_info |
| venders |
| world |
+--------------------+
15 rows in set (0.03 sec)

mysql> CREATE DATABASE STUDENT;


Query OK, 1 row affected (0.03 sec)

mysql> USE STUDENT;


Database changed
mysql> SHOW TABLES;
Empty set (0.03 sec)

mysql> CREATE TABLE STUDENT(S_num int not null auto_increment primary key,S_name
varchar(20) not null,Major varchar(10) not null,Level varchar(15) not null,Age int not null);
Query OK, 0 rows affected (0.08 sec)
mysql> show tables;
+-------------------+
| Tables_in_student |
+-------------------+
| student |
+-------------------+
1 row in set (0.01 sec)

mysql> describe student;


+--------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+----------------+
| S_num | int | NO | PRI | NULL | auto_increment |
| S_name | varchar(20) | NO | | NULL | |
| Major | varchar(10) | NO | | NULL | |
| Level | varchar(15) | NO | | NULL | |
| Age | int | NO | | NULL | |
+--------+-------------+------+-----+---------+----------------+
5 rows in set (0.02 sec)

mysql>

mysql> INSERT INTO STUDENT VALUES(101,'Jhon','CS','SR',19);


Query OK, 1 row affected (0.03 sec)

mysql> INSERT INTO STUDENT VALUES(102,'Smith','CS','JR',20);


Query OK, 1 row affected (0.03 sec)

mysql> INSERT INTO STUDENT VALUES(103,'Jacob','ECE','SR',20);


Query OK, 1 row affected (0.02 sec)

mysql> INSERT INTO STUDENT VALUES(104,'Tom','CS','JR',20);


Query OK, 1 row affected (0.02 sec)

mysql> INSERT INTO STUDENT VALUES(105,'Sid','CS','JR',20);


Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO STUDENT VALUES(106,'Harry','History','SR',21);


Query OK, 1 row affected (0.02 sec)

mysql> INSERT INTO STUDENT VALUES(107,'Hellen','CS','JR',21);


Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO STUDENT VALUES(108,'Bob','English','SR',22);
Query OK, 1 row affected (0.02 sec)

mysql> INSERT INTO STUDENT VALUES(109,'Andy','ECE','JR',21);


Query OK, 1 row affected (0.02 sec)

mysql> INSERT INTO STUDENT VALUES(110,'Charles','History','SR',32);


Query OK, 1 row affected (0.01 sec)

mysql>

mysql> describe tables;


ERROR 1146 (42S02): Table 'student.tables' doesn't exist
mysql> show tables;
+-------------------+
| Tables_in_student |
+-------------------+
| class |
| student |
+-------------------+
2 rows in set (0.01 sec)

mysql> describe class;


+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| C_name | int | NO | | NULL | |
| Meets_at | varchar(20) | YES | | NULL | |
| Room | varchar(10) | YES | | NULL | |
| Fid | varchar(9) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
4 rows in set (0.02 sec)

mysql> create table Class(cname varchar(20) primary key,


-> meets_at varchar(20),
-> room varchar(20),
-> fid int);
Query OK, 0 rows affected (0.09 sec)

mysql> insert into Class values('CSC342', 'Morning', 'R128', 201);


Query OK, 1 row affected (0.01 sec)

mysql> insert into Class values('CSC343', 'Noon', 'R128', 203);


Query OK, 1 row affected (0.01 sec)

mysql> insert into Class values('CSC345', 'Night', 'R154', 204);


Query OK, 1 row affected (0.01 sec)

mysql> insert into Class values('ECE300', 'Morning', 'R111', 202);


Query OK, 1 row affected (0.01 sec)

mysql> insert into Class values('ECE301', 'Noon', 'R111', 203);


Query OK, 1 row affected (0.01 sec)

mysql> insert into Class values('ENG366', 'Morning', 'R154', 203);


Query OK, 1 row affected (0.01 sec)

mysql> insert into Class values('ENG367', 'Evening', 'R111', 205);


Query OK, 1 row affected (0.01 sec)

mysql> insert into Class values('HIS320', 'Evening', 'R128', 205);


Query OK, 1 row affected (0.01 sec)

mysql> DESCRIBE TABLES;


ERROR 1146 (42S02): Table 'student.tables' doesn't exist
mysql> DESCRIBE TABLES;
ERROR 1146 (42S02): Table 'student.tables' doesn't exist
mysql> SHOW TABLES;
+-------------------+
| Tables_in_student |
+-------------------+
| class |
| student |
+-------------------+
2 rows in set (0.01 sec)

mysql> DESCRIBE CLASS;


+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| cname | varchar(20) | NO | PRI | NULL | |
| meets_at | varchar(20) | YES | | NULL | |
| room | varchar(20) | YES | | NULL | |
| fid | int | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
4 rows in set (0.01 sec)

mysql>

mysql> create table Enrolled(snum int, cname varchar(20));


Query OK, 0 rows affected (0.09 sec)

mysql>
mysql>
mysql> create table Enrolled(snum int, cname varchar(20));
Query OK, 0 rows affected (0.09 sec)

mysql> SHOW TABLES;


+-------------------+
| Tables_in_student |
+-------------------+
| class |
| enrolled |
| student |
+-------------------+
3 rows in set (0.02 sec)

mysql> DESCRIBE ENROLLED;


+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| snum | int | YES | | NULL | |
| cname | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.02 sec)

mysql> insert into Enrolled values(101, 'CSC342');


Query OK, 1 row affected (0.02 sec)

mysql> insert into Enrolled values(101, 'CSC343');


Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(101, 'CSC345');


Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(101, 'ECE300');


Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(101, 'ENG366');


Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(102, 'CSC343');


Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(102, 'CSC345');


Query OK, 1 row affected (0.01 sec)
mysql> insert into Enrolled values(102, 'ECE301');
Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(103, 'ECE300');


Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(103, 'ECE301');


Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(104, 'CSC342');


Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(104, 'ECE301');


Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(105, 'CSC345');


Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(105, 'ECE300');


Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(106, 'ENG366');


Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(106, 'HIS320');


Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(107, 'CSC342');


Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(107, 'ENG366');


Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(108, 'ENG367');


Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(108, 'HIS320');


Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(109, 'ECE300');


Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(109, 'ECE301');


Query OK, 1 row affected (0.01 sec)
mysql> insert into Enrolled values(110, 'ENG366');
Query OK, 1 row affected (0.01 sec)

mysql> insert into Enrolled values(110, 'HIS320');

mysql> create table Faculty(fid int primary key, fname varchar(20), deptid int);
Query OK, 0 rows affected (0.08 sec)
mysql> SHOW TABLES;
+-------------------+
| Tables_in_student |
+-------------------+
| class |
| enrolled |
| faculty |
| student |
+-------------------+
4 rows in set (0.01 sec)

mysql> DESCRIBE TABLES;


ERROR 1146 (42S02): Table 'student.tables' doesn't exist
mysql> DESCRIBE FACULTY;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| fid | int | NO | PRI | NULL | |
| fname | varchar(20) | YES | | NULL | |
| deptid | int | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

mysql>
mysql> insert into Faculty values(201,'John', 301);
Query OK, 1 row affected (0.02 sec)

mysql> insert into Faculty values(202,'M. Shanks', 302);


Query OK, 1 row affected (0.01 sec)

mysql> insert into Faculty values(203,'I. Teach', 302);


Query OK, 1 row affected (0.01 sec)

mysql> insert into Faculty values(204,'A. Zobrah', 303);


Query OK, 1 row affected (0.01 sec)

mysql> insert into Faculty values(205,'M. Jensen', 303);


Query OK, 1 row affected (0.02 sec)
Q 10 Find the names of students enrolled in the maximum number of classes.

Q 9 For each faculty member that has taught class only in room R128 print the
faculty member’s name and the total number of classes he or she has taught.

Q 8 For all levels except JR, print the level and the average age of students for
that level.
Q 7 For each level, print the level and the average age of students for that level.

Q 6 Find the names of faculty members for whom the combined enrollment of
the course that they teach is less than five.
Q 5 Find the names of faculty members who teach in every room in which some
class is taught.

Q 4 Find the names of all students who are enrolled in two-class that meet at
the same time.

Q 3 Find the names of all classes that either meet in room R128 or have five or
more students enrolled.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy