1. /* This is here because I've been doing the following to check for errors:
  2. mysql -u root -p < file.sql */
  3. drop database `shop`;
  4. create schema if not exists `shop` default character set utf8;
  5. /* Use it. */
  6. use `shop`;
  7. /* Product-category table. */
  8. create table if not exists `category`
  9. (
  10. `key` int not null auto_increment,
  11. `name` varchar (80) not null,
  12. `num_products` int null, /* number of products in stock under this category. */
  13. primary key (`key`)
  14. );
  15. /* Product sub-category table. */
  16. create table if not exists `sub_category`
  17. (
  18. `key` int not null auto_increment,
  19. `name` varchar (80) not null,
  20. `num_products` int, /* number of products in stock under this sub-category. */
  21. `category_key` int, /* The category this sub-category belongs to. */
  22. primary key (`key`),
  23. foreign key (`category_key`) references category (`key`)
  24. );
  25. /* Manufacturer table. */
  26. create table if not exists `manufacturer`
  27. (
  28. `key` int not null auto_increment,
  29. `name` varchar(40) not null,
  30. `products` int, /* Products the shop buys from this manufacturer. */
  31. primary key (`key`)
  32. );
  33. /* Intermediate table, because I'd like to know the sub-categories that apply
  34. to each manufacturer. */
  35. create table if not exists `sub_categories_per_manufacturer`
  36. (
  37. `key` int not null auto_increment,
  38. `sub_category_key` int,
  39. `manufacturer_key` int,
  40. /* Number of products in stock from a given manufacturer/sub-category pair. */
  41. `num_products` int,
  42. primary key (`key`),
  43. foreign key (`sub_category_key`) references sub_category (`key`),
  44. foreign key (`manufacturer_key`) references manufacturer (`key`)
  45. );
  46. /* memory-series table. */
  47. create table if not exists `memory_series`
  48. (
  49. `key` int not null auto_increment,
  50. `name` varchar(40) not null,
  51. `count` int, /* Number of products in stock. */
  52. primary key (`key`)
  53. );
  54. /* memory-technology table. */
  55. create table if not exists `memory_technology`
  56. (
  57. `key` int not null auto_increment,
  58. `name` varchar(40) not null,
  59. `count` int, /* Number of products in stock. */
  60. primary key (`key`)
  61. );
  62. /* memory-size table. */
  63. create table if not exists `memory_size`
  64. (
  65. `key` int not null auto_increment,
  66. `name` varchar(40) not null,
  67. `count` int, /* Number of products in stock. */
  68. primary key (`key`)
  69. );
  70. /* memory-organization table. */
  71. create table if not exists `memory_organization`
  72. (
  73. `key` int not null auto_increment,
  74. `name` varchar(40) not null,
  75. `count` int, /* Number of products in stock. */
  76. primary key (`key`)
  77. );
  78. /* memory-interface table. */
  79. create table if not exists `memory_interface`
  80. (
  81. `key` int not null auto_increment,
  82. `name` varchar(40) not null,
  83. `count` int, /* Number of products in stock. */
  84. primary key (`key`)
  85. );
  86. /* memory-frequency table. */
  87. create table if not exists `memory_frequency`
  88. (
  89. `key` int not null auto_increment,
  90. `name` varchar(40) not null,
  91. `count` int, /* Number of products in stock. */
  92. primary key (`key`)
  93. );
  94. /* memory-write-cycle-time table. */
  95. create table if not exists `memory_write_cycle_time`
  96. (
  97. `key` int not null auto_increment,
  98. `name` varchar(40) not null,
  99. `count` int, /* Number of products in stock. */
  100. primary key (`key`)
  101. );
  102. /* memory-access-time table. */
  103. create table if not exists `memory_access_time`
  104. (
  105. `key` int not null auto_increment,
  106. `name` varchar(40) not null,
  107. `count` int, /* Number of products in stock. */
  108. primary key (`key`)
  109. );
  110. /* memory-voltage-supply table. */
  111. create table if not exists `memory_voltage_supply`
  112. (
  113. `key` int not null auto_increment,
  114. `name` varchar(40) not null,
  115. `count` int, /* Number of products in stock. */
  116. primary key (`key`)
  117. );
  118. /* memory-operating-temperature table. */
  119. create table if not exists `memory_operating_temperature`
  120. (
  121. `key` int not null auto_increment,
  122. `name` varchar(40) not null,
  123. `count` int, /* Number of products in stock. */
  124. primary key (`key`)
  125. );
  126. /* memory-mounting-type table. */
  127. create table if not exists `memory_mounting_type`
  128. (
  129. `key` int not null auto_increment,
  130. `name` varchar(40) not null,
  131. `count` int, /* Number of products in stock. */
  132. primary key (`key`)
  133. );
  134. /* memory-package table.
  135. Not sure if this should be done as foreign keys into an `ic-package' table. */
  136. create table if not exists `memory_package`
  137. (
  138. `key` int not null auto_increment,
  139. `name` varchar(80) not null,
  140. `count` int, /* Number of products in stock. */
  141. primary key (`key`)
  142. );
  143. /* memory-eeprom table. */
  144. create table if not exists `memory_eeprom`
  145. (
  146. `key` int not null auto_increment,
  147. /*
  148. * Part info.
  149. */
  150. /* Arbritrary string assigned by us, giving such product's
  151. part-number. */
  152. `part_number` varchar(40) not null,
  153. /* Arbitrary integer assigned by the manufacturer, describing such product's
  154. number. */
  155. `manufacturer_part_number` varchar(40) not null,
  156. /* An excerpt of product's name, part-number, and most notable features. */
  157. `description` varchar(40) not null,
  158. /* Long version of the above. */
  159. `detailed_description` varchar(80) not null,
  160. /*
  161. * Media options
  162. */
  163. /* Product's image. */
  164. `picture` mediumblob,
  165. /* Product's datasheet. */
  166. `data_sheet` mediumblob,
  167. /* Some CAD model. */
  168. `eda_model` mediumblob,
  169. /*
  170. * Environmental options
  171. */
  172. /* Whether this product is ROHS compilant. */
  173. `rohs_compilant_p` boolean,
  174. /* Classified moisture-sensivity level. */
  175. `moisture_sensitivity_level` char,
  176. /* I don't know what these stand for. */
  177. `reach_status` varchar(40),
  178. `eccn` varchar(40),
  179. `htsus` varchar(40),
  180. /* Manufacturer or supplier's lead time for this product, in weeks. */
  181. `lead_time` int,
  182. /* Bulk packaging, in units */
  183. `standard_packaging` int,
  184. /*
  185. * Stocking stuff
  186. */
  187. `stock_type` enum ('in-stock', 'normally-stocking', 'new-product'),
  188. `quantity_available` int unsigned,
  189. /* Unitary price */
  190. `price` decimal (10, 6),
  191. /* Foreign key into the `manufacturer's table. */
  192. `manufacturer` int,
  193. /* Foreign key into the `memory-series' table. */
  194. `series` int,
  195. /* Product status. */
  196. `product_status` enum ('active', 'not-for-new-designs', 'obsolete', \
  197. 'discontinued-by-us'),
  198. /* Foreign key into the `memory-technology' table. */
  199. `technology` int,
  200. /* Foregin key into the `memory-size' table. */
  201. `memory_size` int,
  202. /* Foreign key into the `memory-organization' table. */
  203. `memory_organization` int,
  204. /* Foregin key into the `memory-interface' table. */
  205. `memory_interface` int,
  206. /* Foreign key into the `memory-frequency' table. */
  207. `clock_frequency` int,
  208. /* Foreign key into the `memory-write-cycle-time' table. */
  209. `write_cycle_time` int,
  210. /* Foreign key into the `memory-access-time' table. */
  211. `access_time` int,
  212. /* Foreign key into the `memory-voltage-supply'. */
  213. `voltage_supply` int,
  214. /* Foreign key into the `memory-operating-temperature' table. */
  215. `operating_temperature` int,
  216. /* Foreign key into the `memory-mounting-type' table. */
  217. `mounting_type` int,
  218. /* Foreign key into the `ic-package' table. */
  219. `package` int,
  220. /* Key definitions. */
  221. primary key (`key`),
  222. foreign key (`manufacturer`) references manufacturer (`key`),
  223. foreign key (`series`) references memory_series (`key`),
  224. foreign key (`technology`) references memory_technology (`key`),
  225. foreign key (`memory_size`) references memory_size (`key`),
  226. foreign key (`memory_organization`) references memory_organization (`key`),
  227. foreign key (`memory_interface`) references memory_interface (`key`),
  228. foreign key (`clock_frequency`) references memory_frequency (`key`),
  229. foreign key (`write_cycle_time`) references memory_write_cycle_time (`key`),
  230. foreign key (`access_time`) references memory_access_time (`key`),
  231. foreign key (`voltage_supply`) references memory_voltage_supply (`key`),
  232. foreign key (`operating_temperature`) references memory_operating_temperature (`key`),
  233. foreign key (`mounting_type`) references memory_mounting_type (`key`),
  234. foreign key (`package`) references memory_package (`key`)
  235. );