September 7, 2010 at 9:41 am
Hi all,
I'm trying to find the table columns that have wrong collation.. THe sql below gives the column names and the collation but I need the table names also.. Any help please?
SELECT c.name, c.collation_name
FROM sys.columns c
WHERE c.OBJECT_ID IN ( SELECT OBJECT_ID
FROM sys.objects o
WHERE o.type = 'U')
GO
Thank you
September 7, 2010 at 9:54 am
Here is one way:
SELECT schema_name(so.schema_id) as SchemaName, object_name(so.object_id) as ObjectName,
c.name, c.collation_name
FROM sys.columns c inner join sys.objects so on c.object_id = so.object_id
WHERE so.type = 'U' and collation_name is not null
Adi
--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
September 7, 2010 at 9:57 am
SELECT Schema_Name(Schema_id) as SchemaName, t.name as TableName, c.name as ColumnName, c.collation_name
FROM sys.tables t INNER JOIN sys.columns c on t.object_id = c.object_id
WHERE collation_name is not null
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 7, 2010 at 10:03 am
Thanks.. Is it possible to find the collation only for varchar fields???
Thank you so much again
September 7, 2010 at 10:12 am
newbieuser (9/7/2010)
Thanks.. Is it possible to find the collation only for varchar fields???Thank you so much again
SELECT ss.name as SchemaName,
t.name as TableName,
c.name as ColumnName,
c.collation_name,
st.name as DataType
FROM sys.tables t
JOIN sys.schemas ss ON ss.schema_id = t.schema_id
JOIN sys.columns c ON t.object_id = c.object_id
JOIN sys.types st ON st.system_type_id = c.system_type_id
WHERE c.collation_name is not null
AND st.name like '%char%' -- all character fields
--AND st.name = 'varchar' -- just varchar fields
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
September 7, 2010 at 11:32 am
You can also use the Information_Schema.Columns system view. It does all of the joins for you, and I find it much easier to remember one view.
SELECT Table_Schema, Table_Name, Column_Name, Collation_Name, Data_Type
FROM Information_Schema.Columns
WHERE Collation_Name IS NOT NULL
AND Data_Type = 'varchar'
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply