Monday, August 22, 2011

Composite Primary Key in Sql Server

Usually we can create One Primary key. Composite Primary key means multiple Column names in a table..
General Primary Key Syntax:-
Create table <Table_name>
(
    Column_names <Data_type>
    --------
   --------
   Primary Key (Column_name)
)

Composite Primary Key  Syntax:-

Create table <Table_name>
(
    Column_names <Data_type>
    --------
   --------
   Primary Key (Column1,Column2)

)

We can Create Foreign Key on Composite Primary Key

Create table <Table_name>
(
    Column_names <Data_type>,
    --------,
   --------,
   Foreign key(TableB Columns) References TableA (Composite Primary Key Columns)

)



No comments:

Post a Comment