Last active
August 4, 2021 13:50
-
-
Save mikeplate/2f100f17bf443bc59f439ec42ae59205 to your computer and use it in GitHub Desktop.
Microsoft SQL Server T-SQL Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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