SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Auto increment

  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2002
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Auto increment

    I have a table with primary key and I'd like to increment the primary key automatically. Table has six fields (now), which are message_id (int primary key), message_parent_id(int), topic (varchar(64)), author(varchar(64)), message(varchar(2048)), and date_entered(datetime). When I pass the following SQL to MS Access using ODBC, Access creates new id number automatically.

    sSQL = "insert into messages (" +
    "topic," +
    "author," +
    "message," +
    "date_entered)" +
    " values (" +
    "'abced'" + "," +
    "'abced'" + "," +
    "'abced'" + "," +
    "'abced'" + ")";

    But when I do this to MS SQL Server, it doesn't work. How do I modify the SQL? Do I need to recreate the table? Thank you for your help in advance.

  2. #2
    morphine for a wooden leg randem's Avatar
    Join Date
    Jun 2002
    Location
    .chicago.il.us
    Posts
    957
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    An "auto-increment" field in MS SQL Server is called "identity".

    I don't think you can change it with ALTER TABLE... I think that has to be set in the CREATE TABLE statement.
    ----Adopt-a-Sig----
    Your message here!


Bookmarks

Posting Permissions

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