What do you mean by foreign key? - www.studyandupdates.com

Sunday

What do you mean by foreign key?

Q 8. What do you mean by foreign key?

Ans : A Foreign key is a field that can uniquely identify each row in another table. And this constraint is used to specify a field as a Foreign key. That is this

field points to the primary key of another table. This usually creates a kind of link between the two tables.

Consider the two tables as shown below:

Orders:


















Customers:

As we can see clearly, that the field C_ID in the Orders table is the primary key in the Customers’ table, i.e. it uniquely identifies each row in the Customers table.

Syntax:



CREATE TABLE Orders

(

O_ID int NOT NULL,

ORDER_NO int NOT NULL,

C_ID int,

PRIMARY KEY (O_ID),

FOREIGN KEY (C_ID) REFERENCES Customers(C_ID)

)










No comments:

Post a Comment

Popular Posts