Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. -- task 1:
  2. -- Create a table in SQL Server with 10 000 000 log entries (date + text).
  3. -- Search in the table by date range. Check the speed (without caching).
  4.  
  5. create database PerformanceHomewordDb
  6. go
  7.  
  8. use PerformanceHomewordDb
  9.  
  10. create table Concerts(
  11. Id int Identity Primary Key,
  12. Performer nvarchar(100),
  13. [Date] date
  14. )
  15. go
  16.  
  17. -- Insert 10000 different values
  18. SET NOCOUNT ON
  19. DECLARE @ConcertCount int = (SELECT COUNT(*) FROM Concerts)
  20. DECLARE @RowCount int = 10000
  21. WHILE @RowCount > 0
  22. BEGIN
  23. DECLARE @Performer nvarchar(100) =
  24. 'Name ' + CONVERT(nvarchar(100), @RowCount) + ': ' +
  25. CONVERT(nvarchar(100), newid())
  26. DECLARE @Date datetime =
  27. DATEADD(month, CONVERT(varbinary, newid()) % (50 * 12), getdate())
  28. INSERT INTO Concerts(Performer, [Date])
  29. VALUES(@Performer, @Date)
  30. SET @RowCount = @RowCount - 1
  31. END
  32. SET NOCOUNT OFF
  33.  
  34. -- Copy values until the total count is 1 000 000
  35. WHILE (SELECT COUNT(*) FROM Concerts) < 1000000
  36. BEGIN
  37. INSERT INTO Concerts(Performer, [Date])
  38. SELECT Performer, [Date] FROM Concerts
  39. END
  40.  
  41. select count(*) from Concerts
  42.  
  43. CHECKPOINT; DBCC DROPCLEANBUFFERS;
  44.  
  45. -- time taken - 6 sec
  46. select * from Concerts
  47. where [date] > '10-10-2010' AND [date] < '10-10-2012'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement