Skip to content

Instantly share code, notes, and snippets.

Gavin Campbell gavincampbell

View GitHub Profile
@gavincampbell
gavincampbell / CreateDateAzureSQLDW.sql
Last active Nov 7, 2016 — forked from mlongoria/CreateDateAzureSQLDW.sql
Creates a calendar table in Azure SQL Data Warehouse
View CreateDateAzureSQLDW.sql
--Creates a table called Dim.Calendar. Change the table name on line 69. Change date range on line 2.
DECLARE @StartDate DATE = '20000101', @NumberOfYears INT = 30;
-- prevent set or regional settings from interfering with
-- interpretation of dates / literals
CREATE TABLE #dimdate
(
[date] DATE,
[day] tinyint,
@gavincampbell
gavincampbell / SingleRowTable.sql
Last active Dec 17, 2015
Pattern for creating tables that can only ever have one row.
View SingleRowTable.sql
CREATE TABLE ConfigTable(
[ConstrainToSingleRow] [BIT] NOT NULL DEFAULT ((1)),
SomeValue [INT] NULL,
A_String [VARCHAR](10) NULL,
Flag1 [BIT] NULL DEFAULT ((0)),
Flag2 [BIT] NULL DEFAULT ((0)),
A_decimal [DECIMAL](9, 2) NULL,
PRIMARY KEY CLUSTERED
(
@gavincampbell
gavincampbell / oops.sql
Last active Mar 6, 2016
Transact-SQL script to drop all user-defined objects accidentally created in the SQL Server master database
View oops.sql
DECLARE @dropStatements TABLE (dropStatement varchar(1000), dropOrder tinyint);
DECLARE @dropStatement varchar(1000);
INSERT INTO @dropStatements
select
CONCAT(
'DROP',' ',
typename,' ',
OBJECT_SCHEMA_NAME(object_id),
'.',
OBJECT_NAME(object_id),';'),
You can’t perform that action at this time.