Microsoft Data Technology · Microsoft SSDB

SQL Server: INSERT values to IDENTITY column

Problem:

How to insert values into Identity columns

 

Details:

Identity field is system generated key value for the table and it is mostly the primary key. While inserting a new record into your table, this field automatically assign an incremented value by looking at the previous value. There may be situation you want to manually enter the key value without resorting on the automatic process. Normally we create -1 key value in the world of Dimensional modelling with DIM and FACT tables. Dimension tables with -1 Dimkey can be manually created for the purpose of identifying the non-exiting records while processing the FACT tables.

 

Solution:

The following SQL code will INSERT a record with the DIMKEY column with -1


 

 

 

 

 

 

Result:


What do you think?

I hope you enjoy the tip in this blog. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s