Question:
Should I use IDs or Text in Database table columns? See details.?
andreydy
2009-12-03 12:58:51 UTC
Let say I have two tables
ORDER: (order_id, order_type, order_item, order_count)
and
TYPE: (type_id, type_title)
If all my order are stored in ORDER table, what is the best way to handle ORDER/TYPE relationship?

That is: Am I better off storing TYPE_ID value in ORDER_TYPE column, or TYPE_TITLE value in that same column?

If I store TYPE_ID then I have to use JOINs in queries to get TYPE_TITLE value. So, what are the best practices?

Thanks
Three answers:
MichaelInScarborough
2009-12-03 13:38:31 UTC
So I understand that you wonder, whether or not it is standard procedure to use a lookup table (in your case table "Type")..



In case the string field would be i.e. Character literals like I, B, A, etc then it would not make to much sense to dedicate a separate table to capture these one character literals. However, in case these one letter literals had the potential to be replaced by string literals for future reference, it might make sense as well to have a distinct lookup table to store these items.



In case you would store in your type_title string literals like "UPS Ground Service", "UPS overnight", etc then you start saving space by replacing the text in the order table through numbers, which then could be decoded using your table "Type".



And yes, you have to join the tables (create queries) in order to create a i.e. human readable report, etc.
Mike Gambino II
2009-12-03 13:16:15 UTC
actually no. when someone orders your item or puts your item in the cart, it should record everything. that is why you have a table called order. it tells you the order number and all this other stuff. Type is the table of telling the table ORDER what item is what. without type, order will not grab information needed to give information on the item you are selling.



basically, you have books you want to sell online. you type in the table in TYPE as ID=1 and title=book. you put the item online and when someone orders, it will show the order ID, show the ID type of the item grabbed from the table TYPE, order_item should be set as yes or no or however you have it, and order_count should be how many books they want to order.
budzyna
2017-01-10 01:15:36 UTC
yet you're definitely no longer even telling it to show the innovations, you're telling it to show the $result which you have establish because of actuality the variable for the mysql question id. for particular as you are the only one applying it which will consistently be a million. Or 0 if the question fails. you ought to iterate in the technique the information with the objective to show it. so which you like : jointly as($checklist = mysql_fetch_array($result)){ echo $checklist[filedname1], $checklist[fieldname2], ......


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...