Click to See Complete Forum and Search --> : its been a while since I've used sql....


neil
01-20-2004, 11:23 AM
...and I was using mySql b4, but on ms sql server when you create a table whats the syntax for specifying a field that auto increments for each new record added?

'm trying the following:

1> create table maillist(id autoincrement(), email varchar)
2> go
Msg 170, Level 15, State 1, Server ****, Line 1
Line 1: Incorrect syntax near ')'.
1>

neil
01-20-2004, 12:11 PM
Somebody posted me the solution on another forum

CREATE TABLE maillist ([ID] [INT] IDENTITY (1,1) NOT NULL, Email VARCHAR(500))

INSERT INTO maillist (Email) VALUES ('myemail@yahoo.com')

SELECT * FROM maillist

(1 row(s) affected)

ID Email
1 myemail@yahoo.com