How to create sequence in SQL Server 2000??

  • Dear all,

    I would like to create set of SQL statement to generate auto ID when new data is inserted. How I can do this in SQL Server 2000.

    Thanks you for reply!!!

  • Add a IDENTITY column, sql will automatically increment the column when new rows are inserted.

    Far away is close at hand in the images of elsewhere.
    Anon.

  • David Burrows, Thanks you for reply!!

    I still have question about using IDENTITY column. What data type does it return when I use it?? Can I use this to auto generate string value??

    Thanks a lot!!

  • Identity columns can be one of decimal, int, numeric, smallint, bigint, or tinyint, a number by definition. They are normally assigned when a table is created, eg

    CREATE TABLE [tablename] (rowid int IDENTITY(1,1), col1 char(1))

    You do not specifiy the column when inserting, the system automatically generates it for you, eg

    INSERT INTO [tablename] (col1) VALUES ('A')

    If you want character based values then you will have to create them within a procedure prior to INSERT or use a trigger.

    Far away is close at hand in the images of elsewhere.
    Anon.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply