In SQL Server maintains a set of tables for storing all of the objects in SQL Server, data types, constraints condition information, configuration options, available resources, etc., which information is called metadata information (the Metadata), and these tables are called System Basis table (System Base tables). In the base table, present in the base portion of the master database table contains information system level range. Present in a particular database (including master db) in the base table contains objects and resource information belonging to the specific database.
Log in using the system administrator, you can check all the systems in the underlying table from sys.objects.
USE master; SELECT [name] ,type_desc FROM sys.objects WHERE type_desc = 'SYSTEM_TABLE' ORDER BY [name];
The system base tables inside the database engine uses only, not the common functionality provided, so when the changes may not guarantee compatibility. In the "sys" prefix table object, e.g. sysobjects, sysindexes, sysusers, sysdatabases the like, is actually compatible with a view (Compatibility Views). SQL Server to maintain backward compatibility (Backward Compatibility) provided by a compatible set of views, such that the compatible applications based on these views constructed not destroyed. And new features, such as partition tables, and other resources regulation will not be added to these views.
Currently, SQL Server recommended routine interface to access the metadata information is the directory view (Cataog Views) . All catalog views, including dynamic management views DMV (Dynamic Management Views) and the view is compatible (Compatibility Views), are present in the "sys" Schema in.
SELECT SCHEMA_NAME(schema_id) AS schema_name ,[name] AS object_name ,type_desc FROM sys.all_objects WHERE SCHEMA_NAME(schema_id) = 'sys' AND type_desc = 'VIEW' ORDER BY object_name;
The name "sys.dm_" the object is the beginning of a dynamic management views DMV (Dynamic Management Views). These dynamic management objects in view there are both functions, but most of view, it is usually referred to as dynamic management views DMV (Dynamic Management Views). DMV is not based on real tables in the database file, but on the show internal database structure. Terms of reference information to display the object DMV, they are divided into several directories.
- dm_exec_ * contains information related to the user code and the Session.
- dm_os_ * contains low-level system information, such as Memory, Locking, Scheduler and the like.
- dm_tran_ * contains details of the transaction.
- dm_io_ * contains the relevant network and disk I / O activity information.
- dm_db_ * contains details of the database and database objects, such as Index and the like.
View catalog (Catalog Views) is built on the inheritance model (Inheritance Model) such that the common property of the object is defined within no duplicate. E.g. sys.objects contains various object types of common attributes, inherited from the sys.tables sys.objects, and it includes a first sys.objects same column, and then add additional columns specific object type.
Can in SQL Server 2008 R2 System Views Map download directory mapping diagram view of the location.
If you want to view a directory query definition, you can use object_definition function or sp_helptext query.
SELECT object_definition (object_id('sys.tables'));
EXEC sp_help 'sys.tables'; EXEC sp_helptext 'sys.tables';
访问 SQL Server 元数据信息还有一些其他方式:
- 信息架构视图(Information Schema Views)
- 系统函数(System Functions)
- 系统存储过程(System Stored Procedures)
例如,通过系统函数查询指定数据库的恢复模型。
SELECT SERVERPROPERTY('Edition') AS Edition ,SERVERPROPERTY('EngineEdition') AS EngineEdition ,DATABASEPROPERTYEX('msdb', 'Recovery') AS RecoveryModel;
目录视图(Catalog Views)是访问 SQL Server 元数据信息的首选接口,其次是系统函数(System Functions)。
《人人都是 DBA》系列文章索引:
**********转摘:https://www.cnblogs.com/gaochundong/p/everyone_is_a_dba_sqlserver_metadata.html
SQL Server 中维护了一组表用于存储 SQL Server 中所有的对象、数据类型、约束条件、配置选项、可用资源等信息,这些信息称为元数据信息(Metadata),而这些表称为系统基础表(System Base Tables)。在这些基础表中,存在于 master 数据库中的一部分基础表包含系统级范围的信息。存在于特定数据库(也包含 master db)中的基础表包含属于该特定数据库的对象和资源信息。
使用系统管理员身份登录,可以从 sys.objects 中查询所有的系统基础表。
USE master; SELECT [name] ,type_desc FROM sys.objects WHERE type_desc = 'SYSTEM_TABLE' ORDER BY [name];
系统基础表仅在数据库引擎内部使用,并不是提供的通用功能,所以当变化时可能无法保证兼容性。这些以 "sys" 为前缀的表对象,例如 sysobjects, sysindexes, sysusers, sysdatabases 等,实际上是兼容视图(Compatibility Views)。SQL Server 通过提供兼容视图的集合来保持向后兼容(Backward Compatibility),使得基于这些兼容视图构建的应用程序不会被破坏。而新增的特性,例如表分区、资源调控等将不会被添加到这些视图中。
目前,SQL Server 推荐的访问元数据信息的常规接口是目录视图(Catalog Views)。所有的目录视图,包括动态管理视图 DMV(Dynamic Management Views)和兼容视图(Compatibility Views),均存在于 "sys" Schema 中。
SELECT SCHEMA_NAME(schema_id) AS schema_name ,[name] AS object_name ,type_desc FROM sys.all_objects WHERE SCHEMA_NAME(schema_id) = 'sys' AND type_desc = 'VIEW' ORDER BY object_name;
名称为 "sys.dm_" 开头的对象即为动态管理视图 DMV(Dynamic Management Views)。这些动态管理对象中既有视图也有函数,但大部分是视图,所以通常称为动态管理视图 DMV(Dynamic Management Views)。DMV 不是基于数据库文件的真实的表,而是基于内部数据库结构的展现。根据 DMV 对象展示的信息的职责范围,它们被分成若干个目录。
- dm_exec_* 包含与用户代码执行和 Session 相关的信息。
- dm_os_* 包含低层系统信息,如 Memory、Locking、Scheduler 等。
- dm_tran_* 包含事务的细节信息。
- dm_io_* 包含网络和磁盘 I/O 活动相关的信息。
- dm_db_* 包含数据库和数据库对象的细节信息,如 Index 等。
目录视图(Catalog Views)是构建在继承模型(Inheritance Model)上的,使得对象的通用属性不必在内部进行重复定义。例如 sys.objects 包含了各种对象类型的通用属性,而 sys.tables 继承自 sys.objects,所以首先包含有与 sys.objects 完全相同的列,然后再添加特定对象类型的附加列。
可以在 SQL Server 2008 R2 System Views Map 位置下载目录视图的映射关系图。
如果要查询某个目录视图的定义,可以使用 object_definition 函数或 sp_helptext 进行查询。
SELECT object_definition (object_id('sys.tables'));
EXEC sp_help 'sys.tables'; EXEC sp_helptext 'sys.tables';
访问 SQL Server 元数据信息还有一些其他方式:
- 信息架构视图(Information Schema Views)
- 系统函数(System Functions)
- 系统存储过程(System Stored Procedures)
例如,通过系统函数查询指定数据库的恢复模型。
SELECT SERVERPROPERTY('Edition') AS Edition ,SERVERPROPERTY('EngineEdition') AS EngineEdition ,DATABASEPROPERTYEX('msdb', 'Recovery') AS RecoveryModel;
Catalog views (Catalog Views) to access SQL Server is the preferred interface metadata information, followed by system function (System Functions).
"Everyone is DBA" series Index:
********** Zhuanzhai: https://www.cnblogs.com/gaochundong/p/everyone_is_a_dba_sqlserver_metadata.html