Skip to content

Instantly share code, notes, and snippets.

@mikeplate
Last active August 4, 2021 13:50
Show Gist options
  • Save mikeplate/2f100f17bf443bc59f439ec42ae59205 to your computer and use it in GitHub Desktop.
Save mikeplate/2f100f17bf443bc59f439ec42ae59205 to your computer and use it in GitHub Desktop.
Microsoft SQL Server T-SQL Snippets
-- Run an Update statement for all tables that have a specific column. Set TenantId=69 in all tables that have that column.
declare @sql nvarchar(max)
set @sql = (select concat('update [', t.name, '] set TenantId=69; ') as [text()]
from sys.columns c join sys.tables t on c.object_id = t.object_id
where c.name = 'TenantId' for xml path(''))
print @sql
execute (@sql)
-- Disable all constrant checks temporarily for a specific table
alter table TheTableName nocheck constraint all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment