1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| SELECT a.name AS '表格名稱' , c.name AS '欄位名稱' FROM sysobjects a LEFT JOIN syscomments b ON a.id = b.id LEFT JOIN syscolumns c ON a.id = c.id WHERE a.type = 'V' ORDER BY a.name
SET NOCOUNT ON DECLARE @DataBases table ( VIEW_CATALOG nvarchar(256), VIEW_SCHEMA nvarchar(256), VIEW_NAME sysname, TABLE_CATALOG nvarchar(256), TABLE_SCHEMA nvarchar(256), TABLE_NAME sysname, COLUMN_NAME sysname )
INSERT INTO @DataBases (VIEW_CATALOG , VIEW_SCHEMA , VIEW_NAME , TABLE_CATALOG , TABLE_SCHEMA , TABLE_NAME , COLUMN_NAME)
EXEC sp_msforeachdb ' SELECT * FROM [?].INFORMATION_SCHEMA.VIEW_COLUMN_USAGE WHERE VIEW_CATALOG IN (''資料庫1名稱'', ''資料庫2名稱'') ORDER BY VIEW_CATALOG , VIEW_NAME' SET NOCOUNT OFF SELECT VIEW_CATALOG AS '檢視表資料庫' , VIEW_NAME AS '檢視表名稱' , TABLE_CATALOG AS '對應資料庫' , TABLE_NAME AS '資料表名稱' , COLUMN_NAME AS '欄位名稱' FROM @DataBases
|