Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2007

    Question Unanswered: Set custom Identity keys for master tables(auto-incrementing):

    I need some help for designing the IDs / Primary keys for some master tables in my database. Following are master tables. Client_Master, Buyer_Master & Seller_Master; I want to set Client_Id, Buyer_Id & Seller_Id as their respective primary keys and they should have following properties

    Client_Id :- a) should be auto-incrementing value, b) unique & c)should be of the format – CLXXXXXX, where “CL” {Constant start characters} & “X” {any number 0-9}
    Buyer_Id :- BYXXXXXX
    Seller_Id :- SLXXXXXX

    We are implementing the database in MS-SQL 2005 & MySQL

    Can anyone help me find a solution to this, especially in MS-SQL.

  2. #2
    Join Date
    Apr 2002
    Toronto, Canada
    use an ordinary IDENTITY column and then define a computed column for the wacky prefix | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2004
    One Flump in One Place
    ... or don't bother storing the prefix in the table at all and just add it to the beginning of the ID when displaying the data. This would be a perfect candidate for a view.
    pootle flump
    ur codings are working excelent.

Posting Permissions

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