Keys and Constraints in SQL Server

Keys and Constraints:
A key is a way of identifying a record in a database table. We can use keys to build relationships between tables because a key refers to a whole record.
A key can be defined on a single column if that’s enough to identify the record, or it can be defined on more than one column if not. The sections that follow introduce the three kinds of keys you can use in a database.

Some of the keys available in SQL server are :
a. Primary key: Allows each row in a table to be uniquely identified and Ensure that no duplicate rows exist and no null values are entered.
b. Unique key: It is used to prevent the duplication of key values within the rows of a table and allow null values.
c. Foreign key: A foreign key is a column or combination of columns that is used to establish and enforce a link between the data in two tables
d. Composite keys: Sometimes it requires more than one attribute to uniquely identify an entity. A primary key that made up of more than one attribute is known as a composite key
Constraints are used to limit the type of data that can go into a table. They are associated with create or alter statements.



0 comments:

Post a Comment

Blogger news