Results 1 to 2 of 2

Thread: More then one Auto Increment Field in SQL Server

  1. #1

    Thread Starter
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    More then one Auto Increment Field in SQL Server

    I have a table, in which my PK is a an AutoIncrement Number (Identity). Now I need another field which needs to be 10 Digit & Unique, is there any way i could have 2 auto increment field? I want to avoid generating the number from front end and the passing it.

    I would prefere if this could be managed in Back End. Could i use trigger for that sort of thing, or any other ideas?

    Thank you.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  2. #2
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    From SQL Server Books On-Line:
    A table can have only one column defined with the IDENTITY property, and that column must be defined using the decimal, int, numeric, smallint, bigint, or tinyint data type.
    Instead of identity columns, I have a numeric field whose value gets populated by the Stored Procedure that executes the INSERT statement. I just get the Max() column value and add 1 to it:
    Code:
    Create Procedure ins_myTable @Field1 varchar(50),
                                 @Field2 varchar(50),
                                 @Field3 varchar(50)
    AS
    
    Declare @IDCol int
    
    Select @IDCol = Max(id_col) + 1 From myTable
    
    If @IDCol Is Null Set @IDCol = 1
    
    Insert Into myTable (id_col, field1, field2, field3)
    Values (@IDCol, @Field1, @Field2, @Field3)
    You might could try something like that.
    Chris

    Master Of My Domain
    Got A Question? Look Here First

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