如何限制以下查询仅返回数据库中的表并排除视图?
USE [Database Name] SELECT * FROM INFORMATION_SCHEMA.COLUMNS
答案 0 :(得分:1)
Microsoft不鼓励使用INFORMATION_SCHEMA。如果您不想使用sys视图,那么这样做的方法是:
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS AS C
INNER JOIN INFORMATION_SCHEMA.TABLES AS T
ON T.TABLE_SCHEMA = C.TABLE_SCHEMA
AND T.TABLE_NAME = C.TABLE_NAME
WHERE T.TABLE_TYPE = 'BASE TABLE'
答案 1 :(得分:0)
将它加入sys.Tables:
SELECT c.*
FROM INFORMATION_SCHEMA.COLUMNS c inner join sys.tables t
on c.Table_Name = t.name