Advertisement
vlastomar

Untitled

Oct 14th, 2020
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. CREATE TABLE `users`(
  2. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  3. `username` VARCHAR(30) NOT NULL UNIQUE,
  4. `password` VARCHAR(30) NOT NULL,
  5. `email` VARCHAR(50) NOT NULL
  6. );
  7.  
  8. CREATE TABLE `categories`(
  9. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  10. `category` VARCHAR(30) NOT NULL
  11. );
  12.  
  13. CREATE TABLE `articles`(
  14. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  15. `title` VARCHAR(50) NOT NULL,
  16. `content` TEXT NOT NULL,
  17. `category_id` INT,
  18. CONSTRAINT `fk_articles_categories`
  19. FOREIGN KEY (`category_id`)
  20. REFERENCES `categories`(`id`)
  21. );
  22.  
  23. CREATE TABLE `users_articles`(
  24. `user_id` INT,
  25. `article_id` INT,
  26. PRIMARY KEY (`user_id`,`article_id`),
  27. CONSTRAINT `fk_users_articles_users`
  28. FOREIGN KEY (`user_id`)
  29. REFERENCES `users`(`id`),
  30. CONSTRAINT `fk_users_articles_articles`
  31. FOREIGN KEY (`article_id`)
  32. REFERENCES `articles`(`id`)
  33. );
  34.  
  35. CREATE TABLE `comments`(
  36. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  37. `comment` VARCHAR(255) NOT NULL,
  38. `article_id` INT NOT NULL,
  39. `user_id` INT NOT NULL,
  40. CONSTRAINT `fk_comments_articles`
  41. FOREIGN KEY (`article_id`)
  42. REFERENCES `articles`(`id`),
  43. CONSTRAINT `fk_comments_users`
  44. FOREIGN KEY (`user_id`)
  45. REFERENCES `users`(`id`)
  46. );
  47.  
  48. CREATE TABLE `likes`(
  49. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  50. `article_id` INT,
  51. `comment_id` INT,
  52. `user_id` INT NOT NULL,
  53. CONSTRAINT `fk_likes_articles`
  54. FOREIGN KEY (`article_id`)
  55. REFERENCES `articles`(`id`),
  56. CONSTRAINT `fk_likes_comments`
  57. FOREIGN KEY (`comment_id`)
  58. REFERENCES `comments`(`id`),
  59. CONSTRAINT `fk_likes_users`
  60. FOREIGN KEY (`user_id`)
  61. REFERENCES `users`(`id`)
  62. );
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement