code_junkie

How do you manage “pick lists” in a database

Nov 10th, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. PickListContent
  2.  
  3. IdList IdPick Text
  4. 1 1 Apples
  5. 1 2 Oranges
  6. 1 3 Pears
  7. 2 1 Dogs
  8. 2 2 Cats
  9.  
  10. PickList
  11.  
  12. Id Description
  13. 1 Fruit
  14. 2 Pets
  15.  
  16. CREATE TABLE PickList(
  17. ListName varchar(15),
  18. Value varchar(15),
  19. Display varchar(15),
  20. Primary Key (ListName, Display)
  21. )
  22.  
  23. # Put in the name of the list
  24. insert into lists (id, name) values (1, "Country in North America");
  25.  
  26. # Put in the values of the list
  27. insert into list_options (id, list_id, value_text) values
  28. (1, 1, "Canada"),
  29. (2, 1, "United States of America"),
  30. (3, 1, "Mexico");
  31.  
  32. id - identity or UUID field (I actually call the field xxx_id where xxx is the name of the table).
  33. name - display name of the item
  34. display_order - small int of order to display. Default this value to something greater than 1
  35.  
  36. select optionDesc from Options where 'MyList' = optionList
  37.  
  38. select optionDesc from Options where 'MyList' = optionList
  39.  
  40. select optionDesc from Options where 'MyList' = optionList
  41.  
  42. SQL> desc aux_values;
  43. Name Type
  44. ----------------------------------------- ------------
  45. VARIABLE_ID VARCHAR2(20)
  46. VALUE_SEQ NUMBER
  47. DESCRIPTION VARCHAR2(80)
  48. INTEGER_VALUE NUMBER
  49. CHAR_VALUE VARCHAR2(40)
  50. FLOAT_VALUE FLOAT(126)
  51. ACTIVE_FLAG VARCHAR2(1)
Add Comment
Please, Sign In to add comment