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
 How do you setup an auto-increment column?

Author  Topic 

BuzzParker
Starting Member

5 Posts

Posted - 2009-08-16 : 07:34:04
I am using sql server 2005 server mgmt studio. I tried to create a table with the following commands and it fails on the auto-increment command.

USE "mydatabase";

CREATE TABLE "stable" (
"id" bigint(20) NOT NULL auto_increment,
"ip" varchar(50) default NULL,
"hname" varchar(100) default NULL,
"time" time default NULL,
"date" date default NULL,
"fname" varchar(50) default NULL,
PRIMARY KEY ("id")
);

I get:
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near 'auto_increment'.

Shouldn't this work?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-16 : 08:14:33
Date and Time datatypes are available for SQL Server 2008 and later.
CREATE TABLE	stable
(
id bigint identity(1, 1) primary key,
ip varchar(50),
hname varchar(100),
[time] datetime,
[date] datetime,
fname varchar(50)
)



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

- Advertisement -