Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.71 KB | None | 0 0
  1. INSERT INTO Tables(Name) VALUES ('Artisti'), ('Impresar'), ('Lansare')
  2. GO
  3.  
  4. --~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--
  5.  
  6. CREATE VIEW Artisti_Views AS
  7. SELECT Artisti.ImpresarID,Artisti.Nume
  8. FROM Artisti
  9. GO
  10.  
  11. CREATE VIEW Impresar_Views AS
  12. SELECT I.Nume
  13. FROM Impresar I
  14. INNER JOIN Artisti A ON I.ImpresarID = A.ImpresarID
  15. GO
  16.  
  17. CREATE VIEW Lansare_Views AS
  18. SELECT M.Nume, Count(*) as 'Numar melodii lansate'
  19. FROM Melodii M
  20. INNER JOIN Lansare L ON L.MelodieID = M.MelodieID
  21. INNER JOIN Artisti A ON A.ArtistID = L.ArtistID
  22. GROUP BY M.Nume
  23. GO
  24.  
  25. INSERT INTO Views VALUES ('Artisti_Views'), ('Impresar_Views'), ('Lansare_Views')
  26.  
  27. --~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--
  28.  
  29. INSERT INTO Tests(Name) VALUES
  30. ('Insert_x'), --1
  31. ('Delete_x'), --2
  32. ('Evaluate') --3
  33. GO
  34.  
  35. --~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--
  36.  
  37. INSERT INTO TestTables VALUES
  38. (1,1,10000,1), (2,1,10000,2), (3,1,10000,3),
  39. (1,2,10000,1), (2,2,10000,2), (3,2,10000,3)
  40. GO
  41.  
  42. --~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--
  43.  
  44. INSERT INTO TestViews VALUES (1,1), (2,2), (3,3)
  45. GO
  46.  
  47. --~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--
  48.  
  49. CREATE PROCEDURE Insert_Artisti (@rows int) AS
  50.  
  51. BEGIN
  52.  
  53. DECLARE @ID int
  54. DECLARE @name VARCHAR(50)
  55. DECLARE @index int
  56. DECLARE @lastID int
  57. SET @name = 'UNTITLED_NAME'
  58. SET @ID = 10000
  59. SET @index = 1
  60.  
  61. WHILE @index <= @rows
  62. BEGIN
  63. SET @ID = 10000 + @index
  64.  
  65. SELECT TOP 1 @lastID = Artisti.ImpresarID
  66. FROM dbo.Artisti
  67. ORDER BY Artisti.ImpresarID DESC
  68.  
  69. IF @lastID > 10000
  70. SET @ID = @lastID + 1
  71.  
  72. INSERT INTO Artisti VALUES (@ID, @name, null)
  73.  
  74. SET @index = @index + 1
  75. END
  76. END
  77. GO
  78.  
  79. --~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--
  80.  
  81. CREATE PROCEDURE Delete_Artisti (@rows int) AS
  82.  
  83. BEGIN
  84.  
  85. DECLARE @ID int
  86. DECLARE @index int
  87. DECLARE @lastID int
  88. SET @ID = 10000
  89. SET @index = @rows
  90.  
  91. WHILE @index > 0
  92. BEGIN
  93. SET @ID = 10000 + @index
  94.  
  95. SELECT TOP 1 @lastID = Artisti.ArtistID
  96. FROM dbo.Artisti
  97. ORDER BY Artisti.ArtistID DESC
  98.  
  99. IF @lastID > @ID
  100. SET @ID = @lastID
  101.  
  102. DELETE FROM Artisti WHERE Artisti.ArtistID = @ID
  103.  
  104. SET @index = @index - 1
  105. END
  106. END
  107. GO
  108.  
  109. --~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--
  110.  
  111. CREATE PROCEDURE Insert_Impresar (@rows int) AS
  112.  
  113. BEGIN
  114. DECLARE @ID int
  115. DECLARE @name VARCHAR(50)
  116. DECLARE @index int
  117. DECLARE @lastID int
  118. SET @name = 'GHOST_NAME'
  119. SET @ID = 10000
  120. SET @index = 1
  121.  
  122. WHILE @index <= @rows
  123. BEGIN
  124. SET @ID = 10000 + @index
  125.  
  126. SELECT TOP 1 @lastID = Impresar.ImpresarID
  127. FROM dbo.Impresar
  128. ORDER BY Impresar.ImpresarID DESC
  129.  
  130. IF @lastID > 10000
  131. SET @ID = @lastID + 1
  132.  
  133. INSERT INTO Impresar VALUES (@ID, @name)
  134.  
  135. SET @index = @index + 1
  136. END
  137. END
  138. GO
  139.  
  140. --~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--
  141.  
  142. CREATE PROCEDURE Delete_Impresar (@rows int) AS
  143.  
  144. BEGIN
  145.  
  146. DECLARE @ID int
  147. DECLARE @index int
  148. DECLARE @lastID int
  149. SET @ID = 10000
  150. SET @index = @rows
  151.  
  152. WHILE @index > 0
  153. BEGIN
  154. SET @ID = 10000 + @index
  155.  
  156. SELECT TOP 1 @lastID = Impresar.ImpresarID
  157. FROM dbo.Impresar
  158. ORDER BY Impresar.ImpresarID DESC
  159.  
  160. IF @lastID > @ID
  161. SET @ID = @lastID
  162.  
  163. DELETE FROM Impresar WHERE Impresar.ImpresarID = @ID
  164.  
  165. SET @index = @index - 1
  166. END
  167. END
  168. GO
  169.  
  170. --~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--
  171.  
  172. CREATE PROCEDURE Insert_Lansare (@rows int) AS
  173.  
  174. BEGIN
  175.  
  176. DECLARE @ArtistID int
  177. DECLARE @Nume varchar(50)
  178. DECLARE @index int
  179. SET @index = @rows
  180.  
  181. EXEC Insert_Artisti @rows
  182.  
  183. DECLARE arCursor CURSOR SCROLL FOR
  184.  
  185. SELECT ArtistID,Nume
  186. FROM Artisti
  187.  
  188. OPEN arCursor
  189. FETCH LAST FROM arCursor
  190. INTO @ArtistID, @Nume
  191.  
  192. WHILE @index > 0 AND @@FETCH_STATUS = 0
  193. BEGIN
  194. INSERT INTO Lansare VALUES (@ArtistID,1,'2006-06-06')
  195.  
  196. FETCH PRIOR FROM arCursor
  197. INTO @ArtistID, @Nume
  198.  
  199. SET @index = @index - 1
  200. END
  201.  
  202. CLOSE arCursor DEALLOCATE arCursor
  203. END
  204. GO
  205.  
  206. --~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--
  207.  
  208. CREATE PROCEDURE Delete_Lansare(@rows int) AS
  209.  
  210. BEGIN
  211.  
  212. DECLARE @index int
  213. DECLARE @ArtistID int
  214. SET @index = @rows
  215.  
  216. WHILE @index > 0
  217. BEGIN
  218. SELECT TOP 1 @ArtistID = ArtistID
  219. FROM dbo.Artisti
  220. ORDER BY ArtistID DESC
  221.  
  222. IF @ArtistID > 10000
  223. BEGIN
  224. DELETE FROM Lansare
  225. WHERE Lansare.MelodieID = 1 AND
  226. Lansare.ArtistID = @ArtistID
  227.  
  228. EXEC Delete_Artisti 1
  229. END
  230.  
  231. SET @index = @index - 1
  232. END
  233. END
  234. GO
  235.  
  236. --~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--
  237.  
  238. CREATE PROCEDURE Insert_x (@table VARCHAR(50), @x int) AS
  239. BEGIN
  240.  
  241. DECLARE @insert VARCHAR(20)
  242. SET @insert = 'Insert_' + @table
  243. EXEC @insert @x
  244.  
  245. END
  246. GO
  247.  
  248. CREATE PROCEDURE Delete_x (@table VARCHAR(50), @x int) AS
  249. BEGIN
  250.  
  251. DECLARE @delete VARCHAR(20)
  252. SET @delete = 'Delete_' + @table
  253. EXEC @delete @x
  254.  
  255. END
  256. GO
  257.  
  258. CREATE PROCEDURE Evaluate (@View VARCHAR(50)) AS
  259. BEGIN
  260. IF @View = 'Artisti'
  261. SELECT * FROM Artisti_Views
  262.  
  263. IF @View = 'Impresar'
  264. SELECT * FROM Impresar_Views
  265.  
  266. IF @View = 'Lansare'
  267. SELECT * FROM Lansare_Views
  268. END
  269. GO
  270.  
  271. --~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--
  272.  
  273. CREATE PROCEDURE MainProgram (@table VARCHAR(20), @rows int) AS
  274. BEGIN
  275. DECLARE @startTime datetime
  276. DECLARE @endTime datetime
  277. DECLARE @evalTime datetime
  278. DECLARE @info NVARCHAR(2000)
  279. DECLARE @testInsert VARCHAR(20)
  280. DECLARE @testDelete VARCHAR(20)
  281. DECLARE @testID int
  282. DECLARE @index int
  283.  
  284. SET @startTime = GETDATE()
  285.  
  286. EXEC Insert_x @table, @rows
  287. EXEC Delete_x @table, @rows
  288.  
  289. SET @endTime = GETDATE()
  290.  
  291. EXEC Evaluate @table
  292.  
  293. SET @evalTime = GETDATE()
  294.  
  295.  
  296. SET @info = 'The tests were executed on table ' + @table + ' for ' + CONVERT(VARCHAR(5),@rows) + ' entries of data.'
  297.  
  298. INSERT INTO TestRuns VALUES (@info, @startTime, @evalTime)
  299.  
  300. SELECT TOP 1 @testID = T.TestRunID
  301. FROM dbo.TestRuns T
  302. ORDER BY T.TestRunID DESC
  303.  
  304. SELECT TOP 1 @index = Tables.TableID
  305. FROM dbo.Tables
  306. WHERE Tables.Name = @table
  307.  
  308. INSERT INTO TestRunTables VALUES (@testID, @index, @startTime, @endTime)
  309. INSERT INTO TestRunViews VALUES (@testID, @index, @endTime, @evalTime)
  310. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement