Groups | Blog | Home
all groups > sql server programming > july 2005 >

sql server programming : Removing IDENTITY from a tabe column


Hari
7/27/2005 7:28:03 PM
Hi Guys,

I have created a table containg a column with IDENTITY keyword. I have data
in the table. Now i need to alter this table without IDENTITY for that
column. Please help me get a sql script to do this one.

The creation scirpt for the table is :

if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[EventLog]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[EventLog];

CREATE TABLE [dbo].[EventLog] (
[RecordId] [int] IDENTITY (1, 1) NOT NULL ,
[eventId] [int] NOT NULL ,
[eventType] [int] NOT NULL ,
[eventDateTime] [datetime] NULL ,
[AimNumber] [int] NULL ,
[eventMsg] [nvarchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[opId] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[comments] [nvarchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[eventProperties] [nvarchar] (1024) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL
) ON [PRIMARY];

ALTER TABLE [dbo].[EventLog] WITH NOCHECK ADD
CONSTRAINT [PK_EventLog] PRIMARY KEY CLUSTERED
(
[RecordId]
) ON [PRIMARY] ;


Now i need script for altering the just identity column.?????

Hari
sajeevp
7/27/2005 8:52:10 PM
I think

-----------------------
alter table [dbo].[EventLog]
alter column [RecordId] [int]
-----------------------

thsi will work




[quoted text, click to view]
sajeevp
7/27/2005 8:52:21 PM
I think

-----------------------
alter table [dbo].[EventLog]
alter column [RecordId] [int]
-----------------------

this will work




[quoted text, click to view]
sajeevp
7/27/2005 8:52:22 PM
I think

-----------------------
alter table [dbo].[EventLog]
alter column [RecordId] [int]
-----------------------

this will work




[quoted text, click to view]
sajeevp
7/28/2005 6:05:23 AM
that was a wrong post .. sorry
Aaron Bertrand [SQL Server MVP]
7/28/2005 8:51:24 AM
[quoted text, click to view]

No, it will not. Did you try it?

Hari
7/28/2005 10:41:02 AM
Thanks for your suggetion.

Hari


[quoted text, click to view]
Hari Prasad
7/28/2005 1:20:29 PM
Hi,

You can not remove the IDENTITY property using Alter table command.

Only way is export data into a new table using

1. SELECT * INTO newtable from existing table
2. create new table with out identity
3. insert the data from new table
4. drop the existing table and rename the new table using sp_rename

Enterprise manager internally almost does the above steps to remove identity
property.

Thanks
Hari
SQL Server MVP




[quoted text, click to view]

AddThis Social Bookmark Button