October 24, 2006 at 9:41 pm
Can the identity be dropped from a column using Transact SQL? Alter table alter column does not appear to provide this option.
Regards
BanOcto
October 25, 2006 at 2:35 am
Hi,
This need to create a new table changing the identity column to your requirement and migrate the data from the old one.
Here is sample script for this.
CREATE TABLE dbo.Table1
(
id int identity(1,1) NOT NULL,
name char(10) NULL
  ON [PRIMARY]
GO
BEGIN TRANSACTION
CREATE TABLE dbo.Tmp_Table1
(
id int NOT NULL,
name char(10) NULL
  ON [PRIMARY]
GO
IF EXISTS(SELECT * FROM dbo.Table1)
EXEC('INSERT INTO dbo.Tmp_Table1 (id, name)
SELECT id, name FROM dbo.Table1 TABLOCKX')
GO
DROP TABLE dbo.Table1
GO
EXECUTE sp_rename N'dbo.Tmp_Table1', N'Table1', 'OBJECT'
GO
COMMIT
I hope this will slove your problem.
Thanks
Ijaz
cheers
October 25, 2006 at 5:42 am
Thanks Ijaz
October 25, 2006 at 12:31 pm
becareful!
if you have triggers or indexes those will not carry over with the above script. If you don't then consider yourself a happy camper
* Noel
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply