Last active
December 21, 2021 10:31
-
-
Save ax4413/eefcd79b66ff9e6eca12efff98de598a to your computer and use it in GitHub Desktop.
update every column in a table
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
SELECT 'UPDATE '+ QUOTENAME(SCHEMA_NAME(t.schema_id)) + '.' + QUOTENAME(t.name) + CHAR(10) | |
+ 'SET' | |
+ pk.ColumnList + ';' | |
FROM sys.tables t | |
CROSS APPLY (SELECT DISTINCT STUFF((SELECT CHAR(10) + CHAR(9) + ', ' + QUOTENAME(c.name) + ' = ' + 'REPLACE(' + QUOTENAME(c.name) + ', ''"'', '''')' | |
FROM sys.columns c | |
WHERE c.object_id = t.object_id | |
FOR XML PATH(''),TYPE).value('(./text())[1]','VARCHAR(MAX)'),1,3,'') AS ColumnList | |
)pk | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment