473,386 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Creating table in sql

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?
Nov 17 '05 #1
3 4659

"mik" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
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.



Nov 17 '05 #2
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"mik" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
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?

Nov 17 '05 #3
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
);

--
-oj
"mik" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
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?

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: Neil | last post by:
I have an Access 2000 MDB with ODBC linked tables to a SQL Server 7 back end. I currently have a selections table in the front end file which the users use to make selections of records. The table...
7
by: John Baker | last post by:
Hi: I would like to know how to create a temp DB to store the data in a table while I do something else with the table. Specifically, how do I create the temp remove the temp I want to be...
1
by: Dixie | last post by:
I wish to add some fields to an existing table in code. I am using the following code from rkc. CurrentDb.Execute ("ALTER TABLE MyTable ADD MyNewField Text 25") This works , but I need to also set...
8
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1;...
3
by: m3ckon | last post by:
Hi there, I can succesfully create a word doc from my asp.net page, but I have 2 issues I need to resolve in order to use it in my app: 1) Creating a table: I seem unable to create a table,...
4
by: Coleen | last post by:
Hi All :-) Can anyone give me a URL where I can find a good example of code on how to create a temporary SQL table using VB.net? I've checked the Microsoft site at: ...
16
by: pukivruki | last post by:
hi, I wish to create a temporary table who's name is dynamic based on the argument. ALTER PROCEDURE . @PID1 VARCHAR(50), @PID2 VARCHAR(50), @TICKET VARCHAR(20)
2
by: astolpho | last post by:
I am using a slightly outdated reference book on J2EE programming. It gives 2 methods of creating a database used in its casestudies. The first is an ANT script that gives the following output: ...
2
by: djpaul | last post by:
Hello, I have this program and when i want to load pictures it crashes at the form.showdialog()....??? Here it goes: Private Sub CmbPath_SelectedIndexChanged(ByVal sender As Object, ByVal e As...
6
by: firefighter17103 | last post by:
Hi All, I am new to MS Access 07, & do not know any VB, on a new business adventure. I am running Office07 on Vista Home Premium. I am in the process of creating a database that in the end I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.