Tuesday, August 20, 2013

TSQL Interview Questions: Primary Key

uniquely defines the characteristics of each row (also known as record or tuple). The primary key has to consist of characteristics that cannot be duplicated by any other row. The primary key may consist of a single attribute or a multiple attributes in combination. For example, a birthday could be shared by many people and so would not be a prime candidate for the Primary Key, but a social security number or Driver's License number would be ideal since it correlates to one single data value. Another unique characteristic of a Primary Key as it pertains to a relational database is that a Primary Key must also serve as a Foreign Key on a related table.
A table can have only one PRIMARY KEY constraint, and a column that participates in the PRIMARY KEY constraint cannot accept null values.
The database engine enforces data uniqueness by creating unique index for primary key column.
GO

/****** Object:  Table [ASIA\NBKWHDR].[DataTest]    Script Date: 08/20/2013 17:20:51 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE dbo.[DataTest](
[ID] [int] NOT NULL,
[Name] [nchar](10) NULL,
 CONSTRAINT [PK_DataTest] PRIMARY KEY CLUSTERED
(
[ID] ASC
)
) ON [PRIMARY]

GO



No comments:

Post a Comment