Advertisement
Guest User

csc176

a guest
Sep 25th, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.96 KB | None | 0 0
  1. use csc176;
  2.  
  3. create table articles
  4. (
  5.     article_id int not null auto_increment,
  6.     user_id int not null,
  7.     title varchar(30) not null,
  8.     body text not null,
  9.     primary key (article_id)
  10. );
  11.  
  12. create table comments
  13. (
  14.     comment_id int not null auto_increment,
  15.     user_id int not null,
  16.     article_id int not null,
  17.     body text not null,
  18.     parent_id int,
  19.     primary key (comment_id)
  20. );
  21.  
  22. create table users
  23. (
  24.     user_id int not null auto_increment,
  25.     name varchar(30) not null,
  26.     primary key (user_id)
  27. );
  28.  
  29. alter table articles
  30. add constraint fk_articles_user
  31. foreign key (user_id)
  32. references users (user_id)
  33. on delete cascade;
  34.  
  35. alter table comments
  36. add constraint fk_comments_users
  37. foreign key (user_id)
  38. references users (user_id)
  39. on delete cascade,
  40.  
  41. add constraint fk_comments_articles
  42. foreign key (article_id)
  43. references articles (article_id)
  44. on delete cascade,
  45.  
  46. add constraint fk_comments_comments
  47. foreign key (parent_id)
  48. references comments (comment_id)
  49. on delete cascade;
  50.  
  51. insert into users (name) values ('Billyjim Cricketwhisker');
  52. insert into users (name) values ('Lou Beasley');
  53. insert into users (name) values ('Aloysius Montegomery');
  54.  
  55. insert into articles (user_id, title, body) values (1, 'dolor sit amet', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed id congue tellus. Pellentesque mollis erat quis dapibus maximus. Integer interdum, leo eu pulvinar accumsan, lorem mi feugiat justo, nec pharetra ante ante at sapien. Fusce varius a eros vitae venenatis. Ut ultricies laoreet volutpat.');
  56. insert into articles (user_id, title, body) values (2, 'phasellus aliquam nisl', 'Quisque quis lorem pretium, hendrerit ligula non, blandit dolor. Pellentesque tincidunt sapien ex, id laoreet velit placerat vel. Suspendisse potenti. Phasellus aliquam nisl quis pharetra feugiat.');
  57. insert into articles (user_id, title, body) values (3, 'ut turpis ex', 'Nunc ut turpis ex. In varius, tortor et euismod scelerisque, augue quam laoreet diam, quis finibus ante urna non ligula. Morbi id sagittis nisi, eu dictum ipsum. ');
  58.  
  59. insert into comments (user_id, article_id, body, parent_id) values (2, 1, 'That is extremely interesting!', NULL);
  60. insert into comments (user_id, article_id, body, parent_id) values (3, 1, 'I disagree!', 1);
  61.  
  62. insert into comments (user_id, article_id, body, parent_id) values (1, 2, 'And you call my article uninteresting!', NULL);
  63. insert into comments (user_id, article_id, body, parent_id) values (2, 2, 'Y u mad tho?', 3);
  64. insert into comments (user_id, article_id, body, parent_id) values (3, 2, 'Ya\'ll need to calm down', 4);
  65.  
  66. insert into comments (user_id, article_id, body, parent_id) values (1, 3, 'Where do you find this stuff??', NULL);
  67.  
  68. update users set name='Billytim Cricketwillow' where user_id=1;
  69. update articles set title='Best Article Ever' where article_id=1;
  70. update comments set body='u wot?' where comment_id=6;
  71.  
  72. delete from users where user_id=3;
  73. delete from articles where article_id=3;
  74. delete from comments where comment_id=5;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement