0% found this document useful (0 votes)
43 views

Assignment 2

The document describes creating tables, inserting values, and performing queries in MySQL. It creates tables to store personal information, paper details, and academic details. Values are inserted and primary and foreign keys are added. Four sample queries are performed, such as finding students who scored over 60% in English and attended over 75% of classes. The tables are populated with test data and the schema is documented.

Uploaded by

Prabhu Mehrotra
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)
43 views

Assignment 2

The document describes creating tables, inserting values, and performing queries in MySQL. It creates tables to store personal information, paper details, and academic details. Values are inserted and primary and foreign keys are added. Four sample queries are performed, such as finding students who scored over 60% in English and attended over 75% of classes. The tables are populated with test data and the schema is documented.

Uploaded by

Prabhu Mehrotra
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

SHAHEED SUKHDEV COLLEGE OF BUSINESS STUDIES

DBMS ASSIGNMENT (PRACTICAL)

CREATING TABLES AND INSERTING VALUES :

mysql> create database compdep;

Query OK, 1 row affected (0.01 sec)

mysql> use compdep;

Database changed

mysql> create table perinfo(

->rollno int(5) primary key,

-> name char(50),

-> dob date,

-> marks int(3),

-> address varchar(60),

->phnno int(10));

Query OK, 0 rows affected, 3 warnings (0.06 sec)

mysql>descperinfo;

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

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

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

| rollno | int | NO | PRI | NULL | |

| name | char(50) | YES | | NULL | |

| dob | date | YES | | NULL | |

| marks | int | YES | | NULL | |

| address | varchar(60) | YES | | NULL | |

| phnno | int | YES | | NULL | |

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

6 rows in set (0.00 sec)

mysql> create table papdet(

->papercode int(3),

1
-> name varchar(30));

Query OK, 0 rows affected, 1 warning (0.07 sec)

mysql> create table acaddet(

->rollno int(5),

->papercode int(3),

-> attendance int(3),

-> marks int(3));

Query OK, 0 rows affected, 4 warnings (0.05 sec)

mysql> insert into perinfo values(

-> 11001,'priyash','2002/03/13',85,'rahimnagar',887755);

Query OK, 1 row affected, 1 warning (0.02 sec)

mysql> insert into perinfo values(11004,'ram','2003/12/03',65,'lmnagar',986553);

Query OK, 1 row affected, 1 warning (0.02 sec)

mysql> insert into perinfo values (11005,'kritesh','2004/06/12',79,'dvnagar',886342);

Query OK, 1 row affected, 1 warning (0.02 sec)

mysql> insert into perinfo values(11002,"Prakash",'2002/04/15',56,'rknagar',663457);

Query OK, 1 row affected, 1 warning (0.02 sec)

mysql> insert into perinfo values(11003,'yash','2004/03/14',73,'kdnagar',987466) ;

Query OK, 1 row affected, 1 warning (0.03 sec)

mysql> select * from perinfo;

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

| rollno | name | dob | marks | address | phnno |

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

| 11001 | priyash | 2002-03-13 | 85 | rahimnagar | 887755 |

| 11002 | Prakash | 2002-04-15 | 56 | rknagar | 663457 |

| 11003 | yash | 2004-03-14 | 73 | kdnagar | 987466 |

| 11004 | ram | 2003-12-03 | 65 | lmnagar | 986553 |

| 11005 | kritesh | 2004-06-12 | 79 | dvnagar | 886342 |

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

2
5 rows in set (0.00 sec)

mysql> insert into papdet values(1,'ip'),(2,'eng'),(3,'ACC'),(4,"eco"),(5,"Sans");

Query OK, 5 rows affected (0.02 sec)

Records: 5 Duplicates: 0 Warnings: 0

ADDING PRIMARY KEY AND FOREIGN KEYS :

mysql> alter table papdet add primary key(papercode);

Query OK, 0 rows affected (0.07 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table acaddet add foreign key(papercode) references papdet(papercode);

Query OK, 0 rows affected (0.13 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table acaddet add foreign key(rollno) references perinfo(rollno) on delete cascade;

Query OK, 0 rows affected (0.10 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> insert into acaddet values(

-> 11001,1,85,91);

Query OK, 1 row affected (0.03 sec)

mysql> insert into acaddet values(11001,2,85,91);

Query OK, 1 row affected (0.03 sec)

mysql> insert into acaddet values(11003,3,85,91);

Query OK, 1 row affected (0.02 sec)

mysql> insert into acaddet values(11004,4,85,91);

Query OK, 1 row affected (0.01 sec)

mysql> insert into acaddet values(11005,5,85,91);

Query OK, 1 row affected (0.01 sec)

mysql> select * from acaddet;

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

| rollno | papercode | attendance | marks |

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

| 11001 | 1| 85 | 91 |

| 11001 | 2| 85 | 91 |

3
| 11003 | 3| 85 | 91 |

| 11004 | 4| 85 | 91 |

| 11005 | 5| 85 | 91 |

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

5 rows in set (0.00 sec)

mysql> select * from perinfo;

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

| rollno | name | dob | marks | address | phnno |

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

| 11001 | priyash | 2002-03-13 | 85 | rahimnagar | 887755 |

| 11002 | Prakash | 2002-04-15 | 56 | rknagar | 663457 |

| 11003 | yash | 2004-03-14 | 73 | kdnagar | 987466 |

| 11004 | ram | 2003-12-03 | 65 | lmnagar | 986553 |

| 11005 | kritesh | 2004-06-12 | 79 | dvnagar | 886342 |

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

5 rows in set (0.00 sec)

mysql> select * from papdet;

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

| papercode | name |

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

| 1 | ip |

| 2 | eng |

| 3 | ACC |

| 4 | eco |

| 5 | Sans |

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

5 rows in set (0.00 sec)

4
QUERY QUESTION 1 :

mysql> select papdet.*,perinfo.name from perinfo,papdet,acaddet where


perinfo.rollno=acaddet.rollno and papdet.papercode=acaddet.papercode and
acaddet.attendance>75 and perinfo.marks>60 and papdet.papercode=2;

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

| papercode | name | name |

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

| 2 | eng | priyash |

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

1 row in set (0.00 sec)

QUERY QUESTION 2 :

mysql> select perinfo.name from perinfo,acaddet,papdet where perinfo.rollno=acaddet.rollno and


papdet.papercode=acaddet.papercode and papdet.papercode=2 having max(perinfo.marks);

+---------+

| name |

+---------+

| priyash |

+---------+

1 row in set (0.00 sec)

QUERY QUESTION 3 :

mysql> select perinfo.name from perinfo,papdet,acaddet where perinfo.rollno=acaddet.rollno and


papdet.papercode=acaddet.papercode and perinfo.address='delhi' and papdet.papercode=1 and
acaddet.marks>60;

Empty set (0.00 sec)

QUERY QUESTION 4 :

mysql> select perinfo.marks,acaddet.attendance from perinfo,acaddet,papdet where


perinfo.rollno=acaddet.rollno and papdet.papercode=acaddet.papercode ;

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

| marks | attendance |

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

| 85 | 85 |

| 85 | 85 |

| 73 | 85 |

| 65 | 85 |

5
| 79 | 85 |

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

5 rows in set (0.00 sec)

SUBMITTED BY: PRABHU (21166)

You might also like