0% found this document useful (0 votes)
17 views2 pages

Exp 2 Primary Foreign

The document shows the configuration and usage of MySQL. It connects to the "sse" database and shows the tables. The "student" and "studepartment" tables are described. Primary key, foreign key, and unique constraints are added to relate the tables and enforce data integrity.

Uploaded by

Jaswitha Lakshmi
Copyright
© © All Rights Reserved
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% found this document useful (0 votes)
17 views2 pages

Exp 2 Primary Foreign

The document shows the configuration and usage of MySQL. It connects to the "sse" database and shows the tables. The "student" and "studepartment" tables are described. Primary key, foreign key, and unique constraints are added to relate the tables and enforce data integrity.

Uploaded by

Jaswitha Lakshmi
Copyright
© © All Rights Reserved
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
You are on page 1/ 2

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

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


Your MySQL connection id is 28
Server version: 8.0.26 MySQL Community Server - GPL

Copyright (c) 2000, 2021, 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> use sse;


Database changed
mysql> show tables;
+---------------+
| Tables_in_sse |
+---------------+
| bin |
| empdepartment |
| empdept |
| employee |
| student |
| studepartment |
| t |
+---------------+
7 rows in set (0.00 sec)

mysql> desc student;


+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| Rollno | int | YES | | NULL | |
| Name | varchar(20) | YES | | NULL | |
| Gender | char(1) | YES | | NULL | |
| DOB | varchar(10) | YES | | NULL | |
| Mobileno | int | YES | | NULL | |
| City | varchar(20) | YES | | NULL | |
| District | varchar(20) | YES | | NULL | |
| dept | varchar(5) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
8 rows in set (0.00 sec)

mysql> desc studepartment;


+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| Deptid | int | YES | | NULL | |
| Deptname | varchar(20) | YES | | NULL | |
| Rollno | int | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> alter table student add primary key(Rollno);


Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc student;


+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| Rollno | int | NO | PRI | NULL | |
| Name | varchar(20) | YES | | NULL | |
| Gender | char(1) | YES | | NULL | |
| DOB | varchar(10) | YES | | NULL | |
| Mobileno | int | YES | | NULL | |
| City | varchar(20) | YES | | NULL | |
| District | varchar(20) | YES | | NULL | |
| dept | varchar(5) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
8 rows in set (0.01 sec)

mysql> alter table studepartment add foreign key(Rollno) references


student(Rollno);
Query OK, 0 rows affected (0.07 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc studepartment;


+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| Deptid | int | YES | | NULL | |
| Deptname | varchar(20) | YES | | NULL | |
| Rollno | int | YES | MUL | NULL | |
+----------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

mysql>alter table student add unique(Rollno);


Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc student;


+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| Rollno | int | NO | PRI | NULL | |
| Name | varchar(20) | YES | | NULL | |
| Gender | char(1) | YES | | NULL | |
| DOB | varchar(10) | YES | | NULL | |
| Mobileno | int | YES | | NULL | |
| City | varchar(20) | YES | | NULL | |
| District | varchar(20) | YES | | NULL | |
| dept | varchar(5) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
8 rows in set (0.01 sec)
mysql>alter table student add check(age>=15);
Query OK, 0 rows affected (0.11 sec)
Records: 0 Duplicates: 0 Warnings: 0

You might also like