how to create my own primary key which auto-increment

how to create my own primary key which auto-increment

am 18.04.2008 16:58:54 von 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

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

am 18.04.2008 19:42:58 von 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

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

am 18.04.2008 19:48:39 von 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