SQL SERVER 2008 – How does one generate primary key values for a table

To generate Primary Key values for a column in SQL SERVER table we have a Property IDENTITY( seed , increment )

seed

It is the value that is stored in the first row loaded into the database.

increment

Is the incremental value that gets added each time a row loaded after the first one.

You must specify both the seed and increment value or none of them.

If none of them is specified, then default is taken as  (1,1).

Here is the Script how we can use the Identity Property

Step 1 : Creating a table Customer table with a primary key

create table Customer(custId int Primary Key IDENTITY(1,1),

Name varchar(30))

Step 2: Insert values to the Customer table

insert into Customer values(‘Ravi’)

insert into Customer values(‘david’)

Output :

select * from Customer

Reference : Dilip Kumar Jena ( https://sqlexplore.wordpress.com )

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s