Saturday, November 26, 2011

Primary Key & Foreign Key

Primary key :-

Ø  Uniquely identified row
Ø  Which can be formed with single or multiple columns
Ø  Does not allow duplicate records
Ø  Cannot contain Null

   Foreign key : -

Ø  Another identifier which can be used to build relationship between the tables
Ø  Must be the primary key of parent table with same data type & length
Ø  Can consists of single or multiple columns
Ø  Can contain Null or duplicate rows
Ø  Multiple foreign keys can be defined in one table
Ø  Foreign key should be defined at the time of defining child table in the create command by “WITH REFERENCES” option.

CREATE TABLE ITEM(
  INO INTEGER,
  INAME CHAR(15),
  CNO INTEGER,
  PRIMARY KEY IS INO,
  FOREIGN KEY IS CNO
  WITH REFERENCES CUST)

No comments:

Post a Comment