Monday, October 22, 2012

What is primary key and foreign key?



  1. A primary key is the field(s) in a table that uniquely defines the row in the table; the values in the primary key are always unique. A foreign key is a constraint that establishes a relationship between two tables. This relationship typically involves the primary key field(s) from one table with an adjoining set of field(s) in another table (although it could be the same table). The adjoining field(s) is the foreign key.

    How to Create Primary Key with Specific Name while Creating a Table?
    CREATE TABLE [dbo].[TestTable](
    [ID] [int] IDENTITY(1,1)NOTNULL,
    [FirstName] [varchar](100)NULL,
    CONSTRAINT [PK_TestTable] PRIMARYKEYCLUSTERED
    ([ID] ASC))
    GO

No comments:

Post a Comment