Skip to content

Instantly share code, notes, and snippets.

View JosiahSiegel's full-sized avatar
🌌

Josiah Siegel JosiahSiegel

🌌
View GitHub Profile
@JosiahSiegel
JosiahSiegel / download_ms365_video.md
Created October 23, 2024 12:56
Download SharePoint/Stream/Teams Video

For those aiming to download videos from MS Teams meetings in which you participated but were not the Organizer, I managed to do so using yt-dlp and ffmpeg. The procedure is quite similar for both tools.

  • Open your Browser (I got it to work in Chrome, Edge and Firefox)
  • Login to portal.office.com
  • Go to where you can play the video you want to download, either via Sharepoint or Streams.
  • Hit F12
  • Go to the "Network" tab
  • Filter: videomanifest
  • Hit F5
  • Start playing the video
@JosiahSiegel
JosiahSiegel / fn_GetPartitionsForRange.sql
Created October 21, 2024 18:51
Get partition ranges or partitions of given range
-- =============================================
-- Author: Josiah Siegel
-- Create date: 2024-10-21
-- Description: Fetch partition ranges or partitions of given range
-- Example:
/*
-- Fetch partition ranges
select * from [fn_GetPartitionsForRange]('MyTable', DEFAULT, DEFAULT, DEFAULT)
-- Fetch partitions of given range
@JosiahSiegel
JosiahSiegel / force_hint.sql
Created October 17, 2024 20:58
Force hint on query in query store
-- get query id
SELECT
q.query_id,
qt.query_sql_text
FROM sys.query_store_query_text qt
INNER JOIN sys.query_store_query q ON
qt.query_text_id = q.query_text_id
WHERE query_sql_text like N'%select column from table%'
GO
@JosiahSiegel
JosiahSiegel / incremental_statistics.sql
Created October 11, 2024 14:59
Update statistics to incremental for partitioned tables
--ALTER DATABASE [MyDB] SET AUTO_CREATE_STATISTICS ON (INCREMENTAL = ON)
SELECT DISTINCT 'UPDATE STATISTICS ' + QUOTENAME(sc.name) + '.' + QUOTENAME(object_name(S.object_id)) + ' (' + QUOTENAME(s.name) + ') WITH INCREMENTAL = ON'
FROM sys.tables T
INNER JOIN sys.schemas sc ON t.schema_id = sc.schema_id
INNER JOIN sys.indexes I
ON T.object_id = I.object_id
INNER JOIN sys.data_spaces DS
ON I.data_space_id = DS.data_space_id
INNER JOIN sys.stats S
ON I.object_id = S.object_id
@JosiahSiegel
JosiahSiegel / bcp_to_azure_file_share.ps1
Last active September 26, 2024 21:19
BCP from Azure SQL to Azure file share
C:\WINDOWS\system32\net.exe use S: '\\mystorageaccount.file.core.windows.net\bcp-share' /u:'mystorageaccount' '<ACCESS_KEY>'
bcp dbo.mytable OUT 'S:\mytable.txt' -d mydb -U [email protected] -a 16192 -G -S 'myserver.database.windows.net' -n -h "tablock" -K ReadOnly
@JosiahSiegel
JosiahSiegel / table_schema_sensitivity.sql
Created September 11, 2024 14:15
MSSQL Table Schema and Sensitivity Details
SELECT
QUOTENAME(schema_name(o.schema_id)) + '.' + QUOTENAME(t.name) AS [table]
,QUOTENAME([c].[name]) AS [column_name]
,IIF(ic.index_id IS NOT NULL, 1, 0) AS [column_in_index]
,QUOTENAME([i].[name]) AS [index_name]
,[i].[type_desc] AS [index_type]
,[sc].information_type AS [info_type]
,[sc].label AS [sensitivity_label]
,[ep].name AS [properties_name]
,[ep].value AS [properties_value]
@JosiahSiegel
JosiahSiegel / ddm_auto.sql
Last active September 10, 2024 17:01
Dynamic Data Masking Automation
/*
EXECUTE AS USER = 'non-admin-user';
SELECT *
FROM masked_table
REVERT;
*/
DECLARE
@JosiahSiegel
JosiahSiegel / azure_sql_quick_analysis.sql
Last active October 11, 2024 17:51
Azure SQL Quick Analysis
SELECT
req.session_id AS [session],
ses.program_name AS [program],
sqltext.TEXT AS [query],
DB_NAME(req.database_id) AS [database],
req.status,
wg.name AS [resource_group],
req.command,
CONVERT(varchar(10), (req.cpu_time / 86400000)) + ':' +
CONVERT(varchar(10), ((req.cpu_time % 86400000) / 3600000)) + ':' +
@JosiahSiegel
JosiahSiegel / elastic_agent_jobs.sql
Last active November 13, 2024 21:16
Elastic Agent Jobs
-- Elastic Agent Jobs
-- https://sqlkitty.com/elastic-jobs-azure-sql-db/
-- Add target group
EXEC jobs.sp_add_target_group 'AzureSQLDBs';
-- Add single database (or server/elastic pool) to target group
EXEC jobs.sp_add_target_group_member
@target_group_name = 'AzureSQLDBs',
@target_type = 'SqlDatabase',
SELECT TOP 100
t.NAME AS [TableName],
SCHEMA_NAME(t.schema_id) AS [SchemaName],
MAX([data_compression_desc]) AS [Compression],
MAX(p.rows) AS [RowCounts],
SUM(a.total_pages) AS [TotalPages],
SUM(a.used_pages) AS [UsedPages],
SUM(a.data_pages) AS [DataPages],
(SUM(a.total_pages) * 8) / 1024 AS [TotalSpaceMB],
(SUM(a.used_pages) * 8) / 1024 AS [UsedSpaceMB],