July 26, 2001 at 11:51 pm
Hi all
Im having some trouble working out the syntax to alter a table column and remove the IDENTITY property from it. I have a large data move coming up and need to "turn off" identity of some of the tables, insert the data, and reapply the identity after the load.
Ideas?
Cheers
Chris
Chris Kempster
www.chriskempster.com
Author of "SQL Server Backup, Recovery & Troubleshooting"
Author of "SQL Server 2k for the Oracle DBA"
July 27, 2001 at 4:32 am
SET IDENTITY_INSERT tablename ON
INSERT INTO tablename .......
SET IDENTITY_INSERT tablename OFF
Note that only one table at a time (per session) can have IDENTITY_INSERT on.
Chris Hedgate @ Apptus Technologies (http://www.apptus.se)
July 27, 2001 at 11:57 am
July 29, 2001 at 9:30 pm
Hi guys
Hmmm.. yeh, knew this one and wasnt what I was after . Basically I wanted to permanently remove IDENTITY from a column via an ALTER DATABASE statement. Is this only possible via dropping the table all together?
Cheers
Chris
Chris Kempster
www.chriskempster.com
Author of "SQL Server Backup, Recovery & Troubleshooting"
Author of "SQL Server 2k for the Oracle DBA"
July 30, 2001 at 12:00 am
Hey, I just profiled it a couple times, then changed the identity setting via EM several times - looks like it does drop the table each time, but at least you don't have to do the work! Possibly because its late Im just not seeing it, but the only alter I see are those performed on the "new" table to apply constraints to it. That sorta makes sense since identity is treated like a constraint, but where is the "drop identity" or whatever?
Anyone have any insight to offer?
Andy
July 30, 2001 at 9:26 pm
Andy
Hey there Andy, check this out from profiler...my table "aaaaa" didnt have identity enabled, then enabled it and got this:
CREATE TABLE dbo.Tmp_aaaaa
(
aaa int NOT NULL IDENTITY (1, 1),
bbb char(10) NULL
) ON [PRIMARY]
go
SET IDENTITY_INSERT dbo.Tmp_aaaaa ON
go
IF EXISTS(SELECT * FROM dbo.aaaaa)
EXEC('INSERT INTO dbo.Tmp_aaaaa (aaa, bbb)
SELECT aaa, bbb FROM dbo.aaaaa TABLOCKX')
go
SET IDENTITY_INSERT dbo.Tmp_aaaaa OFF
DROP TABLE dbo.aaaaa
exec sp_cursoropen @P1 output, N'EXECUTE sp_rename N''dbo.Tmp_aaaaa'', N''aaaaa'', ''OBJECT''
go
Chris Kempster
www.chriskempster.com
Author of "SQL Server Backup, Recovery & Troubleshooting"
Author of "SQL Server 2k for the Oracle DBA"
August 1, 2001 at 7:54 am
August 6, 2001 at 2:33 am
Yep.
Chris Kempster
www.chriskempster.com
Author of "SQL Server Backup, Recovery & Troubleshooting"
Author of "SQL Server 2k for the Oracle DBA"
August 6, 2001 at 12:24 pm
If you make the change in EM and then click the "script" button (3rd from left) you should see this. Many things you do in EM are only possible through dropping a table and this is usually how EM scripts it.
Steve Jones
June 21, 2017 at 12:48 am
This was removed by the editor as SPAM
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply