Skip to content

Instantly share code, notes, and snippets.

View MarkPryceMaherMSFT's full-sized avatar

Mark Pryce-Maher MarkPryceMaherMSFT

View GitHub Profile
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / GDPR.sql
Created March 12, 2018 17:20
Code observerd from the Data Classify function in SSMS 17.5
DECLARE @Dictionary TABLE
(
pattern NVARCHAR(128),
info_type NVARCHAR(128),
sensitivity_label NVARCHAR(128),
can_be_numeric BIT
)
INSERT INTO @Dictionary (pattern, info_type, sensitivity_label, can_be_numeric)
VALUES
('%username%' ,'Credentials' , 'Confidential' ,1),
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / UpdateExtendedProperties.sql
Created March 12, 2018 19:50
Script for updating Extented Properties
exec sp_updateextendedproperty @name=N'sys_sensitivity_label_name', @level0type=N'schema', @level0name=N'Sales',
@level1type=N'table', @level1name=N'CustomerTransactions', @level2type=N'column',
@level2name=N'AmountExcludingTax',@value=N'Confidential'
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / UpdateExtendedPropertiesCustom.sql
Created March 12, 2018 20:06
Update Extended Properties custom
exec sp_updateextendedproperty @name=N'sys_sensitivity_label_name',
@level0type=N'schema',@level0name=N'Sales',@level1type=N'table',
@level1name=N'CustomerTransactions',@level2type=N'column',
@level2name=N'AmountExcludingTax',@value=N'Custom Confidential'
-- simple function to wrap try_parse
create FUNCTION dbo.check_my_number (@value varchar(255))
RETURNS bigint
as
BEGIN
declare @rt bigint;
set @rt = try_parse(@value as bigint)
return @rt;
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / number_check.sql
Created April 1, 2022 16:39
Sample test for check_my_number
-- code to test number check
select dbo.check_my_number('10') as test1
,dbo.check_my_number('boo') as test2
,dbo.check_my_number('10.1') as test3
,dbo.check_my_number('-10') as test4
create FUNCTION dbo.check_my_decimal (@value varchar(255))
RETURNS decimal(18,2)
as
BEGIN
declare @rt decimal(18,2)
set @rt = try_parse(@value as decimal(18,2))
return @rt;
END;
create FUNCTION dbo.check_my_date (@value varchar(255))
RETURNS datetime2
as
BEGIN
declare @rt datetime2;
set @rt = convert(datetime2,'19000101') -- default value
if @value = '0' -- special case
begin
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / date_test.sql
Created April 1, 2022 18:01
test script for dates
create table dbo.date_test
(
date_test varchar(100)
)
insert into dbo.date_test values ('0');
insert into dbo.date_test values ('1901/01/01');
insert into dbo.date_test values ('error');
insert into dbo.date_test values ('2060/01/01');
insert into dbo.date_test values ('013/013/2060');
--https://docs.microsoft.com/en-us/azure/synapse-analytics/sql-data-warehouse/sql-data-warehouse-tables-overview
SELECT
[Fully Entity Name] = t.full_entity_name,
[Schema Name] = t.schema_name,
[Entity Name] = t.entity_name,
[Current Distribution Method] = t.distribution_method,
[Current Distribution Column] = ISNULL(t.distribution_column, '-'),
[Current Rows] = SUM(t.rows_count),
[Distribution Count] = COUNT(t.rows_count),
[Current Data Size on Disk MB] = SUM(t.data_size_MB),
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / get_dwu_size.sql
Last active April 4, 2022 22:02
size of dedicated sql pool
-- Size of dedicated SQL pool
SELECT DATABASEPROPERTYEX (DB_NAME(), 'ServiceObjective' ) as ServiceObjective