Solved

Using TSQL to make a PK column identity specification

Posted on 2006-06-24
4
484 Views
Last Modified: 2008-02-26
How do I, using TSQL, make a column in a table named IDNumber (which is a primary key) identity specification?  And how do I make it, if it is identity specification, not identity specification?
0
Comment
Question by:stev0931
  • 2
  • 2
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16975700
you cannot change a column to change the identity specification, you have to drop and recreate the column to change it.
another way is to recreate the column entirely.

you should not need to change the specification of identity in prod application, can you explain why you want to do this?
 
0
 

Author Comment

by:stev0931
ID: 16976086
I want to move data from 4 tables from one database to another.  I tried doing an Export Data, but it failed since the fields are identity specification
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 16976409
>but it failed since the fields are identity specification

with DTS, there is a option to allow to insert into a identity field.
in TSQL, the command would be

SET IDENTITY_INSERT ON (tablename)

INSERT ....

SET IDENTITY_INSERT OFF (tablename)
0
 

Author Comment

by:stev0931
ID: 16976712
Thanks!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question