Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Have a major issue with Identity Specification...

Author  Topic 

prototype18
Starting Member

7 Posts

Posted - 2010-10-08 : 13:36:12
I need to make an auto increment primary key field in one of my tables, so I tried setting up the Identity Specification but it will not allow me to change the setting from NO to YES. I have tried just about every common sense approach but no success.

So I re-created the table from scratch with no data, and I still cannot declare or set the identity specification on that specific field, primary key or not.

Any help would be greatly appreciated. THANKS!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-08 : 13:39:12
CREATE TABLE Table1 (Table1Id int identity(1, 1) NOT NULL, SomeOtherColumn, ...)

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

prototype18
Starting Member

7 Posts

Posted - 2010-10-08 : 13:46:03
CREATE TABLE [dbo].[tbreso]
(
[ITEM] [varchar](6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[OWN_1] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[OWN_2] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[OWN_4] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PROP_1] [varchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PROP_2] [varchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PROP_ZIP] [varchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[KEYFIELD] [char](21) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[KEY_T_B_RESO] [int identity (1, 1)] COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[CC_] [char](6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
)

Its failing on the int identity...
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-08 : 13:48:30
Your syntax is wrong.

KEY_T_B_RESO int identity (1, 1)

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

prototype18
Starting Member

7 Posts

Posted - 2010-10-08 : 13:51:05
CREATE TABLE [dbo].[tbreso]
(
[ITEM] [varchar](6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[OWN_1] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[OWN_2] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[OWN_4] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PROP_1] [varchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PROP_2] [varchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PROP_ZIP] [varchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[KEYFIELD] [char](21) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[KEY_T_B_RESO] [int identity] (1,1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[CC_] [char](6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
)

Still failing.

Msg 156, Level 15, State 1, Line 12
Incorrect syntax near the keyword 'COLLATE'.

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-08 : 13:53:21
You haven't done what I showed. Get rid of those square brackets.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-08 : 13:56:48
And if you insist on using square brackets (they aren't needed in your script as you don't have any special characters), then do this:

[KEY_T_B_RESO] [int] identity (1,1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL

I'd remove all of the square brackets from your script as it just makes it hard to read and is completely unnecessary for that table.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -