SQL Server metadata classification

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.

Copy the code
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;
Copy the code

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》系列文章索引:

 序号 

 名称 

1

 人人都是 DBA(I)SQL Server 体系结构

2

 人人都是 DBA(II)SQL Server 元数据

3

 人人都是 DBA(III)SQL Server 调度器

4

 人人都是 DBA(IV)SQL Server 内存管理

5

 人人都是 DBA(V)SQL Server 数据库文件

6

 人人都是 DBA(VI)SQL Server 事务日志

7

 人人都是 DBA(VII)B 树和 B+ 树

8

 人人都是 DBA(VIII)SQL Server 页存储结构

9

 人人都是 DBA(IX)服务器信息收集脚本汇编

10

 人人都是 DBA(X)资源信息收集脚本汇编

11

 人人都是 DBA(XI)I/O 信息收集脚本汇编

12

 人人都是 DBA(XII)查询信息收集脚本汇编

13

 人人都是 DBA(XIII)索引信息收集脚本汇编

14

 人人都是 DBA(XIV)存储过程信息收集脚本汇编 

15

 人人都是 DBA(XV)锁信息收集脚本汇编

 

 

**********转摘: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 中。

Copy the code
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;
Copy the code

名称为 "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:

 No. 

 name 

1

 Everyone is a DBA (I) SQL Server Architecture

2

 Everyone is DBA (II) SQL Server metadata

3

 Everyone is DBA (III) SQL Server scheduler

4

 Everyone is DBA (IV) SQL Server memory management

5

 Everyone is DBA (V) SQL Server database files

6

 Everyone is DBA (VI) SQL Server transaction log

7

 Everyone is DBA (VII) B and B + Tree Tree

8

 Everyone is DBA (VIII) SQL Server memory page structure

9

 Everyone is DBA (IX) server information collection script compilation

10

 Everyone is DBA (X) resource information collection script compilation

11

 Everyone is DBA (XI) I / O information collection script compilation

12

 Everyone is DBA (XII) query information collection script compilation

13

 Everyone is DBA (XIII) index information collection script compilation

14

 Everyone is DBA (XIV) stored procedure information collection script compilation 

15

 Everyone is DBA (XV) lock information collection script compilation

 

 

********** Zhuanzhai: https://www.cnblogs.com/gaochundong/p/everyone_is_a_dba_sqlserver_metadata.html

Guess you like

Origin www.cnblogs.com/linybo/p/11671315.html