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
 General SQL Server Forums
 New to SQL Server Programming
 Auto Incremental Column?

Author  Topic 

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2011-07-06 : 04:40:26
Hi,

I am using SQL Server 2008 R2 and I would like to know if I can add an auto incremental column other than primary key??? I would like to have DeliveryID to be auto incremental.

Thanks in advance.
Best Regards.

here is my sample table:
CREATE TABLE [dbo].[Table1](
[RequestID] [int] IDENTITY(1,1) NOT NULL,
[VendorID] [int] NULL,
[RequestDate] [datetime] NULL,
[ItemID] [int] NULL,
[PackageID] [int] NULL,
[Quantity] [int] NULL,
[Total] [int] NULL,
[StatusID] [int] NULL,
[DeliveryID] [int] NULL,

CONSTRAINT [PK_VendorRequest] PRIMARY KEY CLUSTERED
(
[RequestID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-06 : 05:03:38
No, you can't have two identity columns.
You can of course make theRequestID not auto increment.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-07-06 : 05:34:27
Wait... It depends.
If you are using Denali you can use the SEQUENCE object to do this.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -