If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > automatically generate value of the property ID in database

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-06-09, 02:18
chiefman chiefman is offline
Registered User
 
Join Date: Jan 2009
Posts: 23
automatically generate value of the property ID in database

I am trying to create a table which have "id" as its primary key. the property "id" is a string with fixed length and consists of characters and numbers, e.g. ABC45125. very easy to automatically generate its value in database if it is an integer but I have no idea when it is a string. any idea about it? I will appreciate.
Reply With Quote
  #2 (permalink)  
Old 02-06-09, 02:52
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
so you can't use the inbuilt autonumber column.....

I suppose it depends on what the alpha component refers to, how that is made up.

it also depends on whether the numbers have to be contiguous.. nothing upsets an accountant more that seeing a list of numbers which are non contiguous.

its actually fairly simple to do, once you have sorted out your true requirements.

I've used a composite alphanumeric on numerous occasions (often the alpha component adds more information tot he numeric (eg where an acconting system needed to identify the period as part of the invoice number). they wanted a quick and simple method of identifying what year and month a transaction was raised and they wanted there invoice numbers masked so that their customers and competition couldn't easily identify how much trade they were doing.


so over to you...
what does the ABC but represent, how does that change?
do you need contiguous numbers?
what causes the number to change in what sequence?

bear in mind that to most computers the letter A is 65, a is 97
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 02-06-09, 04:45
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
this is the Database Concepts & Design forum

the concept you've described is pretty clear, but i'm afraid that if you want a working solution, you will have to tell us which database system you're using -- then we can move this thread to the appropriate forum and get to work...
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 02-12-09, 20:33
chiefman chiefman is offline
Registered User
 
Join Date: Jan 2009
Posts: 23
I use mysql
Reply With Quote
  #5 (permalink)  
Old 02-12-09, 22:09
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
thread moved to mysql

if you want automatically assigned numbers, you must use an INTEGER AUTO_INCREMENT column

you can "fake" the alphabetic/numeric codes with concatenation whenever you need to retrieve the code from the table

SELECT CONCAT('ABC',RIGHT(CONCAT('0000',id),5) AS my_id ...
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On