Introduction
In this article i will explain about How to define a Auto incremented Primary Key in table.
Practice
You all are familiar with he Primary Key constraint and here i am using an additional keyword named IDENTITY for performing this operation.
The First Primary Key as its name implies it allows only Unique values and also don't allow to null values.Means if we define a column using Primary key then no value of this column can repeat and never same. We have only one Primary key in a single table.
The second one is IDENTITY which informs SQL server to auto increment numeric values with in a specified column after inserting any new record.
After this table creation , any time the insertion operation performed for the table then Id column automatically incremented by 1. This is very useful when you want to indexing your data. And some times there is need to count total records and find the particulate row record set .
The First Primary Key as its name implies it allows only Unique values and also don't allow to null values.Means if we define a column using Primary key then no value of this column can repeat and never same. We have only one Primary key in a single table.
The second one is IDENTITY which informs SQL server to auto increment numeric values with in a specified column after inserting any new record.
CREATE TABLE EmpDetail
(
Id INT NOT NULL IDENTITY PRIMARY KEY,
Name VARCHAR(50),
Designation VARCHAR(50)
)
(
Id INT NOT NULL IDENTITY PRIMARY KEY,
Name VARCHAR(50),
Designation VARCHAR(50)
)
After this table creation , any time the insertion operation performed for the table then Id column automatically incremented by 1. This is very useful when you want to indexing your data. And some times there is need to count total records and find the particulate row record set .
0 comments:
Post a Comment