Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to have a partial autonumber primary key

Status
Not open for further replies.

mojoT

Technical User
Sep 23, 2003
25
NZ
I'm working on a project where one of the tables' primary key has 10 characters. The first five are the same letters for every record, but the last five need to be an auto-number. Does anyone know how to do this????

I talked to an oracle user, who said i can concatenate two fields, or use a hidden autonumber, or have a partial autonumber primary key.

If anyone has any suggestions, or know any URLs, or anything, PLEASE HELP ME.
 
You can set Column1 to be INTEGER IDENTITY(1,1); that takes care of the autonumber part. Then set Column2 to be a calculated value of whatever the five characters are plus CAST(Column1 AS varchar) and set Column2 as PRIMARY KEY. Something like this:

CREATE TABLE TheTable (
Column1 INT
IDENTITY(1,1) NOT NULL
, Column2 AS 'XXXXX' + CAST(Column1 AS varchar)
PRIMARY KEY
)



--Angel [rainbow]
-----------------------------------
Every time I lose my mind, I wonder
if it's really worth finding.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top