Skip to content

Instantly share code, notes, and snippets.

View MarkPryceMaherMSFT's full-sized avatar

Mark Pryce-Maher MarkPryceMaherMSFT

View GitHub Profile
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / round_robin_part_2.sql
Created April 7, 2022 00:04
The size of data that will fill a distribution
/*
create table [dbo].[round_robin_test1]
with ( distribution = round_robin) as select * from [dbo].[lineitem_source] where 1 = 0
insert into [dbo].[round_robin_test1]
select top 157 * from [dbo].[lineitem_source]
*/
exec gettbldetails '%round_robin_test1%'
SELECT
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / round_robin_1.sql
Created April 4, 2022 23:32
uneven distribution of data in round_robin tables
/*
drop table [dbo].[round_robin_test1]
create table [dbo].[round_robin_test1]
with ( distribution = round_robin) as select * from [dbo].[lineitem_source]
where 1 = 0
drop table [dbo].[round_robin_test1]
create table [dbo].[round_robin_test1]
create table test_table
(
col_a int,
col_b int
) with ( distribution=round_robin)
declare @table_object_id bigint;
select object_id, * from sys.tables where name like 'test_table'
select @table_object_id = object_id from sys.tables where name like 'test_table'
-- distributions
select * from sys.pdw_distributions
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / get_dwu_size2.sql
Created April 4, 2022 22:03
size of dedicated sql pool
-- Run against master database
SELECT db.name [Database]
, ds.edition [Edition]
, ds.service_objective [Service Objective]
FROM sys.database_service_objectives AS ds
JOIN sys.databases AS db ON ds.database_id = db.database_id;
@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
--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 / 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');
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
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;