how to create my own primary key which auto-increment

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • aliakhthar@gmail.com

    how to create my own primary key which auto-increment

    Hi, I'm a newbie in sql server.

    I want to create a primary key that should be auto incremented. for
    example: C0001, C0002, C0003, C0004 etc

    here are the attributes I have for the table

    cust_id, cust_name, cust_address etc
  • Plamen Ratchev

    #2
    Re: how to create my own primary key which auto-increment

    Seems you already have a primary key in the table (cust_id). Why do you want
    another one? You can always do formatting on the client side if the client
    id has to be with some C000 prefix. Or on the server side using a computed
    column or a view.

    SELECT 'C' +
    RIGHT('000' + CAST(cust_id AS VARCHAR(10)), 4) AS
    presentation_va lue
    FROM ...

    HTH,

    Plamen Ratchev


    Comment

    • Jimbo

      #3
      Re: how to create my own primary key which auto-increment

      I would just use SQL Server's identity value, joins on integers are
      faster than on varchars....unl ike Oracle there is no sequence object
      in SQL Server to do what youre describing

      Comment

      Working...