Solved

How can I disable and re-enable the IDENTITY property on a table column using T-SQL.

Posted on 2004-08-30
3
906 Views
Last Modified: 2008-01-09
I would like to be able to disable and re-enable the identity property on a column using T-SQL. Here is my sample table:

CREATE TABLE [dbo].[tblTestIDENT] (
      [Col1] [int] IDENTITY (1, 1) NOT NULL ,
      [Col2] [varchar] (50) NULL
) ON [PRIMARY]
GO

What effect would this have if I have say 100 million records in the table?
0
Comment
Question by:DeMyu
  • 2
3 Comments
 
LVL 12

Expert Comment

by:ill
ID: 11931355
SET IDENTITY_INSERT [tblTestIDENT] ON
insert into tblTestIDENT (col1, col2) values (10, 'test1')
insert into tblTestIDENT (col1, col2) values (1001, 'test2')
SET IDENTITY_INSERT [tblTestIDENT] OFF
insert into tblTestIDENT (col2) values ( 'test3')
select * from [tblTestIDENT]
0
 

Author Comment

by:DeMyu
ID: 11931847
Thank you for your reply. This does not actually remove the identity property of the column in Enterprise Manager. Is there a way to do this in T-SQL such that when I go into EM I wouldn't see the property on the column. I have to do this on a table with about 70 million rows.

Thanks
0
 
LVL 12

Accepted Solution

by:
ill earned 500 total points
ID: 11932089
i'm afraid, you need to recreate table. here is a useful link for you:
http://www.examnotes.net/archive79-2002-7-47264.html
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now