Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

how to create my own primary key which auto-increment

 
   Database Forums (Home) -> General Discussions RSS
Next:  import ADO DLL  
Author Message
aliakhthar

External


Since: Apr 18, 2008
Posts: 1



(Msg. 1) Posted: Fri Apr 18, 2008 7:58 am
Post subject: how to create my own primary key which auto-increment
Archived from groups: comp>databases>ms-sqlserver (more info?)

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

 >> Stay informed about: how to create my own primary key which auto-increment 
Back to top
Login to vote
Jimbo

External


Since: Apr 26, 2007
Posts: 9



(Msg. 2) Posted: Fri Apr 18, 2008 10:48 am
Post subject: Re: how to create my own primary key which auto-increment [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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

 >> Stay informed about: how to create my own primary key which auto-increment 
Back to top
Login to vote
Plamen Ratchev

External


Since: Nov 06, 2007
Posts: 352



(Msg. 3) Posted: Fri Apr 18, 2008 1:42 pm
Post subject: Re: how to create my own primary key which auto-increment [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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
 >> Stay informed about: how to create my own primary key which auto-increment 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Primary Key fails to copy in db Export - Currently, I'm exporting a database from production to local (test) machine. I've done this several times without problem, but during the last few days, the primary keys have failed to export. Would anyone know what options might keep the keys from..

confusion over indexs via primary key and clustered index - Hi I thought that given a table with an index, primary key and clustered index any non clustered index look ups would go via the clustered index and the primary key is irrelevant? (sql server 2000). A colleague has said that the primary key should be..

Relationships error, C# Visual Studio 2005 database bug?, .. - Problem: I replicated, using Frasier "Pro Visual C++/CLI" (2006), Chap 12, a database that has a relationship between two tables, called Content and Author, using a common column, called "AuthorID". I used the Server Explorer inside...

Create view from cursor - I have multiple locations that I want to create views for each individual location. I am using a cursor to create the views for each location. So, the cursor grabs site #1 then <should> create view_site_#1, then grab site #2 and <should> cr...

Create Function permission... - How do I give a Windows group complete rights (including create) to all stored procedures and user defined functions without giving them dbo access in SQL Server 2005? If I have to I can do it from the Management Console, but I would also like to kno...
   Database Forums (Home) -> General Discussions All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]