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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make primary key alphanumeric !

Status
Not open for further replies.

gokeeffe

Programmer
Jan 11, 2005
170
IE
Hi

Want I want to do is create a table with a primary key that
will increment numbers with a letter code before it.

For example FG01
FG02
FG03

Is it possible to do this with mysql, I undertand that the primary key value is usually a integer so it might not be possible to do this.But I have seen it done on other sites so it must be possible.

Could anyone help.

Tks
Graham
 
You can have any type of code as your primary key, it doesn't have to be an integer. Then when you're inserting a record, you would specify a value for the primary key field along with the rest of the fields. However, if you want to use an auto-incremented field (as the primary key or anything else), then that field must be an integer.

Beir bua.
 
the primary key can certainly be of that style but you will have to increment it yourself

if you want to use an auto_increment, you can achieve a similar result by appending the auto_increment value to a constant every time you want to display the key, but this is not recommended, and you should not need to display your key in the first place


rudy | r937.com | Ask the Expert | Premium SQL Articles
SQL for Database-Driven Web Sites (next course starts March 6 2005)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top