-
Notifications
You must be signed in to change notification settings - Fork 681
/
BaselineCollectorSolution.sql
11050 lines (9947 loc) · 432 KB
/
BaselineCollectorSolution.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*********************************************************************************************
Written by Robert Virag
Comprehensive Baseline Collecting Solution
Change History
Changes in V2.0.4 - 2015.09.25
<>BugFixes
() Correcting the SetupScript to run when SQLCMD mode is enabled
() Baseline - Output File Cleanup job's step is not empty anymore when @OutputFileDirectory is NULL
() Minor fixes (correcting typos)
<>Improvements
() New option added for trying to locate the Instance Error Log Directory and configure it for @OutputFileDirectory
() Additional instuctions added to the SetupScript
V2.0.3 - 2015.09.22
<>BugFixes
() SetupScript: Edition check added before Configuring schedules for jobs
() Correction for supporting case sensitivity instances
() [dbo].[sp_CollectFileInfo]: QUOTENAME() added to dynamic statements calling databases
V2.0.2 - 2015.09.19
<>BugFixes
() SetupLog: Instancename 'MSSQLSERVER' in case of Default install
() [dbo].[sp_CollectFileInfo]: #most_recent_file_info - TSMode table was not used in TSMode
V2.0.1 - 2015.09.09
<>BugFixes
() SetupLog: missing 'GO' after sp_CollectInstanceInfo code
<>Improvements
() SetupLog: BCS Version Info, Basic Environment Info and Executer Info added
V2 - 2015.08.14
<>Features
() Central Configuration
- Schema: Table [dbo].[bcs_config]
- Collectors: @CustomConfig parameter
- Procedures: [dbo].[sp_ConfiugreBCS]
<>Improvements
() Version compatibility: 2008+
- 2005 is not supported anymore; DATETIME => DATETIME2)
() [dbo].[sp_CollectFileInfo]: Redesigned - Semi-Dynamic Collector
- Switches:
- @ChangedSizeThreshold
- @ChangedSpaceUsedThreshold /@CSUTExcludeLog/
- @CollectionTimeThreshold
- built-in: ChangedPhysicalLocation
() [dbo].[sp_CollectInstanceInfo]: collects trace flag status info
() [dbo].[sp_CollectPerfmonData]: skip 'WAITFOR DELAY @sample_interval' for the last loop
() [dbo].[sp_CollectTempDBUsage]: skip 'WAITFOR DELAY @sample_interval' for the last loop
() Help info: Dynamic type and default values (Default CustomConfig)!
() New Jobs
- Baseline - Collect InstanceInfo/ConfigData/DatabaseInfo/FileInfo/WaitStats
- based on the collected data type /static-dynamic/
- Baseline - Output File Cleanup
- with recommended schedules
() Setup logging
<>New Schedules added
() baseline - weekend - every 30 mins
() baseline - weekend - every 30 mins - BT/6AM-7PM/
() baseline - weekend - every 1 hour - BT/6AM-7PM/
() baseline - every 4 weeks - 1week - every 30 mins
() baseline - every 4 weeks - 1week - every 30 mins - BT/6AM-7PM/
() baseline - every 4 weeks - 1week - every 1 hour
() baseline - every 4 weeks - 1week - every 1 hour - BT/6AM-7PM/
() baseline - every 4 weeks - 1week - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
() baseline - every 4 weeks - 1week - every 6 hours /6AM/12PM/6PM/12AM/
() baseline - every 4 weeks - 1week - every 8 hours /6AM/2PM/10PM/
() baseline - every 4 weeks - 1week - evey 12 hours /6AM/6PM/
() baseline - every 4 weeks - weekdays - every 30 mins
() baseline - every 4 weeks - weekdays - every 30 mins - BT/6AM-7PM/
() baseline - every 4 weeks - weekdays - every 1 hour
() baseline - every 4 weeks - weekdays - every 1 hour - BT/6AM-7PM/
() baseline - every 4 weeks - weekdays - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
() baseline - every 4 weeks - weekdays - every 6 hours /6AM/12PM/6PM/12AM/
() baseline - every 4 weeks - weekdays - every 8 hours /6AM/2PM/10PM/
() baseline - every 4 weeks - weekdays - evey 12 hours /6AM/6PM/
() baseline - every 4 weeks - weekend - every 30 mins
() baseline - every 4 weeks - weekend - every 30 mins - BT/6AM-7PM/
() baseline - every 4 weeks - weekend - every 1 hour
() baseline - every 4 weeks - weekend - every 1 hour - BT/6AM-7PM/
() baseline - every 4 weeks - weekend - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
() baseline - every 4 weeks - weekend - every 6 hours /6AM/12PM/6PM/12AM/
() baseline - every 4 weeks - weekend - every 8 hours /6AM/2PM/10PM/
() baseline - every 4 weeks - weekend - evey 12 hours /6AM/6PM/
() baseline - every 12 weeks - 1week - every 30 mins
() baseline - every 12 weeks - 1week - every 30 mins - BT/6AM-7PM/
() baseline - every 12 weeks - 1week - every 1 hour
() baseline - every 12 weeks - 1week - every 1 hour - BT/6AM-7PM/
() baseline - every 12 weeks - 1week - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
() baseline - every 12 weeks - 1week - every 6 hours /6AM/12PM/6PM/12AM/
() baseline - every 12 weeks - 1week - every 8 hours /6AM/2PM/10PM/
() baseline - every 12 weeks - 1week - evey 12 hours /6AM/6PM/
() baseline - every 12 weeks - weekdays - every 30 mins
() baseline - every 12 weeks - weekdays - every 30 mins - BT/6AM-7PM/
() baseline - every 12 weeks - weekdays - every 1 hour
() baseline - every 12 weeks - weekdays - every 1 hour - BT/6AM-7PM/
() baseline - every 12 weeks - weekdays - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
() baseline - every 12 weeks - weekdays - every 6 hours /6AM/12PM/6PM/12AM/
() baseline - every 12 weeks - weekdays - every 8 hours /6AM/2PM/10PM/
() baseline - every 12 weeks - weekdays - evey 12 hours /6AM/6PM/
() baseline - every 12 weeks - weekend - every 30 mins
() baseline - every 12 weeks - weekend - every 30 mins - BT/6AM-7PM/
() baseline - every 12 weeks - weekend - every 1 hour
() baseline - every 12 weeks - weekend - every 1 hour - BT/6AM-7PM/
() baseline - every 12 weeks - weekend - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
() baseline - every 12 weeks - weekend - every 6 hours /6AM/12PM/6PM/12AM/
() baseline - every 12 weeks - weekend - every 8 hours /6AM/2PM/10PM/
() baseline - every 12 weeks - weekend - evey 12 hours /6AM/6PM/
() baseline - every 24 weeks - 1week - every 30 mins
() baseline - every 24 weeks - 1week - every 30 mins - BT/6AM-7PM/
() baseline - every 24 weeks - 1week - every 1 hour
() baseline - every 24 weeks - 1week - every 1 hour - BT/6AM-7PM/
() baseline - every 24 weeks - 1week - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
() baseline - every 24 weeks - 1week - every 6 hours /6AM/12PM/6PM/12AM/
() baseline - every 24 weeks - 1week - every 8 hours /6AM/2PM/10PM/
() baseline - every 24 weeks - 1week - evey 12 hours /6AM/6PM/
() baseline - every 24 weeks - weekdays - every 30 mins
() baseline - every 24 weeks - weekdays - every 30 mins - BT/6AM-7PM/
() baseline - every 24 weeks - weekdays - every 1 hour
() baseline - every 24 weeks - weekdays - every 1 hour - BT/6AM-7PM/
() baseline - every 24 weeks - weekdays - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
() baseline - every 24 weeks - weekdays - every 6 hours /6AM/12PM/6PM/12AM/
() baseline - every 24 weeks - weekdays - every 8 hours /6AM/2PM/10PM/
() baseline - every 24 weeks - weekdays - evey 12 hours /6AM/6PM/
() baseline - every 24 weeks - weekend - every 30 mins
() baseline - every 24 weeks - weekend - every 30 mins - BT/6AM-7PM/
() baseline - every 24 weeks - weekend - every 1 hour
() baseline - every 24 weeks - weekend - every 1 hour - BT/6AM-7PM/
() baseline - every 24 weeks - weekend - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
() baseline - every 24 weeks - weekend - every 6 hours /6AM/12PM/6PM/12AM/
() baseline - every 24 weeks - weekend - every 8 hours /6AM/2PM/10PM/
() baseline - every 24 weeks - weekend - evey 12 hours /6AM/6PM/
V1.2 - 2015.05
- Bug Fixes
V1.1 - 2015.04
- Bug Fixes
- New Collector: sp_CollectInstanceInfo
- Additional Schedules*
V1 Original Release - 2014.09.13
-----------------------------------
* - Added in V1.1
** - Added in V2
Tables:
* [dbo].[instance_info]
[dbo].[configuration_data]
[dbo].[database_info]
[dbo].[file_info]
[dbo].[iovf_stats]
[dbo].[perfmon_data]
[dbo].[tempdb_usage]
[dbo].[wait_stats]
[dbo].[ts_file_info]
[dbo].[ts_iovf_stats]
[dbo].[ts_perfmon_data]
[dbo].[ts_tempdb_usage]
[dbo].[ts_wait_stats]
[dbo].[filter_database_file]
[dbo].[filter_performance_counters]
[dbo].[filter_wait_types]
** [dbo].[bcs_config]
Collectors:
* sp_CollectInstanceInfo
sp_CollectConfigData
sp_CollectDatabaseInfo
sp_CollectFileInfo
sp_CollectIOVFStats
sp_CollectPerfmonData
sp_CollectTempDBUsage
sp_CollectWaitStats
Functions/Procedures:
** sp_ConfigureBCS
Jobs:
** Baseline - Collect InstanceInfo/ConfigData/DatabaseInfo/FileInfo/WaitStats
+ SCHEDULE[baseline - daily - every 6 hours /6AM/12PM/6PM/12AM/]
+ STEPS:
- Collect InstanceInfo
- Collect ConfigData
- Collect DatabaseInfo
- Collect FileInfo
- Collect WaitStats with @ResetWaitStats=1
- JobCheck
Baseline - CollectIOVFStats
+ SCHEDULE[baseline - every 4 weeks - 1week - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/]
Baseline - CollectPerfmonData
+ SCHEDULE[baseline - every 4 weeks - 1week - every 1 hour - BT/6AM-7PM/]
Baseline - CollectTempDBUsage
+ SCHEDULE[baseline - every 4 weeks - 1week - every 1 hour - BT/6AM-7PM/]
** Baseline - Output File Cleanup
+ SCHEDULE[baseline - daily - at 2351PM]
Schedules:
baseline - daily - at 2359PM
baseline - daily - at 2355PM
* baseline - daily - at 2351PM
* baseline - daily - every 30 mins
* baseline - daily - every 30 mins - BT/6AM-7PM/
baseline - daily - every 1 hour
baseline - daily - every 1 hour - BT/6AM-7PM/
* baseline - daily - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
baseline - daily - every 6 hours /6AM/12PM/6PM/12AM/
baseline - daily - every 8 hours /6AM/2PM/10PM/
baseline - daily - evey 12 hours /6AM/6PM/
* baseline - weekday - every 30 mins
* baseline - weekday - every 30 mins - BT/6AM-7PM/
baseline - weekday - every 1 hour
baseline - weekday - every 1 hour - BT/6AM-7PM/
* baseline - weekday - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
baseline - weekday - every 6 hours /6AM/12PM/6PM/12AM/
baseline - weekday - every 8 hours /6AM/2PM/10PM/
baseline - weekday - evey 12 hours /6AM/6PM/
** baseline - weekend - every 30 mins
** baseline - weekend - every 30 mins - BT/6AM-7PM/
baseline - weekend - every 1 hour
** baseline - weekend - every 1 hour - BT/6AM-7PM/
baseline - weekend - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
baseline - weekend - every 6 hours /6AM/12PM/6PM/12AM/
baseline - weekend - every 8 hours /6AM/2PM/10PM/
baseline - weekend - evey 12 hours /6AM/6PM/
** baseline - every 4 weeks - 1week - every 30 mins
** baseline - every 4 weeks - 1week - every 30 mins - BT/6AM-7PM/
** baseline - every 4 weeks - 1week - every 1 hour
** baseline - every 4 weeks - 1week - every 1 hour - BT/6AM-7PM/
** baseline - every 4 weeks - 1week - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
** baseline - every 4 weeks - 1week - every 6 hours /6AM/12PM/6PM/12AM/
** baseline - every 4 weeks - 1week - every 8 hours /6AM/2PM/10PM/
** baseline - every 4 weeks - 1week - evey 12 hours /6AM/6PM/
** baseline - every 4 weeks - weekdays - every 30 mins
** baseline - every 4 weeks - weekdays - every 30 mins - BT/6AM-7PM/
** baseline - every 4 weeks - weekdays - every 1 hour
** baseline - every 4 weeks - weekdays - every 1 hour - BT/6AM-7PM/
** baseline - every 4 weeks - weekdays - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
** baseline - every 4 weeks - weekdays - every 6 hours /6AM/12PM/6PM/12AM/
** baseline - every 4 weeks - weekdays - every 8 hours /6AM/2PM/10PM/
** baseline - every 4 weeks - weekdays - evey 12 hours /6AM/6PM/
** baseline - every 4 weeks - weekend - every 30 mins
** baseline - every 4 weeks - weekend - every 30 mins - BT/6AM-7PM/
** baseline - every 4 weeks - weekend - every 1 hour
** baseline - every 4 weeks - weekend - every 1 hour - BT/6AM-7PM/
** baseline - every 4 weeks - weekend - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
** baseline - every 4 weeks - weekend - every 6 hours /6AM/12PM/6PM/12AM/
** baseline - every 4 weeks - weekend - every 8 hours /6AM/2PM/10PM/
** baseline - every 4 weeks - weekend - evey 12 hours /6AM/6PM/
** baseline - every 12 weeks - 1week - every 30 mins
** baseline - every 12 weeks - 1week - every 30 mins - BT/6AM-7PM/
** baseline - every 12 weeks - 1week - every 1 hour
** baseline - every 12 weeks - 1week - every 1 hour - BT/6AM-7PM/
** baseline - every 12 weeks - 1week - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
** baseline - every 12 weeks - 1week - every 6 hours /6AM/12PM/6PM/12AM/
** baseline - every 12 weeks - 1week - every 8 hours /6AM/2PM/10PM/
** baseline - every 12 weeks - 1week - evey 12 hours /6AM/6PM/
** baseline - every 12 weeks - weekdays - every 30 mins
** baseline - every 12 weeks - weekdays - every 30 mins - BT/6AM-7PM/
** baseline - every 12 weeks - weekdays - every 1 hour
** baseline - every 12 weeks - weekdays - every 1 hour - BT/6AM-7PM/
** baseline - every 12 weeks - weekdays - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
** baseline - every 12 weeks - weekdays - every 6 hours /6AM/12PM/6PM/12AM/
** baseline - every 12 weeks - weekdays - every 8 hours /6AM/2PM/10PM/
** baseline - every 12 weeks - weekdays - evey 12 hours /6AM/6PM/
** baseline - every 12 weeks - weekend - every 30 mins
** baseline - every 12 weeks - weekend - every 30 mins - BT/6AM-7PM/
** baseline - every 12 weeks - weekend - every 1 hour
** baseline - every 12 weeks - weekend - every 1 hour - BT/6AM-7PM/
** baseline - every 12 weeks - weekend - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
** baseline - every 12 weeks - weekend - every 6 hours /6AM/12PM/6PM/12AM/
** baseline - every 12 weeks - weekend - every 8 hours /6AM/2PM/10PM/
** baseline - every 12 weeks - weekend - evey 12 hours /6AM/6PM/
** baseline - every 24 weeks - 1week - every 30 mins
** baseline - every 24 weeks - 1week - every 30 mins - BT/6AM-7PM/
** baseline - every 24 weeks - 1week - every 1 hour
** baseline - every 24 weeks - 1week - every 1 hour - BT/6AM-7PM/
** baseline - every 24 weeks - 1week - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
** baseline - every 24 weeks - 1week - every 6 hours /6AM/12PM/6PM/12AM/
** baseline - every 24 weeks - 1week - every 8 hours /6AM/2PM/10PM/
** baseline - every 24 weeks - 1week - evey 12 hours /6AM/6PM/
** baseline - every 24 weeks - weekdays - every 30 mins
** baseline - every 24 weeks - weekdays - every 30 mins - BT/6AM-7PM/
** baseline - every 24 weeks - weekdays - every 1 hour
** baseline - every 24 weeks - weekdays - every 1 hour - BT/6AM-7PM/
** baseline - every 24 weeks - weekdays - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
** baseline - every 24 weeks - weekdays - every 6 hours /6AM/12PM/6PM/12AM/
** baseline - every 24 weeks - weekdays - every 8 hours /6AM/2PM/10PM/
** baseline - every 24 weeks - weekdays - evey 12 hours /6AM/6PM/
** baseline - every 24 weeks - weekend - every 30 mins
** baseline - every 24 weeks - weekend - every 30 mins - BT/6AM-7PM/
** baseline - every 24 weeks - weekend - every 1 hour
** baseline - every 24 weeks - weekend - every 1 hour - BT/6AM-7PM/
** baseline - every 24 weeks - weekend - every 3 hours /12AM/3AM/6AM/9AM/12PM/3PM/6PM/9PM/
** baseline - every 24 weeks - weekend - every 6 hours /6AM/12PM/6PM/12AM/
** baseline - every 24 weeks - weekend - every 8 hours /6AM/2PM/10PM/
** baseline - every 24 weeks - weekend - evey 12 hours /6AM/6PM/
Tested: 2008 / 2008 R2 / 2012 / 2014
Summary:
Collect SQL Server Baseline (Raw) Data
----
For scheduling the collectors with agent jobs, Ola Hallengren's code is used
with his permission.
http://ola.hallengren.com/license.html
License:
Copyright (c) 2014 Robert Virag | SQLApprentice.net
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************************************************************************************/
/*
Please find the following lines in the script below and modify/configure them as you need:
USE [BaselineDB] ---------------------------------------------------- modify
SET @CreateJobs = 1 ---------------------------------------------------- modify
SET @CreateSchedules = 1 ----------------------------------------------- modify
SET @LocateSQLErrorLogDirectoryFromRegistry = 1 --------------------------------- modify
SET @OutputFileDirectory = NULL -- N'...\BaselineLogs\...' ------------ modify
SET @DropJobsIfExist = 1 ----------------------------------------------- modify
SET @DropScheduleIfExist = 1 ------------------------------------------- modify
SET @DropTableIfExist = 1 -------------------------------------------- modify
SET @DataCompression = 1 -------------------------------------------- modify
*/
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Implementation of Baseline Collector Solution is started... /' + CONVERT(nvarchar(24), SYSDATETIME(), 113) + '/'
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Please report every error you get (copy the SetupLog into the message): http://www.sqlapprentice.net/contact/'
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Baseline Collector Solution Version: 2.0.4'
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' MachineName: ' + CAST(SERVERPROPERTY('MachineName') AS nvarchar)
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' InstanceName: ' + CAST(ISNULL(SERVERPROPERTY('InstanceName'), N'MSSQLSERVER') AS nvarchar)
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' ServerName: ' + CAST(SERVERPROPERTY('ServerName') AS nvarchar)
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' ProductVersion: ' + CAST(SERVERPROPERTY('ProductVersion') AS nvarchar)
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Edition: ' + CAST(SERVERPROPERTY('Edition') AS nvarchar)
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Current Database: ' + QUOTENAME(DB_NAME())
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Instance Collation: ' + CAST(ISNULL(SERVERPROPERTY('Collation'), N'UNKNOWN') AS nvarchar)
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Login name: ' + SYSTEM_USER
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' User name: ' + CURRENT_USER
IF(NOT EXISTS (SELECT [name] FROM [sys].[databases] WHERE [name] = 'BaselineDB'))
BEGIN
CREATE DATABASE [BaselineDB]
END
GO
IF OBJECT_ID (N'tempdb..#TempConfiguration' ) IS NOT NULL
BEGIN
DROP TABLE #TempConfiguration
END
CREATE TABLE #TempConfiguration
(
[variable] NVARCHAR(128),
[value] NVARCHAR(max)
)
USE [BaselineDB] ---------------------------------------------------- modify
GO
/*----------------------------------------------------------------------------\
-- THERE ARE STILL SOME SETTINGS TO BE CONFIGURED! PLEASE SCROLL DOWN! --
-- _____ --
-- |*****| --
-- |*****| --
-- |*****| --
-- __|*****|__ --
-- |***********| --
-- \*********/ --
-- \*******/ --
-- \*****/ --
-- \***/ --
-- \*/ --
-- * --
-- --
-----------------------------------------------------------------------------*/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET NOCOUNT ON
GO
/*--------------------------------------------
-- Settings variables
--------------------------------------------*/
DECLARE @CreateJobs TINYINT
DECLARE @CreateSchedules TINYINT
DECLARE @OutputFileDirectory NVARCHAR(max)
DECLARE @LocateSQLErrorLogDirectoryFromRegistry BIT
DECLARE @SQLErrorLogDirectory NVARCHAR(4000)
DECLARE @SQLCommand NVARCHAR(max)
DECLARE @TableName NVARCHAR(255)
DECLARE @DataCompression BIT
DECLARE @DropTableIfExist BIT
DECLARE @DropJobsIfExist TINYINT
DECLARE @DropScheduleIfExist TINYINT
SET @DropTableIfExist = 1 -------------------------------------------- modify
SET @DataCompression = 1 -------------------------------------------- modify
SET @CreateJobs = 1 ---------------------------------------------------- modify
SET @DropJobsIfExist = 1 ----------------------------------------------- modify
/* Schedules will be DISABLED and will not be mapped to jobs!!! */
SET @CreateSchedules = 1 ----------------------------------------------- modify
SET @DropScheduleIfExist = 1 ------------------------------------------- modify
/*
Leave @OutputFileDirectoy = NULL and set @LocateSQLErrorLogDirectoryFromRegistry = 1
if you would like to try to locate the SQL Server Error Log directory from
Registry and use is as OutputFileDirectory.
The setting is ignored in SQL Server 2014 and above.
Please be noticed that xp_instance_regread will be used! You need to take care
of the necessary permissions!
*/
SET @LocateSQLErrorLogDirectoryFromRegistry = 1 ------------------------ modify
/*
Specify the output file directory. The directory MUST exists!
SQL Server 2014: If no directory is specified, then the SQL Server error log directory is used.
SQL Server 2012/2008R2/2008: If no directory is specified, there will be no output files
configured for the steps in the jobs!!!
One log file per day per job will be generated.
*/
SET @OutputFileDirectory = NULL -- N'...\BaselineLogs\...'-------------- modify
/*----------------------------------------------------------------------------\
! THERE IS NO MORE SETTINGS TO BE CONFIGURED! YOU CAN RUN THE SCRIPT! !
\----------------------------------------------------------------------------*/
-- DDDDDDDDDDDD OOOOOOOO NNNNNNN NNNNNNNEEEEEEEEEEEEEEEEEEE
-- D:::::::::::DDD O::::::::O N::::::N N:::::NE:::::::::::::::::E
-- D::::::::::::::DD OO::::::::::OO N:::::::N N:::::NE:::::::::::::::::E
-- DDD::::DDDDD:::::D O::::::OO::::::ON::::::::N N:::::NEE:::::EEEEEEEE:::E
-- D::::D D:::::D O:::::O O:::::ON:::::::::N N:::::N E::::E EEEEE
-- D::::D D:::::DO::::O O::::ON::::::::::N N:::::N E::::E
-- D::::D D:::::DO::::O O::::ON::::::N::::N N:::::N E:::::EEEEEEEE
-- D::::D D:::::DO::::O O::::ON:::::N N::::N N:::::N E::::::::::::E
-- D::::D D:::::DO::::O O::::ON:::::N N::::N::::::N E::::::::::::E
-- D::::D D:::::DO::::O O::::ON:::::N N::::::::::N E:::::EEEEEEEE
-- D::::D D:::::DO::::O O::::ON:::::N N:::::::::N E::::E
-- D::::D D:::::D O:::::O O:::::ON:::::N N::::::::N E::::E EEEEE
-- DDD::::DDDDD:::::D O::::::OO::::::ON:::::N N:::::::NEE:::::EEEEEEE::::E
-- D::::::::::::::DD OO::::::::::OO N:::::N N::::::NE:::::::::::::::::E
-- D:::::::::::DDD O::::::::O N:::::N N:::::NE:::::::::::::::::E
-- DDDDDDDDDDDD OOOOOOOO NNNNNNN NNNNNNEEEEEEEEEEEEEEEEEEE
DECLARE @Version numeric(18,10)
SET @Version = CAST(LEFT(CAST(SERVERPROPERTY('ProductVersion') AS nvarchar(max)),CHARINDEX('.',CAST(SERVERPROPERTY('ProductVersion') AS nvarchar(max))) - 1) + '.' + REPLACE(RIGHT(CAST(SERVERPROPERTY('ProductVersion') AS nvarchar(max)), LEN(CAST(SERVERPROPERTY('ProductVersion') AS nvarchar(max))) - CHARINDEX('.',CAST(SERVERPROPERTY('ProductVersion') AS nvarchar(max)))),'.','') AS numeric(18,10))
IF @LocateSQLErrorLogDirectoryFromRegistry = 1
BEGIN
IF @CreateJobs = 1 AND @OutputFileDirectory IS NULL AND @Version < 12
BEGIN
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Trying to locate the Instance Error Log Directory from registry...'
EXEC xp_instance_regread
N'HKEY_LOCAL_MACHINE',
N'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\Parameters',
N'SQLArg1',
@SQLErrorLogDirectory output
IF LEFT(@SQLErrorLogDirectory, 2) = N'-e'
BEGIN
SET @OutputFileDirectory = LEFT(RIGHT(@SQLErrorLogDirectory, LEN(@SQLErrorLogDirectory)-2),LEN(@SQLErrorLogDirectory)-2-CHARINDEX('\',REVERSE(RIGHT(@SQLErrorLogDirectory, LEN(@SQLErrorLogDirectory)-2))))
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Locating the Instance Error Log Directory...SUCCEED'
END
ELSE
BEGIN
SET @OutputFileDirectory = NULL
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Locating the Instance Error Log Directory...FAILED'
END
END
ELSE
BEGIN
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Locating the Instance Error Log Directory from registry ('+ CASE WHEN @CreateJobs = 0 THEN '1' ELSE '0' END +'|'+ CASE WHEN @Version >= 12 THEN '1' ELSE '0' END +'|'+ CASE WHEN @OutputFileDirectory IS NULL THEN '0' ELSE '1' END +')...SKIPPED'
END
END
INSERT INTO #TempConfiguration ([variable], [value]) VALUES
(N'@CreateJobs', CAST(@CreateJobs AS nvarchar))
INSERT INTO #TempConfiguration ([variable], [value]) VALUES
(N'@DropJobsIfExist', CAST(@DropJobsIfExist AS nvarchar))
INSERT INTO #TempConfiguration ([variable], [value]) VALUES
(N'@OutputFileDirectory', @OutputFileDirectory)
INSERT INTO #TempConfiguration ([variable], [value]) VALUES
(N'@CreateSchedules', CAST(@CreateSchedules AS nvarchar))
INSERT INTO #TempConfiguration ([variable], [value]) VALUES
(N'@DropScheduleIfExist', CAST(@DropScheduleIfExist AS nvarchar))
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Target Baseline Database: ' + QUOTENAME(DB_NAME())
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Configuration of the implementation script:'
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Parameter @CreateJobs: ' + CAST(@CreateJobs AS nvarchar)
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Parameter @CreateSchedules: ' + CAST(@CreateSchedules AS nvarchar)
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Parameter @LocateSQLErrorLogDirectoryFromRegistry: ' + CAST(@LocateSQLErrorLogDirectoryFromRegistry AS nvarchar)
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Parameter @OutputFileDirectory: ' + ISNULL(@OutputFileDirectory, 'NULL')
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Parameter @DropJobsIfExist: ' + CAST(@DropJobsIfExist AS nvarchar)
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Parameter @DropScheduleIfExist: ' + CAST(@DropScheduleIfExist AS nvarchar)
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Parameter @DropTableIfExist: ' + CAST(@DropTableIfExist AS nvarchar)
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Parameter @DataCompression: ' + CAST(@DataCompression AS nvarchar)
/************************************START*************************************
******************************** CREATE SCHEMA ********************************
******************************************************************************/
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' START: CREATE SCHEMA'
/*--------------------------------------------
-- Create Table for BCS Configurations
--------------------------------------------*/
IF(OBJECT_ID('[dbo].[bcs_config]') IS NOT NULL AND @DropTableIfExist = 1)
BEGIN
DROP TABLE [dbo].[bcs_config]
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Table [dbo].[bcs_config] is deleted.'
END
IF OBJECT_ID('[dbo].[bcs_config]') IS NULL
BEGIN
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Creating table [dbo].[bcs_config]...'
SET @SQLCommand = N'CREATE TABLE [dbo].[bcs_config]
(
[config_name] NVARCHAR(35) NOT NULL,
[config_type] TINYINT DEFAULT 0 NOT NULL,
[retention] SMALLINT,
[loginfo] BIT,
[dest_table] NVARCHAR(128),
[dest_schema] NVARCHAR(25),
[ts_mode] BIT,
[empty_ts_table] BIT,
[collecting_interval] SMALLINT,
[sample_interval] SMALLINT,
[measuring_interval] TINYINT,
[reset_wait_stats] BIT,
[bypass_nonactive_srv_conf_error] BIT,
[collection_time_threshold] SMALLINT,
[changed_size_threshold] INT,
[changed_space_used_threshold] INT,
[csut_exclude_log] BIT,
[config_description] NVARCHAR(max),
CONSTRAINT chk_config_type_columns CHECK(
(config_type = 1
AND dest_table IS NULL
AND dest_schema IS NULL
AND ts_mode IS NULL
AND empty_ts_table IS NULL
AND collecting_interval IS NULL
AND sample_interval IS NULL
AND measuring_interval IS NULL
AND reset_wait_stats IS NULL
AND bypass_nonactive_srv_conf_error IS NULL
AND collection_time_threshold IS NULL
AND changed_size_threshold IS NULL
AND changed_space_used_threshold IS NULL
AND csut_exclude_log IS NULL
)
OR (config_type = 2
AND dest_table IS NULL
AND dest_schema IS NULL
AND ts_mode IS NULL
AND empty_ts_table IS NULL
AND collecting_interval IS NULL
AND sample_interval IS NULL
AND measuring_interval IS NULL
AND reset_wait_stats IS NULL
AND collection_time_threshold IS NULL
AND changed_size_threshold IS NULL
AND changed_space_used_threshold IS NULL
AND csut_exclude_log IS NULL
)
OR (config_type = 3
AND collecting_interval IS NULL
AND sample_interval IS NULL
AND measuring_interval IS NULL
AND reset_wait_stats IS NULL
AND bypass_nonactive_srv_conf_error IS NULL
)
OR (config_type = 4
AND measuring_interval IS NULL
AND reset_wait_stats IS NULL
AND bypass_nonactive_srv_conf_error IS NULL
AND collection_time_threshold IS NULL
AND changed_size_threshold IS NULL
AND changed_space_used_threshold IS NULL
AND csut_exclude_log IS NULL
)
OR (config_type = 5
AND reset_wait_stats IS NULL
AND bypass_nonactive_srv_conf_error IS NULL
AND collection_time_threshold IS NULL
AND changed_size_threshold IS NULL
AND changed_space_used_threshold IS NULL
AND csut_exclude_log IS NULL
)
OR (config_type = 6
AND collecting_interval IS NULL
AND sample_interval IS NULL
AND bypass_nonactive_srv_conf_error IS NULL
AND collection_time_threshold IS NULL
AND changed_size_threshold IS NULL
AND changed_space_used_threshold IS NULL
AND csut_exclude_log IS NULL
)
OR (config_type = 0)
)
) '
IF(@@VERSION NOT LIKE N'%Microsoft SQL Server 2000%' AND @@VERSION NOT LIKE N'%Microsoft SQL Server 2005%' AND @DataCompression = 1 AND (CAST(SERVERPROPERTY(N'edition') AS NVARCHAR(100)) LIKE N'%Enterprise%' OR CAST(SERVERPROPERTY(N'edition') AS NVARCHAR(100)) LIKE N'%Developer%' OR CAST(SERVERPROPERTY(N'edition') AS NVARCHAR(100)) LIKE N'%Data Center%'))
BEGIN
SET @SQLCommand = @SQLCommand + N' WITH (DATA_COMPRESSION = PAGE)'
END
EXEC sp_executesql @SQLCommand
CREATE UNIQUE CLUSTERED INDEX [CI_bcs_config] ON [dbo].[bcs_config] ([config_name])
INSERT INTO [dbo].[bcs_config] ([config_name], [config_type], [retention], [loginfo], [config_description])
VALUES (/*[config_name]*/'sp_CollectInstanceInfo',
/*[config_type]*/1,
/*[retention]*/NULL,
/*[loginfo]*/1,
/*[config_description]*/'Default config for sp_collectinstanceinfo') --1
INSERT INTO [dbo].[bcs_config] ([config_name], [config_type], [retention], [loginfo], [config_description])
VALUES (/*[config_name]*/'sp_CollectDatabaseInfo',
/*[config_type]*/1,
/*[retention]*/NULL,
/*[loginfo]*/1,
/*[config_description]*/'Default config for sp_collectdatabaseinfo') --1
INSERT INTO [dbo].[bcs_config] ([config_name], [config_type], [retention], [loginfo], [bypass_nonactive_srv_conf_error], [config_description])
VALUES (/*[config_name]*/'sp_CollectConfigData',
/*[config_type]*/2,
/*[retention]*/NULL,
/*[loginfo]*/1,
/*[bypass_nonactive_srv_conf_error]*/0,
/*[config_description]*/'Default config for sp_collectconfigdata') --2
INSERT INTO [dbo].[bcs_config] ([config_name], [config_type], [retention], [loginfo], [dest_table], [dest_schema], [ts_mode], [empty_ts_table], [collection_time_threshold], [changed_size_threshold], [changed_space_used_threshold], [csut_exclude_log], [config_description])
VALUES (/*[config_name]*/'sp_CollectFileInfo',
/*[config_type]*/3,
/*[retention]*/null,
/*[loginfo]*/1,
/*[dest_table]*/NULL,
/*[dest_schema]*/NULL,
/*[ts_mode]*/0,
/*[empty_ts_table]*/0,
/*[collection_time_threshold]*/71,
/*[changed_size_threshold]*/10,
/*[changed_space_used_threshold]*/10,
/*[csut_exclude_log]*/1,
/*[config_description]*/'Default config for sp_collectfileinfo') --3
INSERT INTO [dbo].[bcs_config] ([config_name], [config_type], [retention], [loginfo], [dest_table], [dest_schema], [ts_mode], [empty_ts_table], [collecting_interval], [sample_interval], [config_description])
VALUES (/*[config_name]*/'sp_CollectTempDBUsage',
/*[config_type]*/4,
/*[retention]*/365,
/*[loginfo]*/1,
/*[dest_table]*/NULL,
/*[dest_schema]*/NULL,
/*[ts_mode]*/0,
/*[empty_ts_table]*/0,
/*[collecting_interval]*/null,
/*[sample_interval]*/300,
/*[config_description]*/'Default config for sp_collecttempdbusage') --4
INSERT INTO [dbo].[bcs_config] ([config_name], [config_type], [retention], [loginfo], [dest_table], [dest_schema], [ts_mode], [empty_ts_table], [collecting_interval], [sample_interval], [config_description])
VALUES (/*[config_name]*/'sp_CollectIOVFStats',
/*[config_type]*/4,
/*[retention]*/1095,
/*[loginfo]*/1,
/*[dest_table]*/NULL,
/*[dest_schema]*/NULL,
/*[ts_mode]*/0,
/*[empty_ts_table]*/0,
/*[collecting_interval]*/null,
/*[sample_interval]*/1798,
/*[config_description]*/'Default config for sp_collectiovfstats') --4
INSERT INTO [dbo].[bcs_config] ([config_name], [config_type], [retention], [loginfo], [dest_table], [dest_schema], [ts_mode], [empty_ts_table], [collecting_interval], [sample_interval], [measuring_interval], [config_description])
VALUES (/*[config_name]*/'sp_CollectPerfmonData',
/*[config_type]*/5,
/*[retention]*/365,
/*[loginfo]*/1,
/*[dest_table]*/NULL,
/*[dest_schema]*/NULL,
/*[ts_mode]*/0,
/*[empty_ts_table]*/0,
/*[collecting_interval]*/null,
/*[sample_interval]*/300,
/*[measuring_interval]*/5,
/*[config_description]*/'Default config for sp_collectperfmondata') --5
INSERT INTO [dbo].[bcs_config] ([config_name], [config_type], [retention], [loginfo], [dest_table], [dest_schema], [ts_mode], [empty_ts_table], [measuring_interval], [reset_wait_stats], [config_description])
VALUES (/*[config_name]*/'sp_CollectWaitStats',
/*[config_type]*/6,
/*[retention]*/365,
/*[loginfo]*/1,
/*[dest_table]*/NULL,
/*[dest_schema]*/NULL,
/*[ts_mode]*/0,
/*[empty_ts_table]*/0,
/*[measuring_interval]*/NULL,
/*[reset_wait_stats]*/0,
/*[config_description]*/'Default config for sp_collectwaitstats') --6
SET @SQLCommand = N'CREATE TRIGGER control_update_bcs_config ON [dbo].[bcs_config]
--INSTEAD OF UPDATE AS
FOR UPDATE AS
BEGIN
IF (UPDATE(config_name) OR UPDATE(config_type)) AND (SELECT config_name FROM DELETED) IN (''sp_CollectInstanceInfo'',''sp_CollectConfigData'',''sp_CollectDatabaseInfo'',''sp_CollectFileInfo'',''sp_CollectIOVFStats'',''sp_CollectPerfmonData'',''sp_CollectTempDBUsage'',''sp_CollectWaitStats'')
BEGIN
ROLLBACK TRAN
RAISERROR(''Cannot modify config name or type which were predefined for the collectors'', 16, -1)
END
IF (SELECT config_type FROM INSERTED) = 1
BEGIN
IF UPDATE(dest_table) OR UPDATE(dest_schema) OR UPDATE(ts_mode) OR UPDATE(empty_ts_table) OR UPDATE(collecting_interval) OR UPDATE(sample_interval) OR UPDATE(measuring_interval) OR UPDATE(reset_wait_stats) OR UPDATE(bypass_nonactive_srv_conf_error) OR UPDATE(collection_time_threshold) OR UPDATE(changed_size_threshold) OR UPDATE(changed_space_used_threshold) OR UPDATE(csut_exclude_log)
BEGIN
ROLLBACK TRAN
RAISERROR(''Cannot update column, parameter is not supported for that collector (1)'', 16, -1)
END
END
IF (SELECT config_type FROM INSERTED) = 2
BEGIN
IF UPDATE(dest_table) OR UPDATE(dest_schema) OR UPDATE(ts_mode) OR UPDATE(empty_ts_table) OR UPDATE(collecting_interval) OR UPDATE(sample_interval) OR UPDATE(measuring_interval) OR UPDATE(reset_wait_stats) OR UPDATE(collection_time_threshold) OR UPDATE(changed_size_threshold) OR UPDATE(changed_space_used_threshold) OR UPDATE(csut_exclude_log)
BEGIN
ROLLBACK TRAN
RAISERROR(''Cannot update column, parameter is not supported for that collector (2)'', 16, -1)
END
END
IF (SELECT config_type FROM INSERTED) = 3
BEGIN
IF UPDATE(collecting_interval) OR UPDATE(sample_interval) OR UPDATE(measuring_interval) OR UPDATE(reset_wait_stats) OR UPDATE(bypass_nonactive_srv_conf_error)
BEGIN
ROLLBACK TRAN
RAISERROR(''Cannot update column, parameter is not supported for that collector (3)'', 16, -1)
END
END
IF (SELECT config_type FROM INSERTED) = 4
BEGIN
IF UPDATE(measuring_interval) OR UPDATE(reset_wait_stats) OR UPDATE(bypass_nonactive_srv_conf_error) OR UPDATE(collection_time_threshold) OR UPDATE(changed_size_threshold) OR UPDATE(changed_space_used_threshold) OR UPDATE(csut_exclude_log)
BEGIN
ROLLBACK TRAN
RAISERROR(''Cannot update column, parameter is not supported for that collector (4)'', 16, -1)
END
END
IF (SELECT config_type FROM INSERTED) = 5
BEGIN
IF UPDATE(reset_wait_stats) OR UPDATE(bypass_nonactive_srv_conf_error) OR UPDATE(collection_time_threshold) OR UPDATE(changed_size_threshold) OR UPDATE(changed_space_used_threshold) OR UPDATE(csut_exclude_log)
BEGIN
ROLLBACK TRAN
RAISERROR(''Cannot update column, parameter is not supported for that collector (5)'', 16, -1)
END
END
IF (SELECT config_type FROM INSERTED) = 6
BEGIN
IF UPDATE(collecting_interval) OR UPDATE(sample_interval) OR UPDATE(bypass_nonactive_srv_conf_error) OR UPDATE(collection_time_threshold) OR UPDATE(changed_size_threshold) OR UPDATE(changed_space_used_threshold) OR UPDATE(csut_exclude_log)
BEGIN
ROLLBACK TRAN
RAISERROR(''Cannot update column, parameter is not supported for that collector (6)'', 16, -1)
END
END
END'
EXEC sp_executesql @SQLCommand
SET @SQLCommand = N'CREATE TRIGGER control_delete_bcs_config ON [dbo].[bcs_config]
--INSTEAD OF UPDATE AS
FOR DELETE AS
BEGIN
IF EXISTS (SELECT config_name FROM DELETED WHERE config_name IN (''sp_CollectInstanceInfo'',''sp_CollectConfigData'',''sp_CollectDatabaseInfo'',''sp_CollectFileInfo'',''sp_CollectIOVFStats'',''sp_CollectPerfmonData'',''sp_CollectTempDBUsage'',''sp_CollectWaitStats''))
BEGIN
ROLLBACK TRAN
RAISERROR(''Cannot delete rows which were predefined for the collectors'', 16, -1)
END
END'
EXEC sp_executesql @SQLCommand
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' ...[dbo].[bcs_config]...DONE'
END
ELSE
BEGIN
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Table [dbo].[bcs_config] is skipped...DONE'
END
/*--------------------------------------------
-- Create Table for Instance Info
--------------------------------------------*/
IF(OBJECT_ID('[dbo].[instance_info]') IS NOT NULL AND @DropTableIfExist = 1)
BEGIN
DROP TABLE [dbo].[instance_info]
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Table [dbo].[instance_info] is deleted.'
END
SET @SQLCommand = N'CREATE TABLE [dbo].[instance_info]
(
[capture_date] DATETIME2(2) NOT NULL,
[name] NVARCHAR(50) NOT NULL,
[value] SQL_VARIANT NULL,
[is_initial] BIT NOT NULL,
[is_pre] BIT NOT NULL
) '
IF(@@VERSION NOT LIKE N'%Microsoft SQL Server 2000%' AND @@VERSION NOT LIKE N'%Microsoft SQL Server 2005%' AND @DataCompression = 1 AND (CAST(SERVERPROPERTY(N'edition') AS NVARCHAR(100)) LIKE N'%Enterprise%' OR CAST(SERVERPROPERTY(N'edition') AS NVARCHAR(100)) LIKE N'%Developer%' OR CAST(SERVERPROPERTY(N'edition') AS NVARCHAR(100)) LIKE N'%Data Center%'))
BEGIN
SET @SQLCommand = @SQLCommand + N' WITH (DATA_COMPRESSION = PAGE)'
END
IF OBJECT_ID('[dbo].[instance_info]') IS NULL
BEGIN
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Creating table [dbo].[instance_info]...'
EXEC sp_executesql @SQLCommand
CREATE UNIQUE CLUSTERED INDEX [CI_instance_info] ON [dbo].[instance_info] ([capture_date],[name])
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' ...[dbo].[instance_info]...DONE'
END
ELSE
BEGIN
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Table [dbo].[instance_info] is skipped...DONE'
END
/*--------------------------------------------
-- Create Table for Server Configuration
--------------------------------------------*/
IF(OBJECT_ID('[dbo].[configuration_data]') IS NOT NULL AND @DropTableIfExist = 1)
BEGIN
DROP TABLE [dbo].[configuration_data]
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Table [dbo].[configuration_data] is deleted.'
END
SET @SQLCommand = N'CREATE TABLE [dbo].[configuration_data]
(
[capture_date] DATETIME2(2) NOT NULL,
[configuration_id] INT NOT NULL,
[value] SQL_VARIANT,
[value_in_use] SQL_VARIANT,
[is_initial] BIT NOT NULL,
[is_pre] BIT NOT NULL
) '
IF(@@VERSION NOT LIKE N'%Microsoft SQL Server 2000%' AND @@VERSION NOT LIKE N'%Microsoft SQL Server 2005%' AND @DataCompression = 1 AND (CAST(SERVERPROPERTY(N'edition') AS NVARCHAR(100)) LIKE N'%Enterprise%' OR CAST(SERVERPROPERTY(N'edition') AS NVARCHAR(100)) LIKE N'%Developer%' OR CAST(SERVERPROPERTY(N'edition') AS NVARCHAR(100)) LIKE N'%Data Center%'))
BEGIN
SET @SQLCommand = @SQLCommand + N' WITH (DATA_COMPRESSION = PAGE)'
END
IF OBJECT_ID('[dbo].[configuration_data]') IS NULL
BEGIN
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Creating table [dbo].[configuration_data]...'
EXEC sp_executesql @SQLCommand
CREATE UNIQUE CLUSTERED INDEX [CI_configuration_data] ON [dbo].[configuration_data] ([capture_date],[configuration_id])
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' ...[dbo].[configuration_data]...DONE'
END
ELSE
BEGIN
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Table [dbo].[configuration_data] is skipped...DONE'
END
/*--------------------------------------------
-- Create Table for Database Info
--------------------------------------------*/
IF(OBJECT_ID('[dbo].[database_info]') IS NOT NULL AND @DropTableIfExist = 1)
BEGIN
DROP TABLE [dbo].[database_info]
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Table [dbo].[database_info] is deleted.'
END
SET @SQLCommand = N'CREATE TABLE [dbo].[database_info]
(
[capture_date] DATETIME2(2) NOT NULL,
[database_name] SYSNAME NOT NULL,
[database_id] INT NOT NULL,
[source_database_id] INT,
[owner_sid] VARBINARY(85),
[create_date] DATETIME,
[compatibility_level] TINYINT,
[collation_name] NVARCHAR(128),
[user_access] TINYINT,
[is_read_only] BIT,
[is_auto_close_on] BIT,
[is_auto_shrink_on] BIT,
[state] TINYINT,
[is_in_standby] BIT,
[is_supplemental_logging_enabled] BIT,
[snapshot_isolation_state] TINYINT,
[is_read_committed_snapshot_on] BIT,
[recovery_model] TINYINT,
[page_verify_option] TINYINT,
[is_auto_create_stats_on] BIT,
[is_auto_update_stats_on] BIT,
[is_auto_update_stats_async_on] BIT,
[is_ansi_null_default_on] BIT,
[is_ansi_nulls_on] BIT,
[is_ansi_padding_on] BIT,
[is_ansi_warnings_on] BIT,
[is_arithabort_on] BIT,
[is_concat_null_yields_null_on] BIT,
[is_numeric_roundabort_on] BIT,
[is_quoted_identifier_on] BIT,
[is_recursive_triggers_on] BIT,
[is_cursor_close_on_commit_on] BIT,
[is_local_cursor_default] BIT,
[is_fulltext_enabled] BIT,
[is_trustworthy_on] BIT,
[is_db_chaining_on] BIT,
[is_parameterization_forced] BIT,
[is_master_key_encrypted_by_server] BIT,
[is_published] BIT,
[is_merge_published] BIT,
[is_distributor] BIT,
[is_sync_with_backup] BIT,
[service_broker_guid] UNIQUEIDENTIFIER,
[is_broker_enabled] BIT,
[is_date_correlation_on] BIT,
/*2008*/
[is_cdc_enabled] BIT,
[is_encrypted] BIT,
[is_honor_broker_priority_on] BIT,
/*2012*/
[replica_id] UNIQUEIDENTIFIER NULL,
[group_database_id] UNIQUEIDENTIFIER,
[default_language_lcid] SMALLINT,
[default_fulltext_language_lcid] INT,
[is_nested_triggers_on] BIT,
[is_transform_noise_words_on] BIT,
[two_digit_year_cutoff] SMALLINT,
[containment] TINYINT NULL,
[target_recovery_time_in_seconds] INT,
/*2014*/
[is_auto_create_stats_incremental_on] BIT,
[is_query_store_on] BIT,
[resource_pool_id] INT,
[delayed_durability] INT,
[is_memory_optimized_elevate_to_snapshot_on] BIT,
[is_initial] BIT NOT NULL,
[is_pre] BIT NOT NULL
) '
IF(@@VERSION NOT LIKE N'%Microsoft SQL Server 2000%' AND @@VERSION NOT LIKE N'%Microsoft SQL Server 2005%' AND @DataCompression = 1 AND (CAST(SERVERPROPERTY(N'edition') AS NVARCHAR(100)) LIKE N'%Enterprise%' OR CAST(SERVERPROPERTY(N'edition') AS NVARCHAR(100)) LIKE N'%Developer%' OR CAST(SERVERPROPERTY(N'edition') AS NVARCHAR(100)) LIKE N'%Data Center%'))
BEGIN
SET @SQLCommand = @SQLCommand + N' WITH (DATA_COMPRESSION = PAGE)'
END
IF OBJECT_ID('[dbo].[database_info]') IS NULL
BEGIN
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' Creating table [dbo].[database_info]...'
EXEC sp_executesql @SQLCommand
CREATE UNIQUE CLUSTERED INDEX [CI_database_info] ON [dbo].[database_info] ([capture_date], [database_name])
PRINT CONVERT(nvarchar(13), SYSDATETIME(), 114)+' ...[dbo].[database_info]...DONE'