SqlShare.com Logo
 
Skip Navigation Links
Home
Video List
Classes
About Us
Login / Register
Subscribe RSS Feed 

Idera Virtual Database

Using Identity Insert to Insert Rows

If you've ever worked with a table that includes a column that is set to an identity (auto number) you know that happiness is nicely ascending keys. What happens when someone deletes a row by mistake, how do you put it back? By default if you specify a value for the identity column an error message is generated, which brings us to our topic today - identity insert!

Duration:
2 mins 32 secs
Skill Level:
100
Rating:
4.48 out of 5
Publish Date:
February 02, 2010
Using Identity Insert to Insert Rows Watch Video Now  Watch it later!
Bookmark and Share
 
1=Poor, 3=Good, 5=Excellent

About the Author

Image of Andy Warren
Andy Warren is a software trainer focusing on SQL Server, a member of the PASS Board of Directors, and a principal in this site - SQLShare.com.

References

There are no downloads or recommended reading links for this video

Comments
Bill Nicolich on 2/2/2010
Perfect.

Stéphane Thinel on 2/2/2010
Straight to the point, with a good example I love it.

Kevin Ray on 2/2/2010
Did not know you could do that. Wish there was a way in MS Access to do the same thing.

Ron Newlin on 2/2/2010
concise no distractions

Huonglien Nguyen on 2/2/2010
Very useful information. Thank you very much.

Chris Williams on 2/2/2010
Pretty basic stuff, but well done nonetheless. I was hoping for code that would find the gap in the sequence and use that 'missing' value for the ID as the next record was inserted. ;-p

Stevan Cohen on 2/2/2010
I did not know that ... Intersting

Feroz Durani on 2/2/2010
This vedio is indeed usefull. Can you come up with more vedios on ow to create Expressions in SSIS packages. More realistic examples on building expressions.

Feroz Durani on 2/2/2010
This vedio is indeed usefull. Can you come up with more vedios on ow to create Expressions in SSIS packages. More realistic examples on building expressions.

Deborah Furse on 2/3/2010
This is something that everyone needs. Great Video.

WChaster on 2/4/2010
To use this to back fill key values then one could simply create a SQL block that started by turning on and ending by turning off the identity feature. This was a very useful topic.

achied on 2/5/2010
i've been in that situation before..

achied on 2/5/2010
For Chris: Find a gap in identity column. Please see this link http://msdn.microsoft.com/en-us/library/aa933196%28SQL.80%29.aspx, You can make this code in the form of function or stored procedure. I've tried it, very simple.

Joegar Ochoa on 2/5/2010
another great share

Rich on 2/5/2010
Great, thanks! Another thing I learned that wasn't explicitly in the video is that, when IDENTITY_INSERT is set to ON, you can add several rows with the same key value (not what we want usually). So, another reason to be sure to turn it OFF after replacing the deleted row.

Christian Bahnsen on 2/5/2010
Very helpful. Thanks.

32DE12EB89 on 2/6/2010
Very good tip - thanks.

Video muito bom, excelente explicação sobre operação com campos identity.

Michel Archambualt on 5/15/2010
Useful trick.

afshin on 8/24/2010
Awesome example, Is there any way to copy paste your code and try it ourselves to practice.



Must Be Logged In
 

How Do I Become a Video Author? |  Newsletter History

Copyright © Fourdeuce, Inc., 2005-2009. All Rights Reserved | Privacy Policy | Terms & Conditions