Thread: Auto Increment?

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    12
    Rep Power
    0

    Auto Increment?


    In MYSQL, there was a column option for auto-increment. Is there such a thing in MSSQL? How do I set up a column to auto-increment when a new record is added?

    Thanks!

    Matthew
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,440
    Rep Power
    4539
    When you define your column add IDENTITY. Here is a sample from the SQL Server BOL

    Code:
    CREATE TABLE new_employees
    (
     id_num int IDENTITY(1,1),
     fname varchar (20),
     minit char(1),
     lname varchar(30)
    )

IMN logo majestic logo threadwatch logo seochat tools logo