Tuesday, 21 August 2012

Foreign Key

A foreign Key is a combination of columns with value is based on the primary key values from another table. A foreign key constraint also known as Referential Integrity Constraint

A foreign key is an attribute of the table which have the reference of a primary key in Second Table.



CREATE TABLE Orders
(
O_Id int NOT NULL PRIMARY KEY,
OrderNo int NOT NULL,
P_Id int FOREIGN KEY REFERENCES Persons(P_Id)
)

and Here on question arise that is, foreign key should be primary key in second table or not?
 So don't be confuse i am clearing you.
Its not necessary that foreign key should be unique or primary key.
it is simple an attribute as other attribute in table.




Note-if you are very confused so do it practically. make table and apply all keys and try to understand.
Follow this Link to Help...www.w3schools.com

No comments:

Post a Comment