Advertisement
Guest User

Untitled

a guest
Jun 13th, 2016
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.63 KB | None | 0 0
  1. SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
  2. SET time_zone = "+00:00";
  3.  
  4. CREATE TABLE `item` (
  5.   `id` int(11) NOT NULL,
  6.   `content` longtext COLLATE utf8_polish_ci NOT NULL,
  7.   `title` int(11) NOT NULL
  8. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
  9.  
  10. INSERT INTO `item` (`id`, `content`, `title`) VALUES
  11. (1, 'some content', 123),
  12. (2, 'some content 2', 456);
  13.  
  14. CREATE TABLE `product` (
  15.   `item_parent_id` int(11) NOT NULL,
  16.   `subtitle` varchar(200) COLLATE utf8_polish_ci NOT NULL
  17. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
  18.  
  19. INSERT INTO `product` (`item_parent_id`, `subtitle`) VALUES
  20. (1, 'some title'),
  21. (2, 'some title 2');
  22.  
  23. CREATE TABLE `review` (
  24.   `id` int(11) NOT NULL,
  25.   `description` longtext COLLATE utf8_polish_ci NOT NULL,
  26.   `rating` int(11) NOT NULL,
  27.   `item_id` int(11) NOT NULL
  28. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
  29.  
  30. INSERT INTO `review` (`id`, `description`, `rating`, `item_id`) VALUES
  31. (1, 'dsadsaads', 2, 1),
  32. (2, 'sadsa', 4, 1),
  33. (3, 'dd', 1, 2),
  34. (4, 'asddas', 2, 2);
  35.  
  36.  
  37. ALTER TABLE `item`
  38.   ADD PRIMARY KEY (`id`);
  39.  
  40. ALTER TABLE `product`
  41.   ADD KEY `item_parent_id` (`item_parent_id`);
  42.  
  43. ALTER TABLE `review`
  44.   ADD PRIMARY KEY (`id`),
  45.   ADD KEY `item_id` (`item_id`);
  46.  
  47.  
  48. ALTER TABLE `item`
  49.   MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
  50. ALTER TABLE `review`
  51.   MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
  52.  
  53. ALTER TABLE `product`
  54.   ADD CONSTRAINT `product_ibfk_1` FOREIGN KEY (`item_parent_id`) REFERENCES `item` (`id`);
  55.  
  56. ALTER TABLE `review`
  57.   ADD CONSTRAINT `review_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `item` (`id`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement