Results 1 to 4 of 4

Thread: Create Table on SQL Server

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Manchester, UK
    Posts
    50
    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?

  2. #2
    Banned
    Join Date
    Feb 2000
    Location
    Edmonton, AB, Canada
    Posts
    64
    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.

  3. #3
    Guest

    correct way

    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!

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Manchester, UK
    Posts
    50

    Cool Thanks

    Thanks, I have got it to work now!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width