473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

auto generate ID'S in sqlserver

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
2 3782
Delerna
1,134 Expert 1GB
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
227 Expert 100+
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

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

Similar topics

8
by: Steven Burn | last post by:
I'm curious, I've written a very simple PIS (personal info store) that allows one to store whatever they wish..... the problem is, when one deletes an entry, the auto-numbering isn't corrected to...
0
by: Nick | last post by:
Is it possible to have multiple auto increments in one column? Say I have two tables... 1. table 'messageboards' with fields ('id' , 'name') 2. table 'messagethreads' with fields ('id' ,...
10
by: Mamuninfo | last post by:
Hello, Have any function in the DB2 database that can generate unique id for each string like oracle, mysql,sybase,sqlserver database. In mysql:- select md5(concat_ws("Row name")) from...
8
by: John Smith | last post by:
Hello all: Is there a way to determine the auto increment id from a newly inserted record in the database? Thanks, John
3
by: James Alba | last post by:
Hey all, I am accessing an ms access database using .NET and C#. Like so, /* Create the database connection. */ connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data...
5
by: David Lozzi | last post by:
Hello, I'd like to create the SQL script for any given table, view or proc in my database, through ASP.Net using VB. I'm building a module library and providing this code on the fly would ease...
6
by: | last post by:
Hi, can someone provide some advise on how to get around with using auto generated proxies? basically I already have the proxy classes, and they are used by other places. I'd like use these...
2
by: x0054 | last post by:
Ok, this is a stupid problem, I admit. I have a scrip that adds records to a table. The records are for photos. So, after adding a record the scrip also uploads a picture from users computer and...
13
by: S.Dickson | last post by:
I had an access database that i use as an ordering system. I have a form for entering customer details. When i add a new customer on the form the customer number is an auto number that appears when...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.