Computer Science, asked by mailtoaditee, 11 months ago

Write the SQL queries implementing the concept of foreign Key in a table.
Write the SQL query to display the constraints enforced by the Foreign Key on the associated tables.

Answers

Answered by naomirosanto
2

FOREIGN KEY

The SQL FOREIGN KEY CONSTRAINT is used to ensure the referential integrity of the data in one table to match values in another table.

The FOREIGN KEY CONSTRAINT is a column or list of columns which points to the PRIMARY KEY of another table.

The main purpose of FOREIGN KEY is, only those values will appear which are present in the primary key table.

SQL FOREIGN KEY

For each row in the referencing table( the table contains the FOREIGN KEY), the foreign key must match an existing primary key in the referenced table(the table contains the PRIMARY KEY). This enforcement of FOREIGN KEY called the Referential Integrity.

The structure and data type of PRIMARY KEY and FOREIGN KEY must be same.

The values of the FOREIGN KEY columns in each row of the referencing table have to match with the values of the corresponding primary key columns of a row in the referenced table.

Syntax:

CREATE TABLE <table_name>(  

column1    data_type[(size)] ,  

column2    data_type[(size)] ,  

constraint(constraint_name)  

FOREIGN KEY  [column1,column2...]  

REFERENCES [primary_key_table] (column_list_of_primary_key_

Answered by Mohdrashid975652
1

Answer:

Programming Tools and Technologies in SQL Server. In Designing SQL ... Foreign key constraints currently enforce table relationships. ... Therefore, the following statement will fail:.

Similar questions