Advertisement
Guest User

Untitled

a guest
May 6th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.36 KB | None | 0 0
  1. --/*------------------------------------------------------------
  2. --* Script SQLSERVER
  3. --------------------------------------------------------------*/
  4.  
  5.  
  6. --/*------------------------------------------------------------
  7. ---- Table: TypeOfBook
  8. --------------------------------------------------------------*/
  9. --CREATE TABLE TypeOfBook(
  10. -- id INT IDENTITY (1,1) NOT NULL ,
  11. -- categoryBook VARCHAR (50) NOT NULL ,
  12. -- CONSTRAINT TypeOfBook_PK PRIMARY KEY (id)
  13. --);
  14.  
  15.  
  16. --/*------------------------------------------------------------
  17. ---- Table: customer
  18. --------------------------------------------------------------*/
  19. --CREATE TABLE customer(
  20. -- id INT IDENTITY (1,1) NOT NULL ,
  21. -- lastName VARCHAR (50) NOT NULL ,
  22. -- firstname VARCHAR (50) NOT NULL ,
  23. -- dateOfBirth DATETIME NOT NULL ,
  24. -- mail VARCHAR (100) NOT NULL ,
  25. -- id_TypeOfBook INT NOT NULL ,
  26. -- CONSTRAINT customer_PK PRIMARY KEY (id)
  27.  
  28. -- ,CONSTRAINT customer_TypeOfBook_FK FOREIGN KEY (id_TypeOfBook) REFERENCES TypeOfBook(id)
  29. --);
  30.  
  31.  
  32. --/*------------------------------------------------------------
  33. ---- Table: author
  34. --------------------------------------------------------------*/
  35. --CREATE TABLE author(
  36. -- id INT IDENTITY (1,1) NOT NULL ,
  37. -- lastName VARCHAR (50) NOT NULL ,
  38. -- firstName VARCHAR (50) NOT NULL ,
  39. -- CONSTRAINT author_PK PRIMARY KEY (id)
  40. --);
  41.  
  42.  
  43. --/*------------------------------------------------------------
  44. ---- Table: book
  45. --------------------------------------------------------------*/
  46. --CREATE TABLE book(
  47. -- id INT IDENTITY (1,1) NOT NULL ,
  48. -- title VARCHAR (100) NOT NULL ,
  49. -- id_TypeOfBook INT NOT NULL ,
  50. -- id_author INT NOT NULL ,
  51. -- CONSTRAINT book_PK PRIMARY KEY (id)
  52.  
  53. -- ,CONSTRAINT book_TypeOfBook_FK FOREIGN KEY (id_TypeOfBook) REFERENCES TypeOfBook(id)
  54. -- ,CONSTRAINT book_author0_FK FOREIGN KEY (id_author) REFERENCES author(id)
  55. --);
  56.  
  57.  
  58. --/*------------------------------------------------------------
  59. ---- Table: register
  60. --------------------------------------------------------------*/
  61. --CREATE TABLE register(
  62. -- id INT IDENTITY (1,1) NOT NULL ,
  63. -- borrowingDate DATETIME NOT NULL ,
  64. -- returnDate DATETIME NOT NULL ,
  65. -- id_book INT NOT NULL ,
  66. -- id_customer INT NOT NULL ,
  67. -- CONSTRAINT register_PK PRIMARY KEY (id)
  68.  
  69. -- ,CONSTRAINT register_book_FK FOREIGN KEY (id_book) REFERENCES book(id)
  70. -- ,CONSTRAINT register_customer0_FK FOREIGN KEY (id_customer) REFERENCES customer(id)
  71. --);
  72.  
  73. --INSERT INTO [dbo].[TypeOfBook]([categoryBook])
  74. --VALUES
  75. -- ('Horreur'),
  76. -- ('science-fiction'),
  77. -- ('roman'),
  78. -- ('jeunesse')
  79. --GO
  80.  
  81. --INSERT INTO [dbo].[author] ([lastName], [firstName])
  82. --VALUES
  83. -- ('Jules', 'Verne'),
  84. -- ('J.K', 'Rowling'),
  85. -- ('Howard', 'Phillips'),
  86. -- ('Albert', 'Camus'),
  87. -- ('J.R.R', 'Tolkien'),
  88. -- ('Agatha', 'Chritie'),
  89. -- ('Guillaume', 'Musso'),
  90. -- ('Molière', 'Lebon'),
  91. -- ('Jean-Claude', 'Van Damme'),
  92. -- ('Arthur', 'Dimbaud'),
  93. -- ('Antoine', 'de Saint-Exupéry'),
  94. -- ('Stephen', 'King')
  95. --GO
  96.  
  97. --INSERT INTO [dbo].[book] ([title], [id_TypeOfBook], [id_author])
  98. --VALUES
  99. -- ('Harry Potter à lécole des Sorciers', '2', '2'),
  100. -- ('Harry Potter et la chambre des secrets', '2', '2'),
  101. -- ('Harry Potter et le Prisonnier dAzkaban', '2', '2'),
  102. -- ('Harry Potter et la Coupe de Feu', '2', '2'),
  103. -- ('Harry Potter et la Coupe de Feu', '2', '2'),
  104. -- ('Harry Potter et le Prince de sang-mêlé', '2', '2'),
  105. -- ('Harry Potter et les Reliques de la Mort', '2', '2'),
  106. -- ('Harry Potter et les Reliques de la Mort tome 2', '2', '2'),
  107. -- ('Harry Potter lenfant maudit', '2', '2'),
  108. -- ('LÎle mystérieuse', '3', '1'),
  109. -- ('Un drame au Mexique', '3', '1'),
  110. -- ('Voyage au centre de la Terre', '3', '1'),
  111. -- ('Vingt mille lieues sous les mers', '3', '1'),
  112. -- ('Aventures de trois Russes et de trois Anglais dans lAfrique australe', '3', '1'),
  113. -- ('Le Tour du monde en quatre-vingts jours', '3', '1'),
  114. -- ('Frritt-Flacc', '3', '1'),
  115. -- ('Le Secret de Wilhelm Storitz', '3', '1'),
  116. -- ('LAppel de Cthulhu', '1', '3'),
  117. -- ('La Cité sans nom', '1', '3'),
  118. -- ('La Peur qui rôde', '1', '3'),
  119. -- ('Le Monstre sur le seuil', '1', '3'),
  120. -- ('Celui qui hantait les ténèbres', '1', '3'),
  121. -- ('Dans labîme du temps', '1', '3'),
  122. -- ('La Couleur tombée du ciel','1','3'),
  123. -- ('La Maison de la sorcière', '1', '3'),
  124. -- ('Letranger', '3', '4'),
  125. -- ('Le Premier Homme', '3', '4'),
  126. -- ('Le Mythe de Sisyphe', '3', '4'),
  127. -- ('La Chute', '3', '4'),
  128. -- ('LÉté ', '3', '4'),
  129. -- ('Lettres à un ami allemand', '3', '4'),
  130. -- ('La Peste', '3', '4'),
  131. -- ('Noces', '3', '4'),
  132. -- ('Le Seigneur des anneaux tome 1', '2', '5'),
  133. -- ('Le Seigneur des anneaux tome 2', '2', '5'),
  134. -- ('Le Seigneur des anneaux tome 3', '2', '5'),
  135. -- ('Le Hobbit', '2', '5'),
  136. -- (' Le Silmarillion', '2', '5'),
  137. -- ('Du conte de fées', '2', '5'),
  138. -- ('Roverandom', '2', '5'),
  139. -- ('La Chute dArthur', '2', '5'),
  140. -- ('LHomme au complet marron', '3', '6'),
  141. -- ('Les Quatre', '3', '6'),
  142. -- ('Le Train bleu', '3', '6'),
  143. -- ('Le Secret de Chimneys', '3', '6'),
  144. -- ('Le Couteau sur la nuque', '3', '6'),
  145. -- ('La Mort dans les nuages', '3', '6'),
  146. -- ('Cartes sur table', '3', '6'),
  147. -- ('Dix petits nègres', '3', '6'),
  148. -- ('La vie secrète des écrivains', '4', '7'),
  149. -- ('La Fille de Brooklyn', '4', '7'),
  150. -- ('La Jeune Fille et la nuit', '4', '7'),
  151. -- ('Demain', '4', '7'),
  152. -- ('La Fille de papier', '4', '7'),
  153. -- ('Parce que je taime', '4', '7'),
  154. -- ('Skidamarink', '4', '7'),
  155. -- ('Blanche fesse et les 7 nains', '4', '7'),
  156. -- ('Le Dépit amoureux', '3', '8'),
  157. -- ('Les Fâcheux', '3', '8'),
  158. -- ('Le Mariage forcé', '3', '8'),
  159. -- ('Le Tartuffe ou lHypocrite', '3', '8'),
  160. -- ('Le Misanthrope', '3', '8'),
  161. -- ('Amphitryon', '3', '8'),
  162. -- ('Psyché', '3', '8'),
  163. -- ('Les Fourberies de Scapin', '3', '8'),
  164. -- ('Bannières de mai', '3', '10'),
  165. -- ('Comédie de la soif', '3', '10'),
  166. -- ('Larme', '3', '10'),
  167. -- ('Mémoire', '3', '10'),
  168. -- ('Honte', '3', '10'),
  169. -- ('Jeune ménage', '3', '10'),
  170. -- ('Le loup criait', '3', '10'),
  171. -- ('Angoisse', '3', '10'),
  172. -- ('Le petit prince', '4', '11')
  173. --GO
  174.  
  175. --INSERT INTO [dbo].[customer] ([lastName], [firstname], [dateOfBirth],[mail],[id_TypeOfBook])
  176. --VALUES
  177. -- ('GARCIA', 'Babacar', '19971013 00:00:00', 'garcia.babacar@gmail.com', 1),
  178. -- ('MARTY', 'Balthazar', '19941203 00:00:00', 'Balthazar@gmail.com', 1),
  179. -- ('FAURE', 'Bazile', '20081111 00:00:00', 'Bazile@gmail.com', 3),
  180. -- ('MARTIN', 'Baudoin', '20111111 00:00:00', 'Baudoin@gmail.com', 3),
  181. -- ('VIDAL', 'Bob', '19800730 00:00:00', 'Bob@gmail.com', 4),
  182. -- ('PUJOL', 'Boubaker', '19980401 00:00:00', 'Boubaker@gmail.com', 3),
  183. -- ('MARTINEZ', 'Brandon', '20121221 00:00:00', 'Brandon@gmail.com', 2),
  184. -- ('LOPEZ', 'Zahr-Eddine', '20000101 00:00:00', 'Zahr-Eddine@gmail.com', 1),
  185. -- ('PEREZ', 'Zaid', '19450314 00:00:00', 'Zaid@gmail.com', 3),
  186. -- ('PONS', 'Zakarya', '20010110 00:00:00', 'Zakarya@gmail.com', 4),
  187. -- ('DURAND', 'Nabile', '19751212 00:00:00', 'Nabile@gmail.com', 1),
  188. -- ('ROQUES', 'Kassandra', '19950915 00:00:00', 'Kassandra@gmail.com', 4),
  189. -- ('FABRE', 'Katharina', '19740314 00:00:00', 'Katharina@gmail.com', 3),
  190. -- ('SANCHEZ', 'Galeane', '20081012 00:00:00', 'Galeane@gmail.com', 1),
  191. -- ('BONNET', 'Clémentine', '19800730 00:00:00', 'Clémentine@gmail.com', 2),
  192. -- ('DUPUY', 'Corentine', '19800730 00:00:00', 'Corentine@gmail.com', 1),
  193. -- ('RIVIERE', 'Cyrine', '19800730 00:00:00', 'Cyrine@gmail.com', 4),
  194. -- ('FERNANDEZ', 'Colette', '20060712 00:00:00', 'Colette@gmail.com', 3),
  195. -- ('BLANC', 'Quentin', '19910605 00:00:00', 'Quentin@gmail.com', 1),
  196. -- ('RODRIGUEZ', 'Quiesie-Vanessa', '19990506 00:00:00', 'Quiesie-Vanessa@gmail.com', 4),
  197. -- ('GONZALEZ', 'Quincy', '19751212 00:00:00', 'Quincy@gmail.com', 3),
  198. -- ('REY', 'Elif', '20081012 00:00:00', 'Elif@gmail.com', 2),
  199. -- ('BOUSQUET', 'Eleana', '20121221 00:00:00', 'Eleana@gmail.com', 2),
  200. -- ('DEJEAN', 'Edouardine', '19860817 00:00:00', 'Edouardine@gmail.com',3 ),
  201. -- ('LOPEZ', 'JORDAN', '20040401 00:00:00', 'darkKiller@hotmail.fr', 4)
  202. --GO
  203.  
  204. --INSERT INTO [dbo].[register] ([borrowingDate], [returnDate], [id_book], [id_customer])
  205. --VALUES
  206. -- ('20190101 00:00:00',NULL, 1, 2),
  207. -- ('20190202 00:00:00',NULL, 9, 3),
  208. -- ('20190303 00:00:00',NULL, 1, 4),
  209. -- ('20190404 00:00:00',NULL, 2, 5),
  210. -- ('20190505 00:00:00',NULL, 3, 6),
  211. -- ('20190606 00:00:00',NULL, 25, 7),
  212. -- ('20190707 00:00:00',NULL, 30, 8),
  213. -- ('20190808 00:00:00',NULL, 6, 9),
  214. -- ('20190909 00:00:00',NULL, 8, 10),
  215. -- ('20191010 00:00:00',NULL, 14, 11),
  216. -- ('20191111 00:00:00',NULL, 40, 12),
  217. -- ('20191212 00:00:00',NULL, 10, 13),
  218. -- ('20191113 00:00:00',NULL, 50, 14),
  219. -- ('20191014 00:00:00',NULL, 69, 15),
  220. -- ('20190915 00:00:00','20190501 00:00:00', 55, 16),
  221. -- ('20190816 00:00:00','20190502 00:00:00', 33, 17),
  222. -- ('20190717 00:00:00','20190503 00:00:00', 25, 18),
  223. -- ('20190618 00:00:00','20190504 00:00:00', 37, 19),
  224. -- ('20190519 00:00:00','20190505 00:00:00', 48, 20),
  225. -- ('20180420 00:00:00','20190506 00:00:00', 58, 21),
  226. -- ('20180321 00:00:00','20190507 00:00:00', 60, 22),
  227. -- ('20180222 00:00:00','20190508 00:00:00', 67, 23),
  228. -- ('20180124 00:00:00','20190509 00:00:00', 66, 24),
  229. -- ('20180223 00:00:00','20190510 00:00:00', 28, 25),
  230. -- ('20180325 00:00:00','20190511 00:00:00', 30, 26),
  231. -- ('20180426 00:00:00','20190512 00:00:00', 21, 20),
  232. -- ('20180527 00:00:00','20190513 00:00:00', 12, 17),
  233. -- ('20180628 00:00:00','20190514 00:00:00', 11, 5),
  234. -- ('20170728 00:00:00','20190515 00:00:00', 10, 6),
  235. -- ('20170829 00:00:00','20190516 00:00:00', 18, 19),
  236. -- ('20170901 00:00:00','20190517 00:00:00', 19, 9),
  237. -- ('20171002 00:00:00','20190518 00:00:00', 20, 25),
  238. -- ('20171103 00:00:00','20190519 00:00:00', 44, 2),
  239. -- ('20171204 00:00:00','20190520 00:00:00', 43, 2),
  240. -- ('20171105 00:00:00','20190521 00:00:00', 48, 3),
  241. -- ('20171006 00:00:00','20190522 00:00:00', 46, 6),
  242. -- ('20180907 00:00:00','20190523 00:00:00', 69, 8),
  243. -- ('20180808 00:00:00','20190524 00:00:00', 26, 11),
  244. -- ('20180709 00:00:00','20190516 00:00:00', 67, 21),
  245. -- ('20180601 00:00:00','20190526 00:00:00', 28, 14)
  246. --GO
  247.  
  248. --SELECT
  249. -- [dbo].[register].[borrowingDate],
  250. -- [dbo].[register].[returnDate],
  251. -- [dbo].[customer].[lastName],
  252. -- [dbo].[customer].[firstname],
  253. -- [dbo].[book].[title]
  254. --FROM
  255. -- [dbo].[register]
  256. --INNER JOIN
  257. -- [dbo].[book]
  258. -- ON [dbo].[register].[id_book] = [dbo].[book].[id]
  259. --INNER JOIN
  260. -- [dbo].[customer]
  261. -- ON [dbo].[register].[id_customer] = [dbo].[customer].[id]
  262. --GO
  263.  
  264. --SELECT
  265. -- [dbo].[book].[title],
  266. -- [dbo].[TypeOfBook].[categoryBook],
  267. -- [dbo].[author].[lastName],
  268. -- [dbo].[author].[firstName],
  269. -- CASE
  270. -- WHEN
  271. -- [dbo].[register].[returnDate] < GETDATE()
  272. -- OR [dbo].[register].[id] IS NULL
  273. -- THEN
  274. -- 'oui'
  275. -- ELSE
  276. -- 'non'
  277. -- END AS [dispo]
  278. --FROM
  279. -- [dbo].[book]
  280. --INNER JOIN
  281. -- [dbo].[TypeOfBook]
  282. -- ON [dbo].[book].[id_TypeOfBook] = [dbo].[TypeOfBook].[id]
  283. --INNER JOIN
  284. -- [dbo].[author]
  285. -- ON [dbo].[book].[id_author] = [dbo].[author].[id]
  286. --LEFT JOIN
  287. -- [dbo].[register]
  288. -- ON [dbo].[register].[id_book] = [dbo].[book].[id]
  289. --ORDER BY [dispo] ASC
  290. --GO
  291.  
  292. --SELECT
  293. -- [dbo].[TypeOfBook].[categoryBook],
  294. -- COUNT([dbo].[TypeOfBook].[id]) AS [Nbr de livre]
  295. --FROM
  296. -- [dbo].[TypeOfBook]
  297. --INNER JOIN
  298. -- [dbo].[book]
  299. -- ON [dbo].[TypeOfBook].[id] = [dbo].[book].[id_TypeOfBook]
  300. --GROUP BY
  301. -- [dbo].[TypeOfBook].[categoryBook]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement