Creating table in sql

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?
 
W

Willy Denoyette [MVP]

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.
 
I

Ignacio Machin \( .NET/ C# MVP \)

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,
 
O

oj

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
);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top