Last active
December 1, 2020 19:29
-
-
Save tcartwright/a1cc60eb8860171d876df13a5b04585c to your computer and use it in GitHub Desktop.
SQL SERVER: List tables with ANSI PADDING off
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
IF OBJECT_ID('tempdb..#tbl') IS NOT NULL DROP TABLE #tbl | |
CREATE TABLE #tbl ( | |
[DBName] sysname, | |
[TableName] sysname, | |
[ColumnName] sysname, | |
[DataType] sysname | |
) | |
EXEC master.dbo.sp_MSforeachdb @command1 = N' | |
USE [?] | |
INSERT INTO #tbl ( | |
[DBName], | |
[TableName], | |
[ColumnName], | |
[DataType] | |
) | |
SELECT ''?'', | |
[t].[name] AS [TableName], | |
[c].[name] AS [ColumnName], | |
[typ].[name] AS [DataType] | |
FROM [sys].[columns] AS [c] | |
INNER JOIN [sys].[tables] AS [t] ON [c].object_id = [t].object_id | |
INNER JOIN [sys].[types] AS [typ] ON [c].[system_type_id] = [typ].[system_type_id] | |
AND [c].[user_type_id] = [typ].[user_type_id] | |
WHERE [t].[type] = N''U'' | |
AND [c].[is_ansi_padded] = 0 | |
AND ([typ].[name] LIKE ''%char'' | |
OR [typ].[name] LIKE ''%binary''); | |
' | |
SELECT t.DBName, | |
t.TableName, | |
t.ColumnName, | |
t.DataType | |
FROM #tbl t |
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 [t].[name] AS [TableName], | |
[c].[name] AS [ColumnName], | |
[typ].[name] AS [DataType] | |
FROM [sys].[columns] AS [c] | |
INNER JOIN [sys].[tables] AS [t] ON [c].object_id = [t].object_id | |
INNER JOIN [sys].[types] AS [typ] ON [c].[system_type_id] = [typ].[system_type_id] AND [c].[user_type_id] = [typ].[user_type_id] | |
WHERE [t].[type] = N'U' | |
AND [c].[is_ansi_padded] = 0 | |
AND ([typ].[name] LIKE '%char' | |
OR [typ].[name] LIKE '%binary'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment