Is there a script I can use to find all columns in all tables in a SQL catalog that does not have the collation <database default>
?
I have taken over a legacy system and have different collations in the some tables and I would like to find all instances in one hit rather than going through manually.
However I don't want to change the collation programmatically as I would like to review each table one by one.
To view the collation setting of a databaseIn Object Explorer, connect to an instance of the Database Engine and on the toolbar, click New Query. In the query window, enter the following statement that uses the sys. databases system catalog view. SELECT name, collation_name FROM sys.
Finding collation of a column in a table. In SSMS, go to the table, then columns, and finally right-click the individual columns to view the “Properties”. If the column is of a character data type, you will see details of the collation.
The SQL_Latin1_General_CP1_CI_AS collation is a SQL collation and the rules around sorting data for unicode and non-unicode data are different. The Latin1_General_CI_AS collation is a Windows collation and the rules around sorting unicode and non-unicode data are the same.
Try this script here:
DECLARE @DatabaseCollation VARCHAR(100) SELECT @DatabaseCollation = collation_name FROM sys.databases WHERE database_id = DB_ID() SELECT @DatabaseCollation 'Default database collation' SELECT t.Name 'Table Name', c.name 'Col Name', ty.name 'Type Name', c.max_length, c.collation_name, c.is_nullable FROM sys.columns c INNER JOIN sys.tables t ON c.object_id = t.object_id INNER JOIN sys.types ty ON c.system_type_id = ty.system_type_id WHERE t.is_ms_shipped = 0 AND c.collation_name <> @DatabaseCollation
It checks for the database default collation and then finds any columns that don't comply with that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With