Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

dbf2mysql parameter, WWWXXXAPC, wwwxxxAPC, How to unsubscrube from dategen spam, docmd.close 2585, WWWXXXDOCO, nu vot, dhcpd lease file "binding state", WWWXXXDOCO, how to setup procmail to process html2text

Links

XODOX
Impressum

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

Posted on 2008-04-18 16:58:54 by aliakhthar

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

Report this message

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

Posted on 2008-04-18 19:42:58 by Plamen Ratchev

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_value
FROM ...

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Report this message

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

Posted on 2008-04-18 19:48:39 by jimbo

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

Report this message