Posted By

alexwilliams on 01/01/07


Tagged

mysql database habtm


Versions (?)

HABTM relationship MySQL tables for use in Rails


 / Published in: SQL
 

  1. DROP TABLE IF EXISTS `products_tags`;
  2. DROP TABLE IF EXISTS `tags`;
  3. DROP TABLE IF EXISTS `products`;
  4.  
  5. CREATE TABLE `products` (
  6. `id` int(11) NOT NULL AUTO_INCREMENT,
  7. `title` varchar(100) NOT NULL,
  8. `price` decimal(10,2) NOT NULL,
  9. PRIMARY KEY (`id`)
  10. )
  11.  
  12. CREATE TABLE `tags` (
  13. `id` int(11) NOT NULL AUTO_INCREMENT,
  14. `title` varchar(64) NOT NULL,
  15. PRIMARY KEY (`id`)
  16. )
  17.  
  18. CREATE TABLE `products_tags` (
  19. `product_id` int(11) NOT NULL DEFAULT '0',
  20. `tag_id` int(11) NOT NULL DEFAULT '0',
  21. PRIMARY KEY (`product_id`,`tag_id`)
  22. )

Report this snippet  

You need to login to post a comment.