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
aliakhthar [ Fr, 18 April 2008 16:58 ] [ ID #1945247 ]

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

HTH,

Plamen Ratchev
http://www.SQLStudio.com
Plamen Ratchev [ Fr, 18 April 2008 19:42 ] [ ID #1945248 ]

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....unlike Oracle there is no sequence object
in SQL Server to do what youre describing
jimbo [ Fr, 18 April 2008 19:48 ] [ ID #1945249 ]
Datenbanken » comp.databases.ms-sqlserver » how to create my own primary key which auto-increment

Vorheriges Thema: select parent records that do not have a particular child
Nächstes Thema: HELP WITH SELECT STATEMENT PLEASE