Syntax For Creating and Deleting Foreign Key

Let’s see the Foreign Key syntax used for creating a table.

Syntax for Creating Foreign Key:

CREATE TABLE Child_table_name (

Child_Column1 data_type,

Child_Column2 data_type, …,

FOREIGN KEY (Child_foreign_key_column)

REFERENCES referenced_table_name (referenced_primary_key_column) );

Below syntax is used to delete the foreign key in DBMS.

Syntax for Dropping Foreign Key:

ALTER TABLE Child_table_name

DROP FOREIGN KEY Child_foreign_key_name;

Foreign Key in DBMS

In DBMS, there are different types of keys available that are used for various purposes. Foreign Key is a column that refers to the primary key/unique key of another table. So it demonstrates the relationship between tables and acts as the cross reference among them.

Similar Reads

Foreign Key

Foreign keys are a set of constraints in DBMS that establish relationships between tables and also ensure consistency and integrity of data. A foreign key is applied to a column of one table which references the primary key of a column in another table....

Syntax For Creating and Deleting Foreign Key

Let’s see the Foreign Key syntax used for creating a table....

Need of Foreign Keys in DBMS

Foreign keys plays a major role in database management systems (DBMS) for the following reasons:...

Implementing Foreign Key

To implement foreign keys in a column of a table, follow the below mentioned steps and make sure to have MYSQL workbench or MYSQL command line client installed in your systems....

Conclusion

In this article we have learned about foreign key in DBMS. To summarize the article, a foreign key establishes relationship between tables and ensures consistency and integrity of data . It is applied to a column of one table which references the primary key of a column in another table. It is mandatory that the other column must have a primary key as it references the data which is related in different tables and creates a relational structure. Foreign key enforces referential integrity and makes sure that data is referenced from one table to table. In order to create a Foreign key we will specify the relationship between the columns during the creation of table’s structure ....

FAQs on Foreign Key in DBMS

Q.1: What is main difference between foreign key and primary key?...

Contact Us