master中的sysdatabase表记录SQL Server中的数据库信息。每新建一个数据库,sysdatabase表就会增加一项。
INFORMATION_SCHEMA.TABLES记录着当前数据库中所有表和视图的信息。以下是该视图的定义和使用示例:
--Identifies tables accessible to the current user
create view INFORMATION_SCHEMA.TABLES
as
select distinct
db_name() as TABLE_CATALOG
,user_name(o.uid) as TABLE_SCHEMA
,o.name as TABLE_NAME
,case o.xtype
when 'U' then 'BASE TABLE'
when 'V' then 'VIEW'
end as TABLE_TYPE
from
sysobjects o
where
o.xtype in ('U', 'V') and
permissions(o.id) != 0
IF EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'T1')
DROP TABLE T1
GO
CREATE TABLE T1 ( aa int, bb varchar(30))
INSERT T1 VALUES (1, 'Ro')
总结的零零散散,也没有条理