Search columns in SQL Server 2005 database

Rédigé par M Sozezzo - - Aucun commentaire

-- Since SQL Server 2005 Management Studio lacks the Object Search feature, here is the simple query to find any column in a database

Select O.name objectName, C.name ColumnName
from sys.columns C inner join sys.objects O
ON C.object_id=O.object_id
where C.name like ‘%ColumntoFind%’order by O.name,C.name

-- This query works for SQL Server 20005. Just replace “ColumnToFind” with your required column name.

SELECT
OBJECT_NAME(c.OBJECT_ID) TableName
,c.name AS ColumnName
,SCHEMA_NAME(t.schema_id) AS SchemaName
,t.name AS TypeName
,t.is_user_defined
,t.is_assembly_type
,c.max_length
,c.PRECISION
,c.scale
FROM sys.columns AS c
JOIN sys.types AS t ON c.user_type_id=t.user_type_id
where
C.name like '%ColumntoFind%'
ORDER BY c.OBJECT_ID;


-- Site d'origine : Pinal Dave ( http://blog.SQLAuthority.com/ )
-- Site d'origine : http://blog.namwarrizvi.com/

Fil RSS des articles de ce mot clé