Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Removing IDENTITY from a tabe column
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_C
P1_CI_AS NULL
 ,
[opId] [nvarchar] (50) COLLATE  SQL_Latin1_General_C
P1_CI_AS NULL ,
[comments] [nvarchar] (64) COLLATE  SQL_Latin1_General_C
P1_CI_AS NULL
 ,
& #91;eventProperties]
 [nvarchar] (1024) COLLATE  SQL_Latin1_General_C
P1_C
I_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

Report this thread to moderator Post Follow-up to this message
Old Post
Hari
07-28-05 08:23 AM


Re: Removing IDENTITY from a tabe column
Hi,

You need to drop and create the table to remove IDENTITY property.

If you use Enterprise manager it internally copy the data outside,script the
schema, modify the script to remove identity
and create the table back and load data.

Thanks
Hari
SQL Server MVP



"Hari" <Hari@discussions.microsoft.com> wrote in message
news:F8F07062-110A-4E07-8526- 5D93E3B6C063@microso
ft.com...
> 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'IsUserTabl
e') = 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_C
P1_CI_AS NU
LL ,
> [opId] [nvarchar] (50) COLLATE  SQL_Latin1_General_C
P1_CI_AS NULL ,
> [comments] [nvarchar] (64) COLLATE  SQL_Latin1_General_C
P1_CI_AS NU
LL ,
> & #91;eventProperties]
 [nvarchar] (1024) COLLATE  SQL_Latin1_General_C
P1
_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



Report this thread to moderator Post Follow-up to this message
Old Post
Hari Prasad
07-28-05 08:23 AM


Re: Removing IDENTITY from a tabe column
Here's the script:

ALTER TABLE dbo.EventLog ADD NewRecordID int NULL
GO
UPDATE dbo.EventLog SET NewRecordID = RecordId
GO
ALTER TABLE dbo.EventLog DROP CONSTRAINT PK_EventLog
GO
ALTER TABLE dbo.EventLog DROP COLUMN RecordId
GO
EXEC sp_rename 'EventLog.NewRecordID', 'RecordId'
GO
ALTER TABLE dbo.EventLog ALTER COLUMN RecordId int NOT NULL
GO
ALTER TABLE dbo.EventLog ADD CONSTRAINT PK_EventLog PRIMARY KEY CLUSTERED
(RecordId) ON [PRIMARY]
GO

Make sure there's nobody making changes to this data while you are running
this script.
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/


"Hari" <Hari@discussions.microsoft.com> wrote in message
news:F8F07062-110A-4E07-8526- 5D93E3B6C063@microso
ft.com...
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_C
P1_CI_AS NULL
 ,
[opId] [nvarchar] (50) COLLATE  SQL_Latin1_General_C
P1_CI_AS NULL ,
[comments] [nvarchar] (64) COLLATE  SQL_Latin1_General_C
P1_CI_AS NULL
 ,
& #91;eventProperties]
 [nvarchar] (1024) COLLATE  SQL_Latin1_General_C
P1_C
I_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



Report this thread to moderator Post Follow-up to this message
Old Post
Narayana Vyas Kondreddi
07-28-05 12:23 PM


Re: Removing IDENTITY from a tabe column
Thank you verymuch for your suggetion.

Hari


"Narayana Vyas Kondreddi" wrote:

> Here's the script:
>
> ALTER TABLE dbo.EventLog ADD NewRecordID int NULL
> GO
> UPDATE dbo.EventLog SET NewRecordID = RecordId
> GO
> ALTER TABLE dbo.EventLog DROP CONSTRAINT PK_EventLog
> GO
> ALTER TABLE dbo.EventLog DROP COLUMN RecordId
> GO
> EXEC sp_rename 'EventLog.NewRecordID', 'RecordId'
> GO
> ALTER TABLE dbo.EventLog ALTER COLUMN RecordId int NOT NULL
> GO
> ALTER TABLE dbo.EventLog ADD CONSTRAINT PK_EventLog PRIMARY KEY CLUSTERED
> (RecordId) ON [PRIMARY]
> GO
>
> Make sure there's nobody making changes to this data while you are running
> this script.
> --
> HTH,
> Vyas, MVP (SQL Server)
> SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/
>
>
> "Hari" <Hari@discussions.microsoft.com> wrote in message
> news:F8F07062-110A-4E07-8526- 5D93E3B6C063@microso
ft.com...
> Hi Guys,
>
> I have created a table containg a column with IDENTITY keyword. I have dat
a
> 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'IsUserTabl
e') = 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_C
P1_CI_AS NU
LL ,
> [opId] [nvarchar] (50) COLLATE  SQL_Latin1_General_C
P1_CI_AS NULL ,
> [comments] [nvarchar] (64) COLLATE  SQL_Latin1_General_C
P1_CI_AS NU
LL ,
> & #91;eventProperties]
 [nvarchar] (1024) COLLATE  SQL_Latin1_General_C
P1
_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
>
>
>

Report this thread to moderator Post Follow-up to this message
Old Post
Hari
07-29-05 01:23 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

MS SQL Server archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 10:52 AM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006