Primary Key
Q.1: What is the primary key in SQL Server?
Answer:
The primary key should contain the UNIQUE Values, but can not contain NULL values. A table can have only one primary key. A primary key in sql server can be created as shown below.
Syntax:
ALTER TABLE table_name
ADD CONSTRAINT constraint_name PRIMARY KEY (column_name);
Q.2: What is time-invariant in the primary key?
Answer:
The values of the primary key must not change or become null during life time of relation. For example we cannot choose the Name attribute of the EMPLOYEE Relation as a primary key because there is no guarantee that two employees with the same name will never exist.
Q.3: Explain the characteristics of the primary key.
Answer:
- A relation can contain only one primary key.
- A primary key may be composed of a single attribute known as single primary key or more than one attribute know as composite primary key.
- A primary key is also called as minimum super key.
- The data values for the primary key attributes should not be null.
Primary Key in DBMS
In DBMS there are different types of keys available that are used for various purposes, for which the most common key is known as a primary key. A primary key is a unique identifier assigned to each record within a database table.