Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 4.58 KB | None | 0 0
  1. drop table Band_Arist;
  2. drop table Events;
  3. drop table Ratings;
  4. drop table Songs;
  5. drop table Albums;
  6. drop table Artist;
  7. drop table Country;
  8. drop table Users;
  9. drop table Genres;
  10. drop table Band;
  11.  
  12. create table Band(
  13. id int NOT NULL AUTO_INCREMENT,
  14. band_name varchar(24),
  15. PRIMARY KEY (id)
  16. );
  17.  
  18. create table Genres(
  19. id int NOT NULL AUTO_INCREMENT,
  20. genre_name varchar(24),
  21. PRIMARY KEY (id)
  22. );
  23.  
  24. create table Users(
  25. id int NOT NULL AUTO_INCREMENT,
  26. user_name varchar(24),
  27. password varchar(24),
  28. first_name varchar(24),
  29. last_name varchar(24),
  30. email varchar(24),
  31. isAdmin boolean,
  32. isActive boolean,
  33. PRIMARY KEY (id)
  34. );
  35.  
  36. create table Country(
  37. id int NOT NULL AUTO_INCREMENT,
  38. country_name varchar(24),
  39. PRIMARY KEY (id)
  40. );
  41.  
  42. create table Artist(
  43. id int NOT NULL AUTO_INCREMENT,
  44. artist_name varchar(24),
  45. artist_surname varchar(24),
  46. artist_pseudo varchar(24),
  47. country_id int,
  48. PRIMARY KEY (id),
  49. FOREIGN KEY (country_id) REFERENCES Country(id) ON DELETE CASCADE
  50. );
  51.  
  52. create table Albums(
  53. id int NOT NULL AUTO_INCREMENT,
  54. artist_id int,
  55. album_name varchar(24),
  56. album_cover_url varchar(24),
  57. sold_quantity int,
  58. PRIMARY KEY (id),
  59. FOREIGN KEY (artist_id) REFERENCES Artist(id) ON DELETE CASCADE
  60. );
  61.  
  62. create table Songs
  63. (
  64. id int NOT NULL AUTO_INCREMENT,
  65. song_name varchar(24),
  66. song_time int,
  67. album_id int,
  68. genre_id int,
  69. PRIMARY KEY (id),
  70. FOREIGN KEY (album_id) REFERENCES Albums(id) ON DELETE CASCADE,
  71. FOREIGN KEY (genre_id) REFERENCES Genres(id) ON DELETE CASCADE
  72. );
  73.  
  74. create table Ratings(
  75. id int NOT NULL AUTO_INCREMENT,
  76. song_id int,
  77. rate int,
  78. user_id int,
  79. PRIMARY KEY (id),
  80. FOREIGN KEY (song_id) REFERENCES Songs(id) ON DELETE CASCADE,
  81. FOREIGN KEY (user_id) REFERENCES Users(id) ON DELETE CASCADE
  82. );
  83.  
  84.  
  85. create table Events(
  86. id int NOT NULL AUTO_INCREMENT,
  87. event_name varchar(24),
  88. event_date date,
  89. band_id int,
  90. country_id int,
  91. price int,
  92. PRIMARY KEY (id),
  93. FOREIGN KEY (band_id) REFERENCES band(id) ON DELETE CASCADE,
  94. FOREIGN KEY (country_id) REFERENCES country(id) ON DELETE CASCADE
  95. );
  96.  
  97. create table Band_Arist(
  98. id int NOT NULL AUTO_INCREMENT,
  99. artist_id int,
  100. band_id int,
  101. PRIMARY KEY (id),
  102. FOREIGN KEY (artist_id) REFERENCES Artist(id) ON DELETE CASCADE,
  103. FOREIGN KEY (band_id) REFERENCES band(id) ON DELETE CASCADE
  104. );
  105.  
  106. insert into band values (null, 'band1');
  107. insert into band values (null, 'band2');
  108. insert into band values (null, 'band3');
  109.  
  110. insert into genres values (null, 'genre1');
  111. insert into genres values (null, 'genre2');
  112. insert into genres values (null, 'genre3');
  113.  
  114. insert into users values (null, 'username1', 'password1', 'fname1', 'sname1', 'email1', true,true);
  115. insert into users values (null, 'username2', 'password2', 'fname2', 'sname2', 'email2', true,true);
  116. insert into users values (null, 'username3', 'password3', 'fname3', 'sname3', 'email3', 1,1);
  117.  
  118. insert into country values (null, 'country1');
  119. insert into country values (null, 'country2');
  120. insert into country values (null, 'country3');
  121.  
  122. insert into artist values (null, 'name1', 'surname1', 'pseudo1', 1);
  123. insert into artist values (null, 'name2', 'surname2', 'pseudo2', 2);
  124. insert into artist values (null, 'name3', 'surname3', 'pseudo3', 3);
  125.  
  126. insert into albums values (null, 1, 'albumname1', 'url1', 10);
  127. insert into albums values (null, 2, 'albumname2', 'url2', 20);
  128. insert into albums values (null, 3, 'albumname3', 'url3', 30);
  129.  
  130. insert into songs values (null, 'song1', 1, 1, 1);
  131. insert into songs values (null, 'song2', 1, 1, 1);
  132. insert into songs values (null, 'song3', 1, 1, 1);
  133. insert into songs values (null, 'song4', 1, 2, 2);
  134. insert into songs values (null, 'song5', 1, 2, 2);
  135. insert into songs values (null, 'song6', 1, 2, 2);
  136. insert into songs values (null, 'song7', 1, 3, 3);
  137. insert into songs values (null, 'song8', 1, 3, 3);
  138. insert into songs values (null, 'song9', 1, 3, 3);
  139.  
  140. insert into ratings values (null, 1, 1, 1);
  141. insert into ratings values (null, 1, 2, 2);
  142. insert into ratings values (null, 2, 3, 3);
  143. insert into ratings values (null, 2, 4, 1);
  144. insert into ratings values (null, 3, 5, 2);
  145. insert into ratings values (null, 3, 6, 3);
  146. insert into ratings values (null, 4, 7, 1);
  147. insert into ratings values (null, 4, 8, 2);
  148. insert into ratings values (null, 5, 9, 3);
  149. insert into ratings values (null, 5, 1, 1);
  150. insert into ratings values (null, 6, 2, 2);
  151. insert into ratings values (null, 6, 3, 3);
  152. insert into ratings values (null, 7, 4, 1);
  153. insert into ratings values (null, 7, 5, 2);
  154. insert into ratings values (null, 8, 6, 3);
  155. insert into ratings values (null, 8, 7, 1);
  156. insert into ratings values (null, 9, 8, 2);
  157. insert into ratings values (null, 9, 9, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement