在SQL SERVER中,如何获取所有表名,列名和所有者的列表?
我已经这样做了,但我从哪里获得了OWNER的详细信息?
SELECT t.name AS tableName,
s.name SchemaName
FROM sys.tables AS t
INNER JOIN sys.schemas AS s
ON t.[schema_id] = s.[schema_id]
答案 0 :(得分:2)
请注意" TABLE_OWNER"与" SCHEMA所有者"相同和" TABLE_TYPE"将识别该项目是否为表格或视图。
希望这有帮助!
--This will return all tables, table owners and table types for all database(s) that are NOT 'Offline'
--Offline database information will not appear
Declare @temp_table table(
DB_NAME varchar(max),
TABLE_OWNER varchar(max),
TABLE_NAME varchar(max),
TABLE_TYPE varchar(max),
REMARKS varchar(max)
)
INSERT INTO @temp_table (DB_NAME, TABLE_OWNER, TABLE_NAME, TABLE_TYPE,REMARKS)
EXECUTE master.sys.sp_MSforeachdb 'USE [?]; EXEC sp_tables'
SELECT *
FROM @temp_table
--Uncomment below if you are seaching for 1 database
--WHERE DB_NAME = '<Enter specific DB Name>'
--For all databases other than 'System Databases'
WHERE DB_NAME not in ('master','model','msdn','tempdb')
order by 1
答案 1 :(得分:1)
您是否尝试过使用内置的sp_tables
存储过程?有关用法,请参阅http://msdn.microsoft.com/en-us/library/ms186250.aspx。
我会将此作为评论添加,但我显然需要50个声誉。