我正在尝试在具有125个表的数据库中找到未知的特定列。我正在寻找一个通配符,比如“%watcher%”。这可能吗?
答案 0 :(得分:4)
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE column_name LIKE '%watcher%'
[AND table_schema = 'database']
答案 1 :(得分:1)
这会向您显示更多信息......
DECLARE @columnName as varchar(100)
SET @columnName = 'ColumnName'
SELECT t.name AS Table, c.name AS Column,
ty.name AS Type, c.max_length AS Length, c.precision AS Precision
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
INNER JOIN sys.types ty ON c.system_type_id = ty.system_type_id
WHERE c.name LIKE @columnName
ORDER BY t.name, c.name
希望它有所帮助!