By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,379 Members | 1,435 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,379 IT Pros & Developers. It's quick & easy.

auto generate ID'S in sqlserver

P: 81
Hi,
My requirement is i want to auto generate ID'S in sqlserver that means
in database one column is there recordid for that coloumn i want to add numbers with no duplication like JDS 10001,JDS 10002,JDS 10003............like that if any record added in database means automatically add that type of id's
if suddenly we deleted that record means that id will not add again how to do dat??
May 27 '08 #1
Share this Question
Share on Google+
2 Replies


Delerna
Expert 100+
P: 1,134
1) Does "JDS " have to be part of the number or can it be totally numeric?
2) If "JDS" is required is there always a single space between it and the number part?
3) can the most recent ID be reused if it gets deleted?

suppose the last ID in the sequence is JDS 1167
If JDS 1167 gets deleted then it will be reused
if JDS 1001 or any other ID less than JDS 1167 gets deleted it wont be reused

Is that acceptable?
May 27 '08 #2

deepuv04
Expert 100+
P: 227
Hi,
My requirement is i want to auto generate ID'S in sqlserver that means
in database one column is there recordid for that coloumn i want to add numbers with no duplication like JDS 10001,JDS 10002,JDS 10003............like that if any record added in database means automatically add that type of id's
if suddenly we deleted that record means that id will not add again how to do dat??
Try the following code, hope will give you some idea...

[code =sql]
create table Sample_Table(pk int identity(1001,1) primary key, CustomKey as 'JDS '+ cast(pk as varchar));

insert Sample_Table default values;

insert Sample_Table default values;

insert Sample_Table default values;


select * from Sample_Table;

[/code]
May 27 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.