The document outlines the creation of three MySQL tables: 'student', 'course', and 'enroll', along with their respective fields and constraints. It includes various insert operations demonstrating successful entries and handling of duplicate entries and foreign key constraints. The final queries display the contents of the 'student', 'course', and 'enroll' tables, confirming the successful data insertion.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
8 views3 pages
Composite PK
The document outlines the creation of three MySQL tables: 'student', 'course', and 'enroll', along with their respective fields and constraints. It includes various insert operations demonstrating successful entries and handling of duplicate entries and foreign key constraints. The final queries display the contents of the 'student', 'course', and 'enroll' tables, confirming the successful data insertion.
mysql> insert into course values(10,'Python',3,7500);
ERROR 1062 (23000): Duplicate entry '10' for key 'course.PRIMARY' mysql> select * from course; +-----+------------+----------+------+ | cid | cname | duration | fees | +-----+------------+----------+------+ | 10 | C Language | 2 | 2500 | | 20 | Java | 3 | 3500 | | 30 | Python | 3 | 7500 | +-----+------------+----------+------+ 3 rows in set (0.00 sec)
mysql> select * from student;
+------+-------+-------+------------+------+--------------------+ | sid | fname | lname | dob | g | email | +------+-------+-------+------------+------+--------------------+ | 1001 | Ajay | Dev | 2024-08-05 | M | Kajol@devgan.com | | 1002 | Ajaya | Devi | 2024-08-05 | F | Kajoli@devgani.com | +------+-------+-------+------------+------+--------------------+ 2 rows in set (0.00 sec)
mysql> desc enroll;
+------------+------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+------+------+-----+---------+----------------+ | erno | int | NO | UNI | NULL | auto_increment | | sid | int | NO | PRI | NULL | | | cid | int | NO | PRI | NULL | | | enrolldate | date | NO | | NULL | | +------------+------+------+-----+---------+----------------+ 4 rows in set (0.00 sec)
mysql> insert into enroll (sid,cid,enrolldate)values(1001,20,now());
Query OK, 1 row affected, 1 warning (0.01 sec)
mysql> insert into enroll (sid,cid,enrolldate)values(1001,20,now());