├── Brent Allen - Overcoming Power Resistance with Cube Formulas ├── Excel Model Demo - Complete.xlsx └── Excel Model Demo.xlsx ├── Deepthi Goguri - SQL Internals ├── 1.Parse and Binding.sql ├── 2.Simplification and Trivian plan.sql └── SQLInternalsandArchitecture_DeepthiGoguri.pptx ├── Eleni Bampalouka - The definitive guide to visualize geo spatial data with Power BI └── The definitive guide to visualize geodata with Power BI.pptx ├── Emily Lisa - High Availability Options for Azure SQL └── High Availability Options for Azure SQL - Emily Lisa.pptx ├── Giovanni Luisotto - Monitoring SQL Server with a free-open source solution └── Monitoring SQL Server with a free-open source solution.pdf ├── Heini Ilmarinen - The Ultimate Jigsaw - Architecting Azure Synapse Analytics └── NewStarsofData_HeiniIlmarinen.pdf ├── Justin Moran - Improving the on call experience using Jupyter Notebooks └── New Stars of Data Presentation.pptx ├── Marco Fischer - Advanced_security_of_PaaS_Azure_data_applications └── MF_Advanced_security_of_PaaS_Azure_data_applications.pdf ├── Marthe Moengen - Power BI - Will too many cooks spoil the broth └── Power BI - Will too many cooks spoil the broth, (Marthe Moengen).pdf ├── Martin Guth - Relaxed Releases with DB-Workload-Tests ├── Demo-Workloadtests_en.zip ├── Relaxed-Releases-with-DB-Workload-Tests.pdf └── Videos-Workloadtests.zip ├── Matthias Vill - Taming the dragon an introduction to Regular Expressions ├── Taming The Dragon - An Introduction To Regular Expressions.pdf ├── regex - demo - examples.sql └── regex - demo - script.md ├── Medha Bandari - My data journey from a kid to a teenager └── My data journey from a kid to a teenager.pdf ├── Michellea David - How to create a Centralized Database environment ├── Centralize SSIS.docx └── Centralize SSIS2.pptx ├── Ned Stratton - Structured Data Successful Dates └── New Stars of Data 2020 - Structured Data Successful Dates.pdf ├── Nikola Ilic - MAGNIFICENT 7 - Simple tricks to boost your Power BI Development ├── MAGNIFICENT 7 - Simple tricks to boost your Power BI Development.pdf └── README.md ├── README.md ├── Reitse Eskens - What they should have told me about being a DBA ├── Create Waitstats Job.sql ├── Create Waitstats Table.sql ├── Create WhoIsActive Job.sql ├── Daily full backup script.sql ├── NSOD 2020 Presentation.pdf ├── NSOD Demo.ps1 ├── NSOD OH Jobs Demo.sql ├── NSOD OH Jobs Demo2.xdl ├── Open transaction demo.sql └── WhoIsActive demo.sql ├── Samudra Bandaranayake - Boost your productivity through ETL Automation using Biml └── Boost Your Productivity Through ETL Automation Using Biml.pdf ├── Satya Ramesh - SQL Server Indexes - Back To The Basics ├── 0_SQLServer_Indexes_Back_To_The_Basics.pptx ├── IndexBasics.sql └── IndexFragmentationExample.sql ├── Shaun Atkinson - An Introduction to Azure SQL Database Serverless ├── An Introduction to Azure SQL Database Serverless Presentation.pdf ├── Autoscale Demo.sql └── ServerlessPowershellDemos.ps1 └── Thimantha Vidanagamage - Azure Analysis Services Shifting to an Effective Semantic Model └── Azure Analysis Services - Shifting to an Effective Semantic Model.pdf /Brent Allen - Overcoming Power Resistance with Cube Formulas/Excel Model Demo - Complete.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Brent Allen - Overcoming Power Resistance with Cube Formulas/Excel Model Demo - Complete.xlsx -------------------------------------------------------------------------------- /Brent Allen - Overcoming Power Resistance with Cube Formulas/Excel Model Demo.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Brent Allen - Overcoming Power Resistance with Cube Formulas/Excel Model Demo.xlsx -------------------------------------------------------------------------------- /Deepthi Goguri - SQL Internals/1.Parse and Binding.sql: -------------------------------------------------------------------------------- 1 | --I used AdventureWorks2016 database for this demo 2 | --please get the backup of the Adventureworks2016 database from below link: 3 | https://docs.microsoft.com/en-us/sql/samples/adventureworks-install-configure?view=sql-server-ver15&tabs=ssms 4 | --Download OLTP version of Adventureworks2016 database backup. 5 | --Created by Deepthi Goguri 6 | 7 | --Parsing 8 | 9 | USE [AdventureWorks2016]; 10 | GO 11 | 12 | -- When PARSEONLY option is turned ON, SQL Server only parses the query 13 | 14 | SET PARSEONLY ON; 15 | GO 16 | 17 | /* 18 | Checks for: 19 | 1. syntax of the query 20 | 2. returns any error messages 21 | 3. Doesn't compile or executes the query 22 | 4. No execution plan gets generated 23 | */ 24 | 25 | SELECT * FROM [Production].[Product]; 26 | GO 27 | 28 | --checks for the variable declaration 29 | 30 | SELECT * FROM [Production].[Product] 31 | where size=@x 32 | GO 33 | 34 | /* 35 | The following query doesnt execute because the column and table name does not exist in the database 36 | but if you parse it, statement will still runs without errors because the statement is syntactically correct. 37 | */ 38 | 39 | SELECT noColumn FROM dbo.noTable; 40 | GO 41 | 42 | 43 | -- Reverting back to the default value (OFF) for PARSEONLY 44 | SET PARSEONLY OFF; 45 | GO 46 | 47 | 48 | -- When FMTONLY option is turned ON, SQL Server performs the parsing and binding 49 | -- phases for the statement 50 | -- No execution plan is generated 51 | -- 52 | 53 | /* 54 | Prsing and Binding phases happen when option FMTONLY is turned ON 55 | 1. Execution plan doesn't get generated 56 | 2. Doesn't get processed 57 | 3. No rows are processed or sent to the client 58 | */ 59 | SET FMTONLY ON; 60 | GO 61 | 62 | SELECT 63 | OH.[SalesOrderID] 64 | ,OH.[AccountNumber] 65 | ,OH.[SubTotal] 66 | ,C.CustomerID 67 | FROM 68 | [Sales].[SalesOrderHeader] AS OH 69 | JOIN 70 | [Sales].[Customer] AS C ON OH.CustomerID=C.CustomerID 71 | WHERE 72 | (OH.CustomerID IS NOT NULL); 73 | GO 74 | 75 | 76 | -- binding phase is now executed with FMTONLY=ON, this statement will fail 77 | SELECT noColumn FROM dbo.noTable; 78 | GO 79 | 80 | 81 | SET FMTONLY OFF; 82 | GO 83 | 84 | 85 | /* 86 | Data type resolution 87 | 1. [CustomerID] [SalesOrderID] have the same data type 88 | 2. we can union the results together 89 | */ 90 | 91 | SELECT 92 | [CustomerID] 93 | FROM 94 | [Sales].[Customer] 95 | UNION ALL 96 | SELECT 97 | [SalesOrderID] 98 | FROM 99 | [Sales].[SalesOrderHeader]; 100 | GO 101 | 102 | 103 | /* 104 | Data type error 105 | 1. [CustomerID] is of Data type Int and [CreditCardApprovalCode] is of Data type Varchar 106 | 2. Sending this query to the optimizer throws an error while converting the varchar value 107 | to Data type Int 108 | */ 109 | 110 | SELECT 111 | [CustomerID] 112 | FROM 113 | [Sales].[Customer] 114 | UNION ALL 115 | SELECT 116 | [CreditCardApprovalCode] 117 | FROM 118 | [Sales].[SalesOrderHeader]; 119 | GO 120 | 121 | 122 | -------------------------------------------------------------------------------- /Deepthi Goguri - SQL Internals/2.Simplification and Trivian plan.sql: -------------------------------------------------------------------------------- 1 | --Simplification 2 | 3 | USE [AdventureWorks2016]; 4 | GO 5 | 6 | -- Subqueries to joins 7 | --converts subqueries to joins 8 | 9 | SELECT 10 | OH.[SalesOrderID] 11 | ,OH.[AccountNumber] 12 | ,OH.[SubTotal] 13 | FROM 14 | [Sales].[SalesOrderHeader] AS OH 15 | WHERE 16 | (OH.CustomerID IN (SELECT 17 | [CustomerID] 18 | FROM [Sales].[Customer] 19 | WHERE 20 | [TerritoryID]=1)); 21 | GO 22 | 23 | 24 | -- Unused table and redundant joins 25 | -- Removes unused table, redundant inner and outer joins 26 | 27 | SELECT 28 | OH.[SalesOrderID] 29 | ,OH.[AccountNumber] 30 | ,OH.[SubTotal] 31 | ,OH.[TerritoryID] 32 | FROM 33 | [Sales].[SalesOrderHeader] AS OH 34 | LEFT OUTER JOIN 35 | [Sales].[Customer] AS C ON C.CustomerID=OH.CustomerID 36 | WHERE 37 | (OH.[TerritoryID]=1) 38 | GO 39 | 40 | 41 | -- Contradictions 42 | -- Query Optimizer detects contradictions, such as opposite 43 | -- conditions in the WHERE clause 44 | 45 | SET STATISTICS IO ON; 46 | 47 | SELECT CustomerID,[TerritoryID] 48 | FROM [Sales].[Customer] 49 | WHERE [TerritoryID] = 1 50 | AND [TerritoryID] != 1 51 | OPTION (RECOMPILE) 52 | 53 | 54 | 55 | -- Trivial Plan- Query Optimizer will check if the query is qualified for a trivial plan 56 | --Once the trivial plan is choosen, optimization process ends immediately 57 | 58 | USE [AdventureWorks2016]; 59 | GO 60 | 61 | SELECT 62 | [SalesOrderID] 63 | ,[TerritoryID] 64 | FROM 65 | [Sales].[SalesOrderHeader] 66 | WHERE 67 | [SalesOrderID]=43661; 68 | GO 69 | 70 | --Query having Trivial Plan can be forced to have FULL plan 71 | 72 | -- TF 3604 enables output in the messages tab 73 | -- TF 8757 is used to force Trivial plan to FULL optimization 74 | 75 | SELECT 76 | [SalesOrderID] 77 | ,[TerritoryID] 78 | FROM 79 | [Sales].[SalesOrderHeader] 80 | WHERE 81 | [SalesOrderID]=43661 82 | OPTION(RECOMPILE, QUERYTRACEON 3604, QUERYTRACEON 8757); 83 | GO 84 | 85 | -------------------------------------------------------------------------------- /Deepthi Goguri - SQL Internals/SQLInternalsandArchitecture_DeepthiGoguri.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Deepthi Goguri - SQL Internals/SQLInternalsandArchitecture_DeepthiGoguri.pptx -------------------------------------------------------------------------------- /Eleni Bampalouka - The definitive guide to visualize geo spatial data with Power BI/The definitive guide to visualize geodata with Power BI.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Eleni Bampalouka - The definitive guide to visualize geo spatial data with Power BI/The definitive guide to visualize geodata with Power BI.pptx -------------------------------------------------------------------------------- /Emily Lisa - High Availability Options for Azure SQL/High Availability Options for Azure SQL - Emily Lisa.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Emily Lisa - High Availability Options for Azure SQL/High Availability Options for Azure SQL - Emily Lisa.pptx -------------------------------------------------------------------------------- /Giovanni Luisotto - Monitoring SQL Server with a free-open source solution/Monitoring SQL Server with a free-open source solution.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Giovanni Luisotto - Monitoring SQL Server with a free-open source solution/Monitoring SQL Server with a free-open source solution.pdf -------------------------------------------------------------------------------- /Heini Ilmarinen - The Ultimate Jigsaw - Architecting Azure Synapse Analytics/NewStarsofData_HeiniIlmarinen.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Heini Ilmarinen - The Ultimate Jigsaw - Architecting Azure Synapse Analytics/NewStarsofData_HeiniIlmarinen.pdf -------------------------------------------------------------------------------- /Justin Moran - Improving the on call experience using Jupyter Notebooks/New Stars of Data Presentation.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Justin Moran - Improving the on call experience using Jupyter Notebooks/New Stars of Data Presentation.pptx -------------------------------------------------------------------------------- /Marco Fischer - Advanced_security_of_PaaS_Azure_data_applications/MF_Advanced_security_of_PaaS_Azure_data_applications.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Marco Fischer - Advanced_security_of_PaaS_Azure_data_applications/MF_Advanced_security_of_PaaS_Azure_data_applications.pdf -------------------------------------------------------------------------------- /Marthe Moengen - Power BI - Will too many cooks spoil the broth/Power BI - Will too many cooks spoil the broth, (Marthe Moengen).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Marthe Moengen - Power BI - Will too many cooks spoil the broth/Power BI - Will too many cooks spoil the broth, (Marthe Moengen).pdf -------------------------------------------------------------------------------- /Martin Guth - Relaxed Releases with DB-Workload-Tests/Demo-Workloadtests_en.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Martin Guth - Relaxed Releases with DB-Workload-Tests/Demo-Workloadtests_en.zip -------------------------------------------------------------------------------- /Martin Guth - Relaxed Releases with DB-Workload-Tests/Relaxed-Releases-with-DB-Workload-Tests.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Martin Guth - Relaxed Releases with DB-Workload-Tests/Relaxed-Releases-with-DB-Workload-Tests.pdf -------------------------------------------------------------------------------- /Martin Guth - Relaxed Releases with DB-Workload-Tests/Videos-Workloadtests.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Martin Guth - Relaxed Releases with DB-Workload-Tests/Videos-Workloadtests.zip -------------------------------------------------------------------------------- /Matthias Vill - Taming the dragon an introduction to Regular Expressions/Taming The Dragon - An Introduction To Regular Expressions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Matthias Vill - Taming the dragon an introduction to Regular Expressions/Taming The Dragon - An Introduction To Regular Expressions.pdf -------------------------------------------------------------------------------- /Matthias Vill - Taming the dragon an introduction to Regular Expressions/regex - demo - examples.sql: -------------------------------------------------------------------------------- 1 | -- Can you spot all references to dbo.Tbl? 2 | SELECT * 3 | FROM Tbl; 4 | SELECT * 5 | FROM Tbl2 6 | CROSS JOIN dbo.Tbl; 7 | UPDATE [dbo].Tbl 8 | SET Val = 42; 9 | INSERT INTO dbo.[Tbl] 10 | (Id) 11 | VALUES 12 | (42); 13 | EXEC (N'SELECT * FROM [dbo].[Tbl]'); 14 | GO 15 | 16 | -- Some procedures to rename 17 | CREATE OR ALTER PROCEDURE my.sp_one 18 | AS 19 | BEGIN 20 | PRINT 'You called me'; 21 | END 22 | GO 23 | CREATE OR ALTER PROCEDURE [my].[sp_two] 24 | AS 25 | BEGIN 26 | PRINT 'You called me, too'; 27 | END 28 | GO 29 | 30 | -- So we have these UPDATEs for our DEV-stage, but we need INSERTs for PRD… 31 | UPDATE V 32 | SET Val = 42 33 | FROM our.Vault V 34 | WHERE V.Id = 42; 35 | 36 | -- Ever needed/wanted to normalize line-endings to CR LF? 37 | SELECT VDT.Input, 38 | Output = REPLACE( 39 | REPLACE( 40 | REPLACE(VDT.Input, 41 | CHAR(13)+CHAR(10), 42 | CHAR(10)), 43 | CHAR(13), 44 | CHAR(10)), 45 | CHAR(10), 46 | CHAR(13)+CHAR(10)) 47 | FROM (VALUES('a' + CHAR(13) + CHAR(10) -- 48 | +'b' + CHAR(10) -- 49 | +'c' + CHAR(13))) VDT(Input); 50 | 51 | SELECT VDT.Input, 52 | Output = REPLACE( 53 | REPLACE( 54 | REPLACE(VDT.[Input], 55 | 'RN', 56 | 'N'), 57 | 'R', 58 | 'N'), 59 | 'N', 60 | 'RN') 61 | FROM (VALUES('aRN' -- 62 | +'bN' -- 63 | +'cR')) VDT(Input); 64 | -------------------------------------------------------------------------------- /Matthias Vill - Taming the dragon an introduction to Regular Expressions/regex - demo - script.md: -------------------------------------------------------------------------------- 1 | # Taming the dragon - An introduction to Regular Expressions - Demos! 2 | 3 | ## Input Validation 4 | 5 | ### 'Our serial numbers always have 6 hex-digits' 6 | Possible solution: 7 | 8 | ^[0-9a-zA-Z]{6}$ 9 | 10 | ### 'Names are made of two parts with a space in between' 11 | Possible solution: 12 | 13 | ^(\S+) (\S+)$ 14 | 15 | Notes: 16 | - Names are not all composed of two parts. Probaly it is 1 to many 17 | - `\S` is probably too much, but remember there are many languages having non-english/-latin letters like á, ö, ß, я, … and people will have those in names. Also: people travel and move. 18 | 19 | ### '`a` is repeated an "unprime" number of times' 20 | Possible solution: https://regex101.com/r/152Ua4/3 21 | 22 | ^(a{2,}?)\1++$ 23 | 24 | Notes: 25 | - Probaly not a too common case, but nice to show a bit of the flexibility 26 | - Way more difficult: only validate length without assuming anything about the content 27 | 28 | ### 'It is a valid E-Mail-address' 29 | 30 | There is a RegExp implementing [RFC822](https://www.rfc-editor.org/rfc/rfc822.html\#section-6.1) available at https://www.ex-parrot.com/pdw/Mail-RFC822-Address.html. [A StackOverflow-answer](https://stackoverflow.com/a/20773069/1266906) is to check for an `@`, then send an E-Mail to verify 31 | 32 | http://regex101.com/r/iE0rF5 33 | 34 | ``` 35 | (?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*:(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)(?:,\s*(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*))*)?;\s*) 36 | ``` 37 | 38 | ## Editor Demos 39 | 40 | ### Find all usages of an object in a script (quoted, default schema, …) 41 | 42 | Possible solution: 43 | 44 | ``` 45 | (? input) 111 | { 112 | var output = new StringBuilder(); 113 | var lastWasCR = false; 114 | foreach (var c in input) 115 | { 116 | if (lastWasCR) 117 | { 118 | output.Append("\r\n"); 119 | switch (c) 120 | { 121 | case '\r': 122 | break; 123 | case '\n': 124 | lastWasCR = false; 125 | break; 126 | default: 127 | output.Append(c); 128 | lastWasCR = false; 129 | break; 130 | } 131 | } 132 | else 133 | { 134 | switch (c) 135 | { 136 | case '\r': 137 | lastWasCR = true; 138 | break; 139 | case '\n': 140 | output.Append("\r\n"); 141 | break; 142 | default: 143 | output.Append(c); 144 | break; 145 | } 146 | } 147 | } 148 | 149 | if (lastWasCR) 150 | { 151 | output.Append("\r\n"); 152 | } 153 | 154 | return output.ToString(); 155 | } 156 | ``` 157 | or just search for one ot these: 158 | ``` 159 | \r?\n|\r 160 | (? 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 13 | 14 | END 15 | 16 | DECLARE @jobId BINARY(16) 17 | EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'AX_GetWaitStatistics', 18 | @enabled=1, 19 | @notify_level_eventlog=0, 20 | @notify_level_email=2, 21 | @notify_level_netsend=0, 22 | @notify_level_page=0, 23 | @delete_level=0, 24 | @description=N'No description available.', 25 | @category_name=N'[Uncategorized (Local)]', 26 | @owner_login_name=N'SA', 27 | @notify_email_operator_name=N'', @job_id = @jobId OUTPUT 28 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 29 | /****** Object: Step [CatchEmAll] Script Date: 13-8-2020 13:50:02 ******/ 30 | EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'CatchEmAll', 31 | @step_id=1, 32 | @cmdexec_success_code=0, 33 | @on_success_action=1, 34 | @on_success_step_id=0, 35 | @on_fail_action=2, 36 | @on_fail_step_id=0, 37 | @retry_attempts=3, 38 | @retry_interval=5, 39 | @os_run_priority=0, @subsystem=N'TSQL', 40 | @command=N'IF EXISTS 41 | ( 42 | SELECT * 43 | FROM TEMPDB.dbo.sysobjects 44 | WHERE ID = OBJECT_ID(N''tempdb..#ws_Capture'') 45 | ) 46 | DROP TABLE #ws_Capture; 47 | 48 | CREATE TABLE #ws_Capture 49 | ( 50 | wst_WaitType VARCHAR(50), 51 | wst_WaitTime BIGINT, 52 | wst_WaitingTasks BIGINT, 53 | wst_SignalWaitTime BIGINT 54 | ) 55 | 56 | INSERT INTO #ws_Capture 57 | SELECT 58 | wait_type, 59 | wait_time_ms, 60 | waiting_tasks_count, 61 | signal_wait_time_ms 62 | FROM sys.dm_os_wait_stats 63 | 64 | WAITFOR DELAY ''00:04:30'' 65 | 66 | INSERT INTO WaitStats 67 | SELECT 68 | GETDATE() AS [DATETIME], 69 | DATEPART(DAY,GETDATE()) AS [DAY], 70 | DATEPART(MONTH, GETDATE()) AS [MONTH], 71 | DATEPART(YEAR, GETDATE()) AS [YEAR], 72 | DATEPART(HOUR, GETDATE()) AS [HOUR], 73 | DATEPART(MINUTE, GETDATE()) AS [MINUTE], 74 | DATENAME(DW, GETDATE()) AS DAYOFWEEK, 75 | dm.wait_type AS WaitType, 76 | dm.wait_time_ms - ws.wst_WaitTime AS WaitTime, 77 | dm.waiting_tasks_count - ws.wst_WaitingTasks AS WaitingTasks, 78 | dm.signal_wait_time_ms - ws.wst_SignalWaitTime AS SignalWaitTime 79 | FROM sys.dm_os_wait_stats dm 80 | INNER JOIN #ws_Capture ws ON dm.wait_type = ws.wst_WaitType; 81 | 82 | DROP TABLE #ws_Capture;', 83 | @database_name=N'DBAdmin', 84 | @flags=0 85 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 86 | EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1 87 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 88 | EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'5 min', 89 | @enabled=1, 90 | @freq_type=4, 91 | @freq_interval=1, 92 | @freq_subday_type=4, 93 | @freq_subday_interval=5, 94 | @freq_relative_interval=0, 95 | @freq_recurrence_factor=0, 96 | @active_start_date=20181003, 97 | @active_end_date=99991231, 98 | @active_start_time=0, 99 | @active_end_time=235959, 100 | @schedule_uid=N'2d69dc5f-a1ba-4ab4-8f51-922eba923a53' 101 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 102 | EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)' 103 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 104 | COMMIT TRANSACTION 105 | GOTO EndSave 106 | QuitWithRollback: 107 | IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION 108 | EndSave: 109 | GO 110 | 111 | 112 | -------------------------------------------------------------------------------- /Reitse Eskens - What they should have told me about being a DBA/Create Waitstats Table.sql: -------------------------------------------------------------------------------- 1 | USE [DBAdmin] 2 | GO 3 | 4 | /****** Object: Table [dbo].[WaitStats] Script Date: 13-8-2020 13:48:55 ******/ 5 | SET ANSI_NULLS ON 6 | GO 7 | 8 | SET QUOTED_IDENTIFIER ON 9 | GO 10 | 11 | CREATE TABLE [dbo].[WaitStats]( 12 | [ws_ID] [int] IDENTITY(1,1) NOT NULL, 13 | [ws_DateTime] [datetime] NULL, 14 | [ws_DAY] [int] NULL, 15 | [ws_MONTH] [int] NULL, 16 | [ws_YEAR] [int] NULL, 17 | [ws_HOUR] [int] NULL, 18 | [ws_MINUTE] [int] NULL, 19 | [ws_DAYOFWEEK] [varchar](15) NULL, 20 | [ws_WaitType] [varchar](50) NULL, 21 | [ws_WaitTime] [int] NULL, 22 | [ws_WaitingTasks] [int] NULL, 23 | [ws_SignalWaitTime] [int] NULL, 24 | [ws_time_per_wait] AS ([ws_WaitTime]/case when [ws_WaitingTasks]=(0) then (1) else [ws_WaitingTasks] end), 25 | PRIMARY KEY CLUSTERED 26 | ( 27 | [ws_ID] ASC 28 | )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 29 | ) ON [PRIMARY] 30 | GO 31 | 32 | 33 | -------------------------------------------------------------------------------- /Reitse Eskens - What they should have told me about being a DBA/Create WhoIsActive Job.sql: -------------------------------------------------------------------------------- 1 | USE [msdb] 2 | GO 3 | 4 | /****** Object: Job [AX_Log_WhoIsActive] Script Date: 13-8-2020 14:17:39 ******/ 5 | BEGIN TRANSACTION 6 | DECLARE @ReturnCode INT 7 | SELECT @ReturnCode = 0 8 | /****** Object: JobCategory [[Uncategorized (Local)]] Script Date: 13-8-2020 14:17:39 ******/ 9 | IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1) 10 | BEGIN 11 | EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]' 12 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 13 | 14 | END 15 | 16 | DECLARE @jobId BINARY(16) 17 | EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'AX_Log_WhoIsActive', 18 | @enabled=1, 19 | @notify_level_eventlog=0, 20 | @notify_level_email=2, 21 | @notify_level_netsend=0, 22 | @notify_level_page=0, 23 | @delete_level=0, 24 | @description=N'No description available.', 25 | @category_name=N'[Uncategorized (Local)]', 26 | @owner_login_name=N'sa', 27 | @notify_email_operator_name=N'', @job_id = @jobId OUTPUT 28 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 29 | /****** Object: Step [Log_the_data] Script Date: 13-8-2020 14:17:39 ******/ 30 | EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Log_the_data', 31 | @step_id=1, 32 | @cmdexec_success_code=0, 33 | @on_success_action=1, 34 | @on_success_step_id=0, 35 | @on_fail_action=2, 36 | @on_fail_step_id=0, 37 | @retry_attempts=3, 38 | @retry_interval=5, 39 | @os_run_priority=0, @subsystem=N'TSQL', 40 | @command=N'SET NOCOUNT ON; 41 | 42 | DECLARE @retention INT = 15, 43 | @destination_table VARCHAR(500) = ''WhoIsActive'', 44 | @destination_database sysname = ''DBAdmin'', 45 | @schema VARCHAR(MAX), 46 | @SQL NVARCHAR(4000), 47 | @parameters NVARCHAR(500), 48 | @exists BIT; 49 | 50 | SET @destination_table = @destination_database + ''.dbo.'' + @destination_table; 51 | 52 | --create the logging table 53 | IF OBJECT_ID(@destination_table) IS NULL 54 | BEGIN; 55 | EXEC dbo.sp_WhoIsActive @get_transaction_info = 1, 56 | @get_outer_command = 1, 57 | @get_plans = 1, 58 | @return_schema = 1, 59 | @schema = @schema OUTPUT; 60 | SET @schema = REPLACE(@schema, '''', @destination_table); 61 | EXEC ( @schema ); 62 | END; 63 | 64 | --create index on collection_time 65 | SET @SQL 66 | = ''USE '' + QUOTENAME(@destination_database) 67 | + ''; IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(@destination_table) AND name = N''''cx_collection_time'''') SET @exists = 0''; 68 | SET @parameters = N''@destination_table varchar(500), @exists bit OUTPUT''; 69 | EXEC sys.sp_executesql @SQL, @parameters, @destination_table = @destination_table, @exists = @exists OUTPUT; 70 | 71 | IF @exists = 0 72 | BEGIN; 73 | SET @SQL = ''CREATE CLUSTERED INDEX cx_collection_time ON '' + @destination_table + ''(collection_time ASC)''; 74 | EXEC ( @SQL ); 75 | END; 76 | 77 | --collect activity into logging table 78 | EXEC dbo.sp_WhoIsActive @get_transaction_info = 1, 79 | @get_outer_command = 1, 80 | @get_plans = 1, 81 | @destination_table = @destination_table; 82 | 83 | --purge older data 84 | SET @SQL 85 | = ''DELETE FROM '' + @destination_table + '' WHERE collection_time < DATEADD(day, -'' + CAST(@retention AS VARCHAR(10)) 86 | + '', GETDATE());''; 87 | EXEC ( @SQL );', 88 | @database_name=N'master', 89 | @flags=0 90 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 91 | EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1 92 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 93 | EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'sp_WhoIsActive', 94 | @enabled=1, 95 | @freq_type=4, 96 | @freq_interval=1, 97 | @freq_subday_type=4, 98 | @freq_subday_interval=1, 99 | @freq_relative_interval=0, 100 | @freq_recurrence_factor=0, 101 | @active_start_date=20190320, 102 | @active_end_date=99991231, 103 | @active_start_time=0, 104 | @active_end_time=235959, 105 | @schedule_uid=N'c54d689a-701b-468b-a657-2e31ba46472c' 106 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 107 | EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)' 108 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 109 | COMMIT TRANSACTION 110 | GOTO EndSave 111 | QuitWithRollback: 112 | IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION 113 | EndSave: 114 | GO 115 | 116 | 117 | -------------------------------------------------------------------------------- /Reitse Eskens - What they should have told me about being a DBA/Daily full backup script.sql: -------------------------------------------------------------------------------- 1 | USE DBAdmin 2 | 3 | DECLARE @DatabaseList varchar(max); 4 | 5 | SET @DatabaseList = ( 6 | 7 | SELECT 8 | Name = STUFF( (SELECT DISTINCT ','+DATABASENAME 9 | FROM dbo.OHManagement 10 | where DAILYFULLBACKUP = 1 11 | FOR XML PATH('') 12 | ), 1, 1, '' 13 | ) ) 14 | IF(@DatabaseList is null) 15 | print 'No database has been selected.' 16 | else 17 | EXECUTE [master].[dbo].[DatabaseBackup] 18 | @Databases = @DatabaseList, 19 | @Directory = N'\\yourbackupdir', 20 | @BackupType = 'FULL', 21 | @Verify = 'Y', 22 | @CleanupTime = 480, 23 | @CheckSum = 'Y', 24 | @LogToTable = 'Y', 25 | @CleanupMode = 'AFTER_BACKUP', 26 | @NumberOfFiles = 4, 27 | @Compress = 'Y' -------------------------------------------------------------------------------- /Reitse Eskens - What they should have told me about being a DBA/NSOD 2020 Presentation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Reitse Eskens - What they should have told me about being a DBA/NSOD 2020 Presentation.pdf -------------------------------------------------------------------------------- /Reitse Eskens - What they should have told me about being a DBA/NSOD Demo.ps1: -------------------------------------------------------------------------------- 1 | # Demoscript 1. 2 | # Use for demonstrations only. 3 | # do not run on a production environment without prior testing! 4 | # Both VSCode and Terminal will connect to the latest version of Powershell. 5 | # If you haven't installed core 6 or 7, it will run the regular 5.x build. 6 | # In the Windows Terminal you can choose the version that's used. 7 | # Remember that the installation of a module is version-specific. Installing a module in 5x 8 | # makes it available only to 5.x, not to 6 or 7 if you installed those versions. 9 | 10 | # To check your version of Powershell, run this command: 11 | # Whether you do this in ISE, VSCode, Terminal or the PS Core application shouldn't matter. Or does it. 12 | 13 | $PSVersionTable 14 | 15 | 16 | # first up, let's install the DBA Tools commandlets. 17 | # to get these, just run the following command and accept the repository. It's safe, trust them. 18 | Start-Process https://dbatools.io/secure 19 | 20 | Install-Module dbatools 21 | 22 | 23 | 24 | # In VS Code, this is easy, but you're not bound to Code. 25 | 26 | # You can also use Windows Terminal. 27 | 28 | Install-Module dbachecks 29 | 30 | 31 | 32 | # In Windows Terminal, you can choose between different environments, really cool and this can be very handy. 33 | 34 | 35 | 36 | # If you want to use the modules, you first have to import them :) 37 | # importing modules is easy too! 38 | 39 | Import-Module dbatools 40 | 41 | Import-Module dbachecks 42 | 43 | 44 | 45 | 46 | # Cool! Now we have two of the best Powershell modules ready to use. 47 | # these modules run on any system that has WinRM enabled and where you have the right to log in. 48 | 49 | # Because Powershell eanbles you to use variables, we just enter our logins once and reference them through the variables, just like the servernames 50 | 51 | # local VMWare env. 52 | $ServerList = "WIN-NAJQHOBU8QD\SQL2016DEVELOPER", "WIN-NAJQHOBU8QD\AXIANS_SQL2012_D" 53 | $password = ConvertTo-SecureString 'yourPW' -AsPlainText -Force 54 | $credential = New-Object System.Management.Automation.PSCredential ('sa_admin', $password) 55 | 56 | # Azure Env 57 | $ServerList = "10.4.0.4\sql_nsod", "10.4.0.4\SQLEXPRESS2012", "10.4.0.4\SQLEXPRESS2017" 58 | $password = ConvertTo-SecureString 'yourPW' -AsPlainText -Force 59 | $credential = New-Object System.Management.Automation.PSCredential ('NSOD-Admin', $password) 60 | 61 | 62 | # One of the first things we want to do is import Ola Hallengrens scripts. 63 | #You can go to his site, download the scripts and install them on every server you've got. 64 | 65 | 66 | # but.. boring! 67 | 68 | # And if i think so, i won't be alone, so let's see if there's a command for that. 69 | # you can find all the commands online: 70 | 71 | Start-Process https://dbatools.io/commands/ 72 | 73 | # Type in Ola in the search box and see what happens! 74 | 75 | 76 | 77 | 78 | 79 | 80 | Install-DbaMaintenanceSolution -SqlInstance $ServerList -SqlCredential $credential -ReplaceExisting 81 | 82 | 83 | 84 | 85 | 86 | 87 | # Check out your instance and presto! The software is installed. 88 | 89 | # Now, to control Ola's scripts can be a bit of a nuisance because you have to apply some kind of filtering to them. 90 | # You have to either tell the script that you're going for the user databases, systemdatabases or enter a list of databases. 91 | # But, databases come and go on some servers and remembering to update the script... Yup 92 | 93 | # So I've come up with a small solution that you get to see here first. 94 | 95 | # switch over to SSMS! 96 | 97 | # A really good blog on settings for statistics maintenance by Erin Stellato: 98 | 99 | Start-Process https://www.sqlskills.com/blogs/erin/updating-statistics-with-ola-hallengrens-script/ 100 | 101 | 102 | 103 | # Something that can really come in handy are Glenn Allan Berry's diagnostic scripts 104 | # To create those scripts, check out the following link 105 | 106 | Start-Process https://spaghettidba.com/2019/03/20/generating-a-jupyter-notebook-for-glenn-berrys-diagnostic-queries-with-powershell/ 107 | 108 | # if you've managed to create the notebook, open it in ADS and check out all the goodies in it. 109 | 110 | 111 | 112 | 113 | # Remember I said someting about a free toolkit from Brent Ozar? 114 | 115 | # Same thing as with the Ola solution: 116 | 117 | Install-DbaFirstResponderKit -SqlInstance $ServerList -SqlCredential $credential -Database master -Force 118 | 119 | 120 | 121 | # run it on your machines and done. 122 | 123 | 124 | # oh, you want results? 125 | 126 | # hang on 127 | 128 | 129 | Invoke-DbaQuery -SqlInstance $ServerList -SqlCredential $credential -Database master -Query "EXEC sp_blitz @CheckServerInfo = 1" | Out-GridView 130 | 131 | 132 | # Let's check out the DBA Checks. There are many many many options and you'll really see what it's capable of when you run it on multiple servers. 133 | # Again, Rob Sewell has a great session on the details of this tooling. 134 | # But let's do a simple check. 135 | 136 | #last Backups 137 | Invoke-DbcCheck -SqlInstance $ServerList -SqlCredential $credential -Tags LastBackup -Show Failed 138 | 139 | #Last Good DBCC CheckDB 140 | Invoke-DbcCheck -SqlInstance $ServerList -SqlCredential $credential -Tags LastGoodCheckDb -Show Failed 141 | 142 | # These are two simple examples on how to use the DBA Checks module. 143 | 144 | 145 | # final demo for now: Plan Explorer. 146 | 147 | # I've prepared a deadlock and will open this in SSMS. You'll see that it's readable, but only just. 148 | # When we open the same file in Plan Explorer, we can see what happens and where the deadlocks appear! 149 | # note that the order it is shown in the plan explorer isn't by default what you did. 150 | 151 | 152 | 153 | # end of demo part 1 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | # demo part 2 168 | 169 | 170 | # wait stats, how to capture them 171 | # cool script by Enrico van der Laar 172 | # Let's start in SSMS to check out what to capture and how! 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | # Who is Active, cool script by Adam Machanic 183 | 184 | Install-DbaWhoIsActive -SqlInstance $ServerList -SqlCredential $credential -Database master 185 | 186 | 187 | 188 | # Let's see if we can see anything happening on one or more of our servers. 189 | 190 | Invoke-DbaWhoIsActive -SqlInstance $ServerList -SqlCredential $credential | Out-GridView 191 | 192 | 193 | 194 | 195 | # If you want to log the data from WhoIsActive to a table, check out the accompanying sql file. 196 | 197 | 198 | -------------------------------------------------------------------------------- /Reitse Eskens - What they should have told me about being a DBA/NSOD OH Jobs Demo.sql: -------------------------------------------------------------------------------- 1 | -- let's create the database 2 | 3 | CREATE DATABASE DBADMIN; 4 | GO 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | USE DBADMIN; 19 | GO 20 | 21 | -- now create the table we need 22 | USE [DBAdmin] 23 | GO 24 | 25 | SET ANSI_NULLS ON 26 | GO 27 | 28 | SET QUOTED_IDENTIFIER ON 29 | GO 30 | 31 | CREATE TABLE [dbo].[OHManagement]( 32 | [ID] [int] IDENTITY(1,1) NOT NULL, 33 | [DATABASENAME] [varchar](100) NOT NULL, 34 | [DAILYINDEX] [bit] NULL, 35 | [WEEKINDEX] [bit] NULL, 36 | [DAILYFULLBACKUP] [bit] NULL, 37 | [WEEKFULLBACKUP] [bit] NULL, 38 | [DAILYINCREMENTAL] [bit] NULL, 39 | [LOGBACKUP] [bit] NULL, 40 | [STATISTICSDAILY] [bit] NULL, 41 | [STATISTICSWEEKLY] [bit] NULL, 42 | [SERVERNAME] AS (@@servername), 43 | [INTEGRITYDAILY] [bit] NULL, 44 | [INTEGRITYWEEKLY] [bit] NULL, 45 | PRIMARY KEY CLUSTERED 46 | ( 47 | [ID] ASC 48 | )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 49 | ) ON [PRIMARY] 50 | GO 51 | 52 | ALTER TABLE [dbo].[OHManagement] ADD DEFAULT ((0)) FOR [DAILYINDEX] 53 | GO 54 | 55 | ALTER TABLE [dbo].[OHManagement] ADD DEFAULT ((0)) FOR [WEEKINDEX] 56 | GO 57 | 58 | ALTER TABLE [dbo].[OHManagement] ADD DEFAULT ((0)) FOR [DAILYFULLBACKUP] 59 | GO 60 | 61 | ALTER TABLE [dbo].[OHManagement] ADD DEFAULT ((0)) FOR [WEEKFULLBACKUP] 62 | GO 63 | 64 | ALTER TABLE [dbo].[OHManagement] ADD DEFAULT ((0)) FOR [DAILYINCREMENTAL] 65 | GO 66 | 67 | ALTER TABLE [dbo].[OHManagement] ADD DEFAULT ((0)) FOR [LOGBACKUP] 68 | GO 69 | 70 | ALTER TABLE [dbo].[OHManagement] ADD DEFAULT ((0)) FOR [STATISTICSDAILY] 71 | GO 72 | 73 | ALTER TABLE [dbo].[OHManagement] ADD DEFAULT ((0)) FOR [STATISTICSWEEKLY] 74 | GO 75 | 76 | ALTER TABLE [dbo].[OHManagement] ADD DEFAULT ((0)) FOR [INTEGRITYDAILY] 77 | GO 78 | 79 | ALTER TABLE [dbo].[OHManagement] ADD DEFAULT ((0)) FOR [INTEGRITYWEEKLY] 80 | GO 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 | -- We'll look at the script in a moment 109 | -- First, let's create the job to update the table 110 | 111 | USE [msdb] 112 | GO 113 | 114 | /****** Object: Job [AX_UpdateOHManagement] Script Date: 5-8-2020 21:32:27 ******/ 115 | BEGIN TRANSACTION 116 | DECLARE @ReturnCode INT 117 | SELECT @ReturnCode = 0 118 | /****** Object: JobCategory [[Uncategorized (Local)]] Script Date: 5-8-2020 21:32:27 ******/ 119 | IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1) 120 | BEGIN 121 | EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]' 122 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 123 | 124 | END 125 | 126 | DECLARE @jobId BINARY(16) 127 | EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'AX_UpdateOHManagement', 128 | @enabled=1, 129 | @notify_level_eventlog=0, 130 | @notify_level_email=2, 131 | @notify_level_netsend=0, 132 | @notify_level_page=0, 133 | @delete_level=0, 134 | @description=N'No description available.', 135 | @category_name=N'[Uncategorized (Local)]', 136 | @owner_login_name=N'sa', 137 | @notify_email_operator_name=N'', @job_id = @jobId OUTPUT 138 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 139 | /****** Object: Step [AddNewDatabase] Script Date: 5-8-2020 21:32:27 ******/ 140 | EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'AddNewDatabase', 141 | @step_id=1, 142 | @cmdexec_success_code=0, 143 | @on_success_action=3, 144 | @on_success_step_id=0, 145 | @on_fail_action=2, 146 | @on_fail_step_id=0, 147 | @retry_attempts=3, 148 | @retry_interval=5, 149 | @os_run_priority=0, @subsystem=N'TSQL', 150 | @command=N'MERGE OHMANAGEMENT T USING 151 | (select name 152 | from sys.databases) S 153 | on T.databasename = S.Name 154 | WHEN NOT MATCHED BY TARGET 155 | THEN INSERT (Databasename, dailyindex, weekindex, dailyfullbackup, weekfullbackup, dailyincremental, logbackup, statisticsdaily, statisticsweekly, integritydaily, integrityweekly) 156 | values (name, 0,1,1,1,0,1,0,0,1,0) 157 | WHEN NOT MATCHED BY SOURCE THEN DELETE;', 158 | @database_name=N'DBAdmin', 159 | @flags=0 160 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 161 | /****** Object: Step [CheckFullRecoveryModel] Script Date: 5-8-2020 21:32:27 ******/ 162 | EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'CheckFullRecoveryModel', 163 | @step_id=2, 164 | @cmdexec_success_code=0, 165 | @on_success_action=1, 166 | @on_success_step_id=0, 167 | @on_fail_action=2, 168 | @on_fail_step_id=0, 169 | @retry_attempts=3, 170 | @retry_interval=5, 171 | @os_run_priority=0, @subsystem=N'TSQL', 172 | @command=N'update OHMANAGEMENT 173 | SET LOGBACKUP = 0; 174 | GO 175 | update OHMANAGEMENT 176 | SET LOGBACKUP = 1 177 | WHERE DATABASENAME in (select name 178 | from sys.databases 179 | where recovery_model_desc != ''SIMPLE'' 180 | and name not in (''master'', ''model'', ''tempdb'' ))', 181 | @database_name=N'DBAdmin', 182 | @flags=0 183 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 184 | EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1 185 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 186 | EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'UpdateOla', 187 | @enabled=1, 188 | @freq_type=4, 189 | @freq_interval=1, 190 | @freq_subday_type=1, 191 | @freq_subday_interval=0, 192 | @freq_relative_interval=0, 193 | @freq_recurrence_factor=0, 194 | @active_start_date=20191107, 195 | @active_end_date=99991231, 196 | @active_start_time=180000, 197 | @active_end_time=235959, 198 | @schedule_uid=N'cc7083e4-6342-476e-ab94-182e55c03c13' 199 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 200 | EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)' 201 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 202 | COMMIT TRANSACTION 203 | GOTO EndSave 204 | QuitWithRollback: 205 | IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION 206 | EndSave: 207 | GO 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | -- Now that we've seen the job it creates, let's create a job that uses this table. 220 | 221 | 222 | USE [msdb] 223 | GO 224 | 225 | /****** Object: Job [AX_OH_DAILY_FULL_BACKUP] Script Date: 5-8-2020 21:42:50 ******/ 226 | BEGIN TRANSACTION 227 | DECLARE @ReturnCode INT 228 | SELECT @ReturnCode = 0 229 | /****** Object: JobCategory [[Uncategorized (Local)]] Script Date: 5-8-2020 21:42:50 ******/ 230 | IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1) 231 | BEGIN 232 | EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]' 233 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 234 | 235 | END 236 | 237 | DECLARE @jobId BINARY(16) 238 | EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'AX_OH_DAILY_FULL_BACKUP', 239 | @enabled=1, 240 | @notify_level_eventlog=0, 241 | @notify_level_email=2, 242 | @notify_level_netsend=0, 243 | @notify_level_page=0, 244 | @delete_level=0, 245 | @description=N'No description available.', 246 | @category_name=N'[Uncategorized (Local)]', 247 | @owner_login_name=N'sa', 248 | @notify_email_operator_name=N'', @job_id = @jobId OUTPUT 249 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 250 | /****** Object: Step [Step1] Script Date: 5-8-2020 21:42:50 ******/ 251 | EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Step1', 252 | @step_id=1, 253 | @cmdexec_success_code=0, 254 | @on_success_action=1, 255 | @on_success_step_id=0, 256 | @on_fail_action=2, 257 | @on_fail_step_id=0, 258 | @retry_attempts=3, 259 | @retry_interval=5, 260 | @os_run_priority=0, @subsystem=N'TSQL', 261 | @command=N'USE DBAdmin 262 | 263 | DECLARE @DatabaseList varchar(max); 264 | 265 | SET @DatabaseList = ( 266 | 267 | SELECT 268 | Name = STUFF( (SELECT DISTINCT '',''+DATABASENAME 269 | FROM dbo.OHManagement 270 | where DAILYFULLBACKUP = 1 271 | FOR XML PATH('''') 272 | ), 1, 1, '''' 273 | ) ) 274 | IF(@DatabaseList is null) 275 | print ''No database has been selected.'' 276 | else 277 | EXECUTE [master].[dbo].[DatabaseBackup] 278 | @Databases = @DatabaseList, 279 | @Directory = N''\\yourbackupdir'', 280 | @BackupType = ''FULL'', 281 | @Verify = ''Y'', 282 | @CleanupTime = 480, 283 | @CheckSum = ''Y'', 284 | @LogToTable = ''Y'', 285 | @CleanupMode = ''AFTER_BACKUP'', 286 | @NumberOfFiles = 4, 287 | @Compress = ''Y''', 288 | @database_name=N'DBAdmin', 289 | @flags=20 290 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 291 | EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1 292 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 293 | EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'Daily Full Backup', 294 | @enabled=1, 295 | @freq_type=4, 296 | @freq_interval=1, 297 | @freq_subday_type=1, 298 | @freq_subday_interval=0, 299 | @freq_relative_interval=0, 300 | @freq_recurrence_factor=0, 301 | @active_start_date=20191028, 302 | @active_end_date=99991231, 303 | @active_start_time=200000, 304 | @active_end_time=235959, 305 | @schedule_uid=N'42656cb2-d40f-4e41-94fd-ead601541d94' 306 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 307 | EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)' 308 | IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback 309 | COMMIT TRANSACTION 310 | GOTO EndSave 311 | QuitWithRollback: 312 | IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION 313 | EndSave: 314 | GO 315 | 316 | 317 | 318 | -- Cool, job has been created. Now execute the job to fill the table. 319 | 320 | 321 | 322 | -- That should have worked. Now, what's in the table? 323 | 324 | 325 | Select * -- don't ever use select *, really! ;) 326 | from OHManagement 327 | -------------------------------------------------------------------------------- /Reitse Eskens - What they should have told me about being a DBA/NSOD OH Jobs Demo2.xdl: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | unknown 10 | 11 | unknown 12 | 13 | 14 | update Comments set Score += 1 15 | where score > 150 16 | 17 | 18 | 19 | 20 | unknown 21 | 22 | 23 | update Badges set UserId += 1 24 | where name like 'A%' 25 | 26 | 27 | 28 | 29 | unknown 30 | 31 | 32 | update VoteTypes set name = Name + '2' 33 | where name like 'A%' 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 | -------------------------------------------------------------------------------- /Reitse Eskens - What they should have told me about being a DBA/Open transaction demo.sql: -------------------------------------------------------------------------------- 1 | begin transaction 2 | 3 | -- you've got me! 4 | 5 | select top 100 * 6 | from F1.dbo.F1_points_per_race -------------------------------------------------------------------------------- /Reitse Eskens - What they should have told me about being a DBA/WhoIsActive demo.sql: -------------------------------------------------------------------------------- 1 | -- WHoIsActive demo 2 | 3 | -- Install the script through dbatools. Not because you can, but because you will learn from it. Really. 4 | 5 | 6 | -- What can be logged with whoisactive? Check it out! 7 | 8 | exec sp_whoisactive @help = 1 9 | 10 | 11 | -- Want to log WhoIsActive to a table? 12 | -- https://www.brentozar.com/archive/2016/07/logging-activity-using-sp_whoisactive-take-2/ 13 | 14 | 15 | -- What can you find in my table? 16 | 17 | Select * 18 | from DBADMIN.dbo.whoisactive -------------------------------------------------------------------------------- /Samudra Bandaranayake - Boost your productivity through ETL Automation using Biml/Boost Your Productivity Through ETL Automation Using Biml.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Samudra Bandaranayake - Boost your productivity through ETL Automation using Biml/Boost Your Productivity Through ETL Automation Using Biml.pdf -------------------------------------------------------------------------------- /Satya Ramesh - SQL Server Indexes - Back To The Basics/0_SQLServer_Indexes_Back_To_The_Basics.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Satya Ramesh - SQL Server Indexes - Back To The Basics/0_SQLServer_Indexes_Back_To_The_Basics.pptx -------------------------------------------------------------------------------- /Satya Ramesh - SQL Server Indexes - Back To The Basics/IndexBasics.sql: -------------------------------------------------------------------------------- 1 | -- Create sample database 2 | USE master; 3 | GO 4 | IF EXISTS(SELECT * FROM sys.databases WHERE name='SQLMaestros_Prod') 5 | BEGIN 6 | ALTER DATABASE SQLMaestros_Prod 7 | SET SINGLE_USER WITH ROLLBACK IMMEDIATE 8 | DROP DATABASE SQLMaestros_Prod 9 | END 10 | 11 | CREATE DATABASE SQLMaestros_Prod 12 | GO 13 | 14 | USE SQLMaestros_Prod; 15 | SET NOCOUNT ON; 16 | GO 17 | 18 | -- Create a schema named SQLMaestros_Prod 19 | CREATE SCHEMA [SQLMaestros_Prod] AUTHORIZATION [dbo]; 20 | GO 21 | 22 | -- Create HOLs table in SQLMaestros_Prod database 23 | CREATE Table [SQLMaestros_Prod].[HOLs]( 24 | Column1 INT, 25 | Column2 VARCHAR(8000), 26 | Column3 CHAR(10), 27 | Column4 INT); 28 | GO 29 | 30 | 31 | -- Insert 10000 records into HOLs table 32 | DECLARE @COUNT INT; 33 | SET @COUNT = 1; 34 | DECLARE @DATA1 VARCHAR(7000) 35 | SET @DATA1 = REPLICATE('bigdata',1000) 36 | WHILE @COUNT < 10001 37 | BEGIN 38 | DECLARE @DATA2 INT; 39 | SET @DATA2 = ROUND(10000000*RAND(),0); 40 | INSERT INTO [SQLMaestros_Prod].[HOLs] VALUES(@COUNT,@DATA1,'AAAAA',@DATA2); 41 | SET @COUNT = @COUNT + 1; 42 | END 43 | GO 44 | --SELECT * FROM SQLMaestros_Prod.HOLs 45 | --------------------- 46 | -- End: Setup 47 | --------------------- 48 | 49 | -- Run the following command to clear off all the plans in cache and drop buffers 50 | DBCC FREEPROCCACHE /*Do Not Run These Commnads in Production Environment*/ 51 | DBCC DROPCLEANBUFFERS 52 | 53 | -- To observe Reads 54 | SET STATISTICS IO ON 55 | 56 | -- Check the logical reads and observe the table scan happened 57 | -- Turn on execution plan 58 | SELECT * FROM SQLMaestros_Prod.HOLs 59 | WHERE Column1=125 60 | 61 | --Create a clustered index on Column1 column of HOLs table 62 | CREATE CLUSTERED INDEX CL_HOLs_Column1 63 | ON [SQLMaestros_Prod].[HOLs](Column1 ASC); 64 | GO --DROP INDEX CL_HOLs_Column1 ON SQLMaestros_Prod.HOLs 65 | 66 | 67 | --DBCC IND ('sqlmaestros_prod','[SQLMaestros_Prod].[HOLs]',1) 68 | --DBCC TRACEON (3604) 69 | --DBCC PAGE ('SQLMaestros_Prod',1,1312,3) 70 | --View index information for HOLs table 71 | EXEC sp_helpindex 'SQLMaestros_Prod.HOLs'; 72 | GO 73 | 74 | 75 | -- Check the no.of logical reads and observe the index seek happened 76 | SELECT * FROM SQLMaestros_Prod.HOLs 77 | WHERE Column1=125 78 | 79 | -- Check the no.of logical reads and observe the clustered index scan happened 80 | SELECT * FROM SQLMaestros_Prod.HOLs 81 | WHERE Column4 = 840 -- this value may change in your case 82 | 83 | CREATE NONCLUSTERED INDEX NCL_HOLs_Column4 84 | ON SQLMaestros_Prod.HOLs(Column4) 85 | GO --DROP INDEX NCL_HOLs_Column4 ON SQLMaestros_Prod.HOLs 86 | 87 | -- Check the execution time and observe the index seek and key look up happened 88 | SELECT * FROM SQLMaestros_Prod.HOLs 89 | WHERE Column4 > 840 -- this value may change in your case 90 | 91 | -- DROP INDEX NCL_HOLs_Column4 ON SQLMaestros_Prod.HOLs 92 | 93 | --Covering Index 94 | CREATE NONCLUSTERED INDEX NCL_HOLs_Column4 ON SQLMaestros_Prod.HOLs(Column4) 95 | INCLUDE (Column2,Column3) 96 | GO --DROP INDEX NCL_HOLs_Column4 ON SQLMaestros_Prod.HOLs 97 | 98 | -- Only index seek 99 | SELECT * FROM SQLMaestros_Prod.HOLs 100 | WHERE Column4 = 9442447 -- this value may change in your case 101 | 102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /Satya Ramesh - SQL Server Indexes - Back To The Basics/IndexFragmentationExample.sql: -------------------------------------------------------------------------------- 1 | 2 | SET NOCOUNT ON; 3 | USE tempdb; 4 | GO 5 | 6 | -- Create table T1 7 | -- This table has two columns. one has NEWID() function which will be used to insert some random values into column1 8 | -- Second column is a filler column to fill up the 8k page faster 9 | IF OBJECT_ID('dbo.T1', 'U') IS NOT NULL DROP TABLE dbo.T1; 10 | 11 | CREATE TABLE dbo.T1 12 | ( 13 | col1 UNIQUEIDENTIFIER NOT NULL DEFAULT(NEWID()), 14 | bloat CHAR(2000) NOT NULL DEFAULT('a') 15 | ); 16 | GO 17 | CREATE UNIQUE CLUSTERED INDEX idx_cl_col ON dbo.T1(col1); 18 | GO 19 | 20 | 21 | -- Endless loop. Run for 2 sec and stop. Be careful with this otherwise your machine will crash 22 | SET NOCOUNT ON; 23 | USE tempdb; 24 | WHILE 1 = 1 25 | INSERT INTO dbo.T1 DEFAULT VALUES; 26 | GO 27 | 28 | 29 | -- Check the fragmentation percentage using the DMF. For more details Refer sys.dm_db_index_physical_stats 30 | SELECT avg_fragmentation_in_percent FROM sys.dm_db_index_physical_stats 31 | ( 32 | DB_ID('tempdb'), 33 | OBJECT_ID('dbo.T1'), 34 | 1, 35 | NULL, 36 | NULL 37 | ); 38 | 39 | 40 | -- Reorganize the index (if percentage is >5 and <30) 41 | ALTER INDEX idx_cl_col ON dbo.T1 REORGANIZE 42 | 43 | -- Rebuild the index (if percentage is >30) 44 | ALTER INDEX idx_cl_col ON dbo.T1 REBUILD 45 | 46 | -- Create index using fill factor 47 | CREATE UNIQUE CLUSTERED INDEX idx_cl_col ON dbo.T1(col1) 48 | WITH (FILLFACTOR=50, PAD_INDEX=ON); 49 | GO --DROP INDEX idx_cl_col ON dbo.T1 50 | 51 | -- Drop index 52 | DROP INDEX idx_cl_col ON dbo.T1 53 | 54 | -- Drop the table 55 | DROP TABLE dbo.T1 -------------------------------------------------------------------------------- /Shaun Atkinson - An Introduction to Azure SQL Database Serverless/An Introduction to Azure SQL Database Serverless Presentation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Shaun Atkinson - An Introduction to Azure SQL Database Serverless/An Introduction to Azure SQL Database Serverless Presentation.pdf -------------------------------------------------------------------------------- /Shaun Atkinson - An Introduction to Azure SQL Database Serverless/Autoscale Demo.sql: -------------------------------------------------------------------------------- 1 | 2 | -- autoscale demo 3 | 4 | -- clear procedure cache so that there is no auto tuning on the query 5 | 6 | ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE ; 7 | 8 | -- run CPU intensive query 9 | 10 | DROP TABLE IF EXISTS #Temp1 11 | GO 12 | 13 | DROP TABLE IF EXISTS #Temp2 14 | GO 15 | 16 | SELECT MyInt = CONVERT(BIGINT, o1.object_id) + CONVERT(BIGINT, o2.object_id) + CONVERT(BIGINT, o3.object_id) 17 | INTO #temp1 18 | FROM sys.objects o1 19 | JOIN sys.objects o2 ON o1.object_id < o2.object_id 20 | JOIN sys.objects o3 ON o1.object_id < o3.object_id 21 | order by o1.object_id 22 | 23 | SELECT SUM(CONVERT(BIGINT, o1.MyInt) + CONVERT(BIGINT, o2.MyInt)) 24 | FROM #temp1 o1 25 | JOIN #temp1 o2 ON o1.MyInt < o2.MyInt 26 | 27 | SELECT MyInt = CONVERT(BIGINT, o1.object_id) + CONVERT(BIGINT, o2.object_id) + CONVERT(BIGINT, o3.object_id) 28 | INTO #temp2 29 | FROM sys.objects o1 30 | JOIN sys.objects o2 ON o1.object_id < o2.object_id 31 | JOIN sys.objects o3 ON o1.object_id < o3.object_id 32 | order by o1.object_id 33 | 34 | SELECT SUM(CONVERT(BIGINT, o1.MyInt) + CONVERT(BIGINT, o2.MyInt)) 35 | FROM #temp2 o1 36 | JOIN #temp2 o2 ON o1.MyInt < o2.MyInt 37 | 38 | 39 | -- get cpu usage statistics to show CPU autoscaling 40 | 41 | select end_time as mesurement_end_time, cpu_limit as max_vcores, avg_cpu_percent 42 | from sys.dm_db_resource_stats 43 | order by end_time desc 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Shaun Atkinson - An Introduction to Azure SQL Database Serverless/ServerlessPowershellDemos.ps1: -------------------------------------------------------------------------------- 1 | 2 | # before you begin connect to your Azure account using Connect-AzAccount below 3 | # then find and replace the string Your Resource Group Name in this script 4 | # with the name of your Azure SQL DB resource group. 5 | 6 | Connect-AzAccount 7 | 8 | return 'You pressed F5 and I saved you from giving all your demo ` 9 | secrets away' 10 | 11 | # create a new serverless database 12 | 13 | # Enter your Resource Group Name, and if you want to you can change the 14 | # Database Name, Minimum Number of vCores, Maximum Number of vCores, Database size (GB) 15 | # and Auto Pause Delay in Minutes 16 | 17 | # Ensure the Auto Pause Delay in Minutes is at least 60 and ends with a 0 e.g. 60, 70, 80, 90 etc. 18 | 19 | $ResourceGroup = 'Your Resource Group Name' 20 | $DatabaseName = 'ServerlessPoshTestDB' 21 | $MinVcore = 0.5 22 | $MaxVcore = 1 23 | $MaxsizeinGB = 2 24 | $AutoPauseDelayMins = 60 25 | 26 | # Get Server Name 27 | 28 | $ServerName=Get-AzResource | Where-Object { ($_.ResourceId -match "\b$ResourceGroup\b")} | ` 29 | Select-Object -First 1 -ExpandProperty ResourceId | ForEach-Object {$_.Split('/')[8]} 30 | 31 | $MaxSizeinBytes = 1024*1024*1024*$MaxsizeinGB 32 | 33 | New-AzSqlDatabase -ResourceGroupName $ResourceGroup -ServerName $serverName ` 34 | -DatabaseName $DatabaseName -Edition GeneralPurpose -MaxSizeBytes $MaxSizeinBytes ` 35 | -ComputeModel Serverless -ComputeGeneration Gen5 -MinVcore $MinVcore ` 36 | -MaxVcore $MaxVcore -AutoPauseDelayInMinutes $AutoPauseDelayMins 37 | 38 | #------------------------------------------------------------------------------------------------------------------ 39 | 40 | # Get information about your Serverless Database 41 | 42 | # If you changed the $DatabaseName in the script above then will need to change it below 43 | 44 | $ResourceGroup = 'Your Resource Group Name' 45 | $DatabaseName = 'ServerlessPoshTestDB' 46 | 47 | # Get Server Name 48 | 49 | $ServerName=Get-AzResource | Where-Object { ($_.ResourceId -match "\b$DatabaseName\b")} | ` 50 | Select-Object -ExpandProperty ResourceId | ForEach-Object {$_.Split('/')[8]} 51 | 52 | # Return Serverless DB Status Results 53 | 54 | Get-AzSqlDatabase -ResourceGroupName $ResourceGroup -ServerName $ServerName ` 55 | -DatabaseName $DatabaseName | ` 56 | Select-Object ResourceGroupName, ServerName, DatabaseName, Location, Edition, ` 57 | CurrentServiceObjectiveName, MinimumCapacity, Capacity, ` 58 | AutoPauseDelayInMinutes, MaxSizeBytes, Status 59 | 60 | #---------------------------------------------------------------------------------------------------------------------- 61 | 62 | # change AutoPauseDelay 63 | 64 | # Enter your Resource Group Name 65 | 66 | # If you changed the $DatabaseName in the script above then you will need to change it below 67 | 68 | # This script will fail because AutoPauseDelayMins must end with a 0 69 | 70 | $ResourceGroup = 'Your Resource Group Name' 71 | $DatabaseName = 'ServerlessPoshTestDB' 72 | $MinVcore = 0.5 73 | $MaxVcore = 1 74 | $AutoPauseDelayMins = 75 75 | 76 | # Get Server Name 77 | 78 | $ServerName=Get-AzResource | Where-Object { ($_.ResourceId -match "\b$DatabaseName\b")} | ` 79 | Select-Object -ExpandProperty ResourceId | ForEach-Object {$_.Split('/')[8]} 80 | 81 | 82 | Set-AzSqlDatabase -ResourceGroupName $resourceGroup -ServerName $serverName ` 83 | -DatabaseName $databaseName -AutoPauseDelayInMinutes $AutoPauseDelayMins 84 | 85 | #-------------------------------------------------------------------------------------------------------------------------------- 86 | 87 | # change min and max Vcores 88 | 89 | # Enter your Resource Group Name 90 | # If you changed the $DatabaseName in the script above then will need to change it below 91 | 92 | # This script will fail because $MaxVcore is set to an invalid value. 93 | 94 | # valid $MaxvCore values can be found here 95 | # https://docs.microsoft.com/en-us/azure/azure-sql/database/resource-limits-vcore-single-databases 96 | # or on the Serverless maxVcore slider in the Azure Portal 97 | 98 | $ResourceGroup = 'Your Resource Group Name' 99 | $DatabaseName = 'ServerlessPoshTestDB' 100 | $MinVcore = 0.5 101 | $MaxVcore = 3 102 | $AutoPauseDelayMins = 60 103 | 104 | # Get Server Name 105 | 106 | $ServerName=Get-AzResource | Where-Object { ($_.ResourceId -match "\b$DatabaseName\b")} | ` 107 | Select-Object -ExpandProperty ResourceId | ForEach-Object {$_.Split('/')[8]} 108 | 109 | 110 | Set-AzSqlDatabase -ResourceGroupName $resourceGroup -ServerName $serverName ` 111 | -DatabaseName $databaseName -MinVcore $MinVcore -MaxVcore $MaxVcore 112 | 113 | # ------------------------------------------------------------------------------------------------------------------------------ 114 | 115 | # change multiple settings together 116 | 117 | # Enter your Resource Group Name 118 | 119 | # this script with succeed as all parameters are now valid 120 | 121 | $ResourceGroup = 'Your Resource Group Name' 122 | $DatabaseName = 'ServerlessPoshTestDB' 123 | $MinVcore = 0.5 124 | $MaxVcore = 4 125 | $AutoPauseDelayMins = 70 126 | 127 | # Get Server Name 128 | 129 | $ServerName=Get-AzResource | Where-Object { ($_.ResourceId -match "\b$DatabaseName\b")} | ` 130 | Select-Object -ExpandProperty ResourceId | ForEach-Object {$_.Split('/')[8]} 131 | 132 | Set-AzSqlDatabase -ResourceGroupName $resourceGroup -ServerName $serverName ` 133 | -DatabaseName $DatabaseName -MinVcore $MinVcore -MaxVcore $MaxVcore ` 134 | -AutoPauseDelayInMinutes $AutoPauseDelayMins 135 | 136 | #------------------------------------------------------------------------------------------------------------------------------------- 137 | # Move AdventureWorksLT database to the Serverless compute tier 138 | 139 | # Ensure that the AdventureWorksLT database is on either the Provisoned Compute tier 140 | # or another Azure Service Tier before running this script 141 | 142 | # Instructions about how to create the AdventureWorksLT database in Azure can be found 143 | # here https://docs.microsoft.com/en-us/sql/samples/adventureworks-install-configure?view=sql-server-ver15&tabs=ssms 144 | # under the Deploy to Azure SQL Database heading, Deploy new sample database. 145 | 146 | # Enter your Resource Group Name 147 | # Enter your own Database Name if you want to move one of your own DB's to serverless 148 | 149 | # if you want to you can change the Minimum Number of vCores, Maximum Number of vCores, 150 | # Database size (GB) and Auto Pause Delay in Minutes parameters 151 | 152 | $ResourceGroup = 'Your Resource Group Name' 153 | $DatabaseName = 'AdventureWorksLT' 154 | $MinVcore = 0.5 155 | $MaxVcore = 1 156 | $SizeinGB = 2 157 | $AutoPauseDelayMins = 60 158 | 159 | # Get Server Name 160 | 161 | $ServerName=Get-AzResource | Where-Object { ($_.ResourceId -match "\b$ResourceGroup\b")} | ` 162 | Select-Object -First 1 -ExpandProperty ResourceId | ForEach-Object {$_.Split('/')[8]} 163 | 164 | $MaxSizeinBytes = 1024*1024*1024*$SizeinGB 165 | 166 | Set-AzSqlDatabase -ResourceGroupName $ResourceGroup -ServerName $ServerName ` 167 | -DatabaseName $DatabaseName -Edition GeneralPurpose -MaxSizeBytes $MaxSizeinBytes ` 168 | -ComputeModel Serverless -ComputeGeneration Gen5 -MinVcore $MinVcore -MaxVcore $MaxVcore ` 169 | -AutoPauseDelayInMinutes $AutoPauseDelayMins 170 | 171 | #----------------------------------------------------------------------------------------------------------------------------------- 172 | 173 | 174 | 175 | 176 | -------------------------------------------------------------------------------- /Thimantha Vidanagamage - Azure Analysis Services Shifting to an Effective Semantic Model/Azure Analysis Services - Shifting to an Effective Semantic Model.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLGrillen/NSOD-1/caa3cc2a37b8a85aea80da61260079b819ef58bb/Thimantha Vidanagamage - Azure Analysis Services Shifting to an Effective Semantic Model/Azure Analysis Services - Shifting to an Effective Semantic Model.pdf --------------------------------------------------------------------------------