Creating table in sql

  • Thread starter Thread starter mik
  • Start date Start date
M

mik

I realise this is the wrong place to post, but i can't
find an equivalent newsgroup for sql.
My query is simple. Please help!

i'm trying to create a table in a database. It needs a
primary key and the primary key should increment.

i've written:
CREATE TABLE animals
(
Id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
Name VARCHAR(30) NOT NULL
);


but get this error:
Incorrect syntax near 'AUTO_INCREMENT'.

What am i doing wrong?
 
mik said:
I realise this is the wrong place to post, but i can't
find an equivalent newsgroup for sql.
My query is simple. Please help!

i'm trying to create a table in a database. It needs a
primary key and the primary key should increment.

i've written:
CREATE TABLE animals
(
Id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
Name VARCHAR(30) NOT NULL
);


but get this error:
Incorrect syntax near 'AUTO_INCREMENT'.

What am i doing wrong?


If your are talking about SQL Server and T-SQL, please post to:

microsoft.public.sqlserver.programming

Willy.
 
Hi,


You are right, this is not the group for this, anyway this is how you
declare a PK

create table T1
(
CrewID SMALLINT IDENTITY PRIMARY KEY NOT NULL
)


Cheers,
 
Microsoft.public.sqlserver.programming is where you'd want.

Anyway, the equivalent to auto_increment is identity. So, your ddl would
look like this.
CREATE TABLE animals
(
[Id] INT IDENTITY NOT NULL PRIMARY KEY ,
[Name] VARCHAR(30) NOT NULL
);
 
Back
Top