0% found this document useful (0 votes)
3 views1 page

Foreign Key Commands

Uploaded by

Ronak Pahuja
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)
3 views1 page

Foreign Key Commands

Uploaded by

Ronak Pahuja
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

mysql> desc student;

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

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

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

| name | varchar(20) | YES | | NULL | |

| class | varchar(10) | YES | | NULL | |

| rollno | int(11) | YES | | NULL | |

| marks | int(11) | YES | | NULL | |

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

4 rows in set (0.01 sec)

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

Query OK, 2 rows affected (0.41 sec)

Records: 2 Duplicates: 0 Warnings: 0

mysql> create table act(acode varchar(10),rollno int(11),foreign key(rollno) references


student(rollno));

Query OK, 0 rows affected (0.16 sec)

sql> desc act

-> ;

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

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

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

| acode | varchar(10) | YES | | NULL | |

| rollno | int(11) | YES | MUL | NULL | |

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

2 rows in set (0.01 sec)

You might also like