Skip to content

Instantly share code, notes, and snippets.

View MarkPryceMaherMSFT's full-sized avatar

Mark Pryce-Maher MarkPryceMaherMSFT

View GitHub Profile
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / updatecolumns.sql
Created August 1, 2025 18:41
this generates the script to alter the columns and remove the user defined data types
/*
This is very rough, it doesn't work for ints/bits/etc only varchars
This does not work if there are schema bound views
*/
select 'alter table ' + s.name + '.' + object_name(c.object_id) + ' ALTER COLUMN ' + c.name + ' ' + ttt.name + '(' + convert(varchar,c.max_length) + ');',
c.max_length , c.*, tt.*, s.* from sys.columns c
inner join sys.tables tt on tt.object_id = c.object_id
inner join sys.schemas s on s.schema_id = tt.schema_id
Value Description Meaning
Failure Indicates a failure. Something when wrong. Check the errors.
NotRun Indicates that the operation did not run. We did run - but found no changes to the table.
Success Indicates a success. We found a update i.e. a new delta log and updated the SQL Endpoint.
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / _metadata.json
Created June 18, 2025 23:44
Example metadata file for a DelimitedText text file
{
"KeyColumns": [ "_id_" ],
"SchemaDefinition": {
"Columns": [
{
"Name": "id",
"DataType": "Int32"
},
{
"Name": "Timestamp",
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / mdsync-rest-api.py
Last active November 12, 2025 09:28
Example code using the new fabric rest api
import json
import notebookutils
import sempy.fabric as fabric
from sempy.fabric.exceptions import FabricHTTPException, WorkspaceNotFoundException
def pad_or_truncate_string(input_string, length, pad_char=' '):
# Truncate if the string is longer than the specified length
if len(input_string) > length:
return input_string[:length]
# Pad if the string is shorter than the specified length
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / createstats.sql
Created May 29, 2025 08:52
script to manually create stats
create proc CreateStats @table varchar(128) as
begin
declare @create_type tinyint -- 1 default, 2 Fullscan, 3 Sample
declare @sample_pct tinyint
IF @create_type IS NULL
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / info.sql
Created May 22, 2025 08:17
Useful information about the workspace/warehouse/sql ae
-- Is it a lakehouse or warehouse
SELECT db_name() as db_name, DATABASEPROPERTYEX(db_name(), 'Edition') as [Type]
-- Whats the workspace id?
SELECT DATABASEPROPERTYEX('master', 'workspaceid') AS workspaceid
-- What is the artifact id?
SELECT DATABASEPROPERTYEX(db_name(), 'ArtifactId') AS ArtifactId
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / monitorMirroring.kql
Created May 12, 2025 11:36
script that shows when the tables were last replicated
// use when you have workspace monitoring enabled
// when were tables last updated
MirroredDatabaseTableExecutionLogs
| summarize max(Timestamp), sum(ProcessedRows) by SourceSchemaName, SourceTableName
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / findingwarehouses.sql
Created April 17, 2025 10:18
script to show if the databases are for a lakehouse or warehouse
DECLARE @command varchar(8000)
declare @i int =1;
declare @d int =0;
select @d = max(database_id) from sys.databases;
declare @dbname nvarchar(128);
set @command = '';
while(@i < @d)
begin
set @dbname = '';
select @dbname = name from sys.databases where database_id = @i
SELECT db_name(), DATABASEPROPERTYEX(db_name(), 'Edition')
@MarkPryceMaherMSFT
MarkPryceMaherMSFT / datetime with timezone example.sql
Created March 19, 2025 08:40
Some code to show how to add a timezone to the datetime2 in Fabric
-- Create test table
create table datetest (d varchar(50), dt DATETIME2(6));
insert into datetest SELECT 'Central European Standard Time', CONVERT(DATETIME2(6), '2022-03-27T01:01:00', 126)
AT TIME ZONE 'Central European Standard Time';
insert into datetest SELECT 'Pacific Standard Time' , CONVERT(DATETIME2(6), '2022-03-27T01:01:00', 126)
AT TIME ZONE 'Pacific Standard Time';
select d as TimeZone, dt as DateTime_without_TimeZone,