Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi to all ......

i have a table registr master in this i have some columns ...
auto_id
name
block
name_who_registered



i want to create a primary key in the pattern like...

name.block.auti_id

for ex...

if a person has name raju, block barakhamba, and auto_id 1
then pK is raju.barakhamba.01

if name sanju, block khurja, and auti_id 2
then pK is sanju.khurja.02



here auto_id has set auti increment




and after this how can i access this record which i entered immediately...

becoz i think @@identity is use for auti increment column...

pls help guys/...

Thanks in advance...
Posted
Comments
Sudhakar Shinde 26-Apr-13 3:39am    
Your question is not clear.Why do you need to have primary key like this? Anyway you have auto_id which can be primary key for your table. Still you want to have primary key with three values mentioned by you then you can define one column of type text (VARCHAR in oracle) and concatenate while inserting into the table.
GDdixit 26-Apr-13 4:48am    
ok ...i can make auto id as primary key..but my problem is that i want to make a column of type as told u above in my question and it must be unique...


for ex...
raju.232.01

last value increment automatically and first two take from column , r u understnding my problem , pls suggest something.......
Sudhakar Shinde 26-Apr-13 5:12am    
Uniqueness will be taken care by auto_id as names can not be unique. So there can be two Raju in barakhamba block and in this case this auto_id will make them unique. Then why not keep auto_id as PK? It is not good practice to have key on name and that is the reason I asked you the purpose behine having key composed of name, block and auto id. You can define a text field and define it as PK. You need to concat the values before you insert it in the table. To have auto increment value oracle provides sequence while mysql you can define the column as AUTO_INCREMENT.
GDdixit 27-Apr-13 1:15am    
ya ..thanks ...your suggestion is good....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900