-
SQL Server auto-increment primary key
Can someone teach me how to auto increment the primary key? I am currenlty using ms sql server 2000. I had tried
create table TABLE1
(id int not null auto_increment primary key
);
but it did not work. Please help
Last edited by Phil Weber; 03-18-2006 at 01:38 AM.
-
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
Thank you.
-
Auto Increment Field or Identity Field In MS SQL Server
Creating a Auto Increment field in SQL Server allows a unique number to be generated when a new record is inserted into a table.
Syntax for creating an Auto Increment field in SQL Server.
CREATE TABLE [dbo].[Company](
[CompanyId] [bigint] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](200) NOT NULL,
[Address] [nvarchar](max) NOT NULL,
[Phone] [nvarchar](max) NULL,
[autoBackup] [bit] NOT NULL,
[applycreditlimit] [bit] NULL,
[EmailId] [nvarchar](max) NULL,
[salesTaxPercentage] [numeric](18, 2) NULL)
Here, CompanyId has been set as an Auto Increment Id.
A column which has datatype int, big int, tiny int or small int can only be set as an Auto Increment field.
Suppose, you would like to set the AutoIncrement field (CompanyId) at the remote databases to only use the next number free AFTER the 100.
Here, CompanyId has been set as an Auto Increment Id.
A column which has datatype int, big int, tiny int or small int can only be set as an Auto Increment field.
Suppose, you would like to set the AutoIncrement field (CompanyId) at the remote databases to only use the next number free AFTER the 100.
There’s an “Identity Seed” parameter that you can specify (either through SQL or through the table designer in Enterprise Manager) that will let you set the base value for an Identity/AutoNumber field to the value you want. Any new Identity values will be incremented from this base (using the “Identity Increment” value which you can specify in the same place to determine how much to grow the value by).
Last edited by Hack; 03-04-2011 at 07:49 AM.
Similar Threads
-
By Mark in forum Database
Replies: 5
Last Post: 07-15-2002, 10:24 AM
-
Replies: 2
Last Post: 08-15-2001, 03:03 AM
-
By DavidR in forum Database
Replies: 5
Last Post: 02-14-2001, 11:46 PM
-
By Marie in forum VB Classic
Replies: 0
Last Post: 11-20-2000, 05:32 AM
-
By andriano in forum Enterprise
Replies: 1
Last Post: 10-02-2000, 03:54 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks