Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 auto number

Author  Topic 

igorblackbelt
Constraint Violating Yak Guru

407 Posts

Posted - 2006-04-17 : 14:30:20
Guys -
Is there a way to automatically generate a number in a table for each new record inserted ?
I'm trying to create a automatic customer number for each new client registered on the intranet web site.

Thanks!

---

Thanks!
Igor.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-04-17 : 14:34:16
You can use the identity option on a column.

CREATE TABLE Table1 (Column1 int IDENTITY(1, 1) NOT NULL, Column2 varchar(30), ...)

Tara Kizer
aka tduggan
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-04-17 : 14:37:18
Yes
Make Identity = Yes and select a seed

Srinika
Go to Top of Page

igorblackbelt
Constraint Violating Yak Guru

407 Posts

Posted - 2006-04-19 : 11:30:02
Never used Identity before, I'll give it a try... Since they want this client number to follow a certain patern, is it possible to add like 3 letters in front of it, plus some digits at the end, that will be generated thru some business logic, mixed with current date ?

---

Thanks!
Igor.
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-04-19 : 11:42:38
Unfortunately Identity is Integer.

as far as I know
Either u have to have a UDF to create the sequential - varchar that u want
or u have to have a composite column with one haveing character data and identity col having Integer data
May be there is another workaround

Srinika
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-20 : 02:00:35
quote:
Originally posted by igorblackbelt

Never used Identity before, I'll give it a try... Since they want this client number to follow a certain patern, is it possible to add like 3 letters in front of it, plus some digits at the end, that will be generated thru some business logic, mixed with current date ?

---

Thanks!
Igor.


Refer this
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=57069

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

igorblackbelt
Constraint Violating Yak Guru

407 Posts

Posted - 2006-04-21 : 14:11:21
great, I think this is what I need, it's easier than I thought. thanks man!

---

Thanks!
Igor.
Go to Top of Page
   

- Advertisement -