Creating a combinational Primary Mysql

39 Views Asked by At

I am trying to create a very custom primary key, example in a [table_1] having columns tble_id, date_entered, time_entered, card_number, name, address. I would like to have the primary key (tble_id) to be a combination of the columns: date_entered, time_entered, card_number. So for example primary key being: 2014082717010001, in this case 20140827 being the date, 1701 being the time and 00001 being the card number.

1

There are 1 best solutions below

2
On

why don't you make this id a string , separated by commas such as 20140827,1701,0001 therefore when you fetch each id , you can get each of the needed information by using $x=explode(',' , table_id) where you'll get $x[0]=date , $x[1]=time_entered and $x[1]=card_number but all of string type