PDA

Click to See Complete Forum and Search --> : Create Table on SQL Server


rodders45
Jan 5th, 2001, 01:06 PM
Does anyone know how to create a primary key field which automatically increments each time you add a new record?

This SQL works in an Access database:

CREATE TABLE News (NewsID AutoIncrement Constraint PrimaryKey PRIMARY KEY, OtherField TEXT (50))

But using SQL Server I get the following error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC SQL Server Driver][SQL Server]Column or parameter #1:
Cannot find data type AutoIncrement

Can you help?

pactalon
Jan 5th, 2001, 03:13 PM
I think you have to do it manually in the code. You'd have to get the ID number of the last record, up that by one, then place it on the next record.

Jan 9th, 2001, 10:56 AM
I think you had better used Identity, check out your sql server help pages (it's really simple, go to the design of your table and check identity 1)


In your SQL you do the following (for example)

Insert into Clients (client_name) " &_
"Values ('" & strName & '") " &_
"Select @@identity as client_id"

hope I helped you out!

rodders45
Jan 9th, 2001, 12:00 PM
Thanks, I have got it to work now!!