sql:SQL Server metadata queries

本文涉及的产品
RDS SQL Server Serverless,2-4RCU 50GB 3个月
推荐场景:
云数据库 RDS SQL Server,基础系列 2核4GB
简介: -- 2012--https://technet.microsoft.com/zh-cn/library/ms186778(v=sql.110).aspx--对象目录视图 (Transact-SQL)select * from sys.foreign_keysselect * from sys.foreign_key_columnsselect * from sys.all_c
-- 2012
--https://technet.microsoft.com/zh-cn/library/ms186778(v=sql.110).aspx
--对象目录视图 (Transact-SQL)
select * from sys.foreign_keys
select * from sys.foreign_key_columns

select * from sys.all_columns 
select * from sys.all_objects 
select * from sys.all_parameters 
select * from sys.all_sql_modules 
select * from sys.all_views 
select * from sys.allocation_units 
select * from sys.assembly_modules 
select * from sys.check_constraints 
select * from sys.column_store_dictionaries 
select * from sys.column_store_segments 
select * from sys.columns 
select * from sys.computed_columns 
select * from sys.default_constraints 
select * from sys.events 
select * from sys.event_notifications 
select * from sys.event_notification_event_types 
select * from sys.extended_procedures 
select * from sys.foreign_keys 
select * from sys.foreign_key_columns 
select * from sys.function_order_columns 
select * from sys.identity_columns 
select * from sys.indexes 
select * from sys.index_columns 
select * from sys.internal_tables 
select * from sys.key_constraints 
select * from sys.module_assembly_usages 
select * from sys.numbered_procedures 
select * from sys.numbered_procedure_parameters 
select * from sys.objects 
select * from sys.parameters 
select * from sys.partitions 
select * from sys.plan_guides 
select * from sys.procedures 
select * from sys.sequences 
select * from sys.server_assembly_modules 
select * from sys.server_events 
select * from sys.server_event_notifications 
select * from sys.server_sql_modules 
select * from sys.server_triggers 
select * from sys.server_trigger_events 
select * from sys.sql_dependencies 
select * from sys.sql_expression_dependencies 
select * from sys.sql_modules 
select * from sys.stats 
select * from sys.stats_columns 
select * from sys.synonyms 
select * from sys.system_columns 
select * from sys.system_objects 
select * from sys.system_parameters 
select * from sys.system_sql_modules 
select * from sys.system_views 
select * from sys.table_types 
select * from sys.tables 
select * from sys.trigger_event_types 
select * from sys.trigger_events 
select * from sys.triggers 
select * from sys.views 

--信息架构视图 (Transact-SQL)
SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, COLUMN_DEFAULT
FROM PersonalCRM.INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = N'ProjectList';
GO

SELECT * FROM INFORMATION_SCHEMA.CHECK_CONSTRAINTS
SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
SELECT * FROM INFORMATION_SCHEMA.COLUMN_DOMAIN_USAGE
SELECT * FROM INFORMATION_SCHEMA.ROUTINES
SELECT * FROM INFORMATION_SCHEMA.COLUMN_PRIVILEGES
SELECT * FROM INFORMATION_SCHEMA.ROUTINE_COLUMNS
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
SELECT * FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE
SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
SELECT * FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE
SELECT * FROM INFORMATION_SCHEMA.TABLE_PRIVILEGES
SELECT * FROM INFORMATION_SCHEMA.DOMAIN_CONSTRAINTS
SELECT * FROM INFORMATION_SCHEMA.TABLES
SELECT * FROM INFORMATION_SCHEMA.DOMAINS
SELECT * FROM INFORMATION_SCHEMA.VIEW_COLUMN_USAGE
SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
SELECT * FROM INFORMATION_SCHEMA.VIEW_TABLE_USAGE
SELECT * FROM INFORMATION_SCHEMA.PARAMETERS
SELECT * FROM INFORMATION_SCHEMA.VIEWS
--兼容性视图 (Transact-SQL)
SELECT * FROM sys.sysaltfiles 
SELECT * FROM sys.syscacheobjects 
SELECT * FROM sys.syscharsets 
SELECT * FROM sys.syscolumns 
SELECT * FROM sys.syscomments 
SELECT * FROM sp_configure 
SELECT * FROM sys.sysconstraints 
SELECT * FROM sys.syscurconfigs 
SELECT * FROM sys.sysdatabases 
SELECT * FROM sys.sysdepends 
SELECT * FROM sys.sysdevices 
SELECT * FROM sys.sysfilegroups 
SELECT * FROM sys.sysfiles 
SELECT * FROM sys.sysforeignkeys 
SELECT * FROM sys.sysfulltextcatalogs 
SELECT * FROM sys.sysindexes 
SELECT * FROM sys.sysindexkeys 
SELECT * FROM sys.syslanguages 
SELECT * FROM sys.syslockinfo 
SELECT * FROM sys.syslogins 
SELECT * FROM sys.sysmembers 
SELECT * FROM sys.sysmessages 
SELECT * FROM sys.sysobjects 
SELECT * FROM sys.sysoledbusers 
SELECT * FROM sys.sysperfinfo 
SELECT * FROM sys.syspermissions 
SELECT * FROM sys.sysprocesses 
SELECT * FROM sys.sysprotects 
SELECT * FROM sys.sysreferences 
SELECT * FROM sys.sysremotelogins 
SELECT * FROM sys.sysservers 
SELECT * FROM sys.systypes 
SELECT * FROM sys.sysusers 

--2005
--https://technet.microsoft.com/zh-cn/library/ms177862(v=sql.90).aspx
--系统视图 (Transact-SQL)

SELECT * FROM sys.schemas

--目录视图 (Transact-SQL)
--对象目录视图 (Transact-SQL)
SELECT * FROM sys.allocation_units 
SELECT * FROM sys.assembly_modules 
SELECT * FROM sys.check_constraints 
SELECT * FROM sys.columns 
SELECT * FROM sys.computed_columns 
SELECT * FROM sys.default_constraints 
SELECT * FROM sys.events 
SELECT * FROM sys.event_notifications 
SELECT * FROM sys.event_notification_event_types 
SELECT * FROM sys.extended_procedures 
SELECT * FROM sys.foreign_keys 
SELECT * FROM sys.foreign_key_columns 
SELECT * FROM sys.fulltext_indexes 
SELECT * FROM sys.fulltext_index_columns 
SELECT * FROM sys.identity_columns 
SELECT * FROM sys.indexes 
SELECT * FROM sys.index_columns 
SELECT * FROM sys.internal_tables 
SELECT * FROM sys.key_constraints 
SELECT * FROM sys.module_assembly_usages 
SELECT * FROM sys.numbered_procedures 
SELECT * FROM sys.numbered_procedure_parameters 
SELECT * FROM sys.objects 
SELECT * FROM sys.parameters 
SELECT * FROM sys.partitions 
SELECT * FROM sys.plan_guides
SELECT * FROM sys.procedures 
SELECT * FROM sys.server_assembly_modules 
SELECT * FROM sys.server_events 
SELECT * FROM sys.server_event_notifications 
SELECT * FROM sys.server_sql_modules
SELECT * FROM sys.server_triggers
SELECT * FROM sys.server_trigger_events
SELECT * FROM sys.service_queues 
SELECT * FROM sys.sql_dependencies 
SELECT * FROM sys.sql_modules 
SELECT * FROM sys.stats 
SELECT * FROM sys.stats_columns 
SELECT * FROM sys.synonyms 
SELECT * FROM sys.tables 
SELECT * FROM sys.triggers 
SELECT * FROM sys.trigger_events 
SELECT * FROM sys.views 
--数据空间目录视图和全文目录视图 (Transact-SQL)
SELECT * FROM sys.data_spaces 
SELECT * FROM sys.destination_data_spaces 
SELECT * FROM sys.filegroups 
SELECT * FROM sys.fulltext_catalogs 
SELECT * FROM sys.fulltext_document_types
SELECT * FROM sys.fulltext_index_catalog_usages
SELECT * FROM sys.partition_schemes 
--数据库和文件目录视图 (Transact-SQL)
SELECT * FROM sys.backup_devices 
SELECT * FROM sys.databases 
SELECT * FROM sys.database_files 
SELECT * FROM sys.database_mirroring 
SELECT * FROM sys.database_recovery_status 
SELECT * FROM sys.master_files 
--CLR 程序集目录视图 (Transact-SQL)
SELECT * FROM sys.assemblies 
SELECT * FROM sys.assembly_files 
SELECT * FROM sys.assembly_references 
--分区函数目录视图 (Transact-SQL)

SELECT * FROM sys.partition_functions 
SELECT * FROM sys.partition_parameters 
SELECT * FROM sys.partition_range_values 
--标量类型目录视图 (Transact-SQL)
SELECT * FROM sys.assembly_types
SELECT * FROM sys.types
SELECT * FROM sys.type_assembly_usages
SELECT * FROM sys.column_type_usages
SELECT * FROM sys.parameter_type_usages
--安全性目录视图 (Transact-SQL)
SELECT * FROM sys.asymmetric_keys 
SELECT * FROM sys.certificates 
SELECT * FROM sys.credentials 
SELECT * FROM sys.crypt_properties 
SELECT * FROM sys.database_permissions 
SELECT * FROM sys.database_principals 
SELECT * FROM sys.database_role_members 
SELECT * FROM sys.key_encryptions 
SELECT * FROM sys.master_key_passwords 
SELECT * FROM sys.openkeys 
SELECT * FROM sys.securable_classes 
SELECT * FROM sys.server_permissions 
SELECT * FROM sys.server_principals 
SELECT * FROM sys.server_role_members 
SELECT * FROM sys.sql_logins 
SELECT * FROM sys.symmetric_keys 
SELECT * FROM sys.system_components_surface_area_configuration 
--服务器范围内的配置目录视图 (Transact-SQL)
SELECT * FROM sys.configurations 
SELECT * FROM sys.fulltext_languages 
SELECT * FROM sys.traces 
SELECT * FROM sys.trace_categories 
SELECT * FROM sys.trace_columns 
SELECT * FROM sys.trace_events 
SELECT * FROM sys.trace_event_bindings 
SELECT * FROM sys.trace_subclass_values 

--架构目录视图 (Transact-SQL)
SELECT * FROM sys.schemas 

--XML 架构(XML 类型系统)目录视图 (Transact-SQL)
SELECT * FROM sys.column_xml_schema_collection_usages 
SELECT * FROM sys.parameter_xml_schema_collection_usages 
SELECT * FROM sys.xml_schema_attributes 
SELECT * FROM sys.xml_schema_component_placements 
SELECT * FROM sys.xml_schema_components 
SELECT * FROM sys.xml_schema_elements 
SELECT * FROM sys.xml_schema_facets 
SELECT * FROM sys.xml_indexes 
SELECT * FROM sys.xml_schema_model_groups 
SELECT * FROM sys.xml_schema_collections 
SELECT * FROM sys.xml_schema_namespaces 
SELECT * FROM sys.xml_schema_types 
SELECT * FROM sys.xml_schema_wildcard_namespaces 
SELECT * FROM sys.xml_schema_wildcards 

--数据库镜像见证服务器目录视图 (Transact-SQL)

SELECT * FROM  sys.database_mirroring_witne
SELECT * FROM sys.database_mirroring_witnesses
SELECT * FROM sys.database_mirroring_endpoints
--端点目录视图 (Transact-SQL)
SELECT * FROM sys.database_mirroring_endpoints 
SELECT * FROM sys.endpoints 
SELECT * FROM sys.endpoint_webmethods 
SELECT * FROM sys.http_endpoints 
SELECT * FROM sys.service_broker_endpoints 
SELECT * FROM sys.soap_endpoints 
SELECT * FROM sys.tcp_endpoints 
SELECT * FROM sys.via_endpoints 
---扩展属性目录视图 (Transact-SQL)

SELECT * FROM sys.extended_properties 


--链接服务器目录视图 (Transact-SQL)
SELECT * FROM sys.linked_logins 
SELECT * FROM sys.remote_logins 
SELECT * FROM sys.servers 

--(错误)消息目录视图 (Transact-SQL)

SELECT * FROM sys.messages

--Service Broker 目录视图 (Transact-SQL)
SELECT * FROM sys.conversation_endpoints 
SELECT * FROM sys.conversation_groups 
SELECT * FROM sys.message_type_xml_schema_collection_usages 
SELECT * FROM sys.remote_service_bindings 
SELECT * FROM sys.routes 
SELECT * FROM sys.service_contracts 
SELECT * FROM sys.service_contract_message_usages 
SELECT * FROM sys.service_contract_usages 
SELECT * FROM sys.service_message_types 
SELECT * FROM sys.service_queue_usages 
SELECT * FROM sys.services 
SELECT * FROM sys.transmission_queue 



--兼容性视图 (Transact-SQL)

SELECT * FROM sys.sysaltfiles 
SELECT * FROM sys.syscacheobjects 
SELECT * FROM sys.syscharsets 
SELECT * FROM sys.syscolumns 
SELECT * FROM sys.syscomments 
SELECT * FROM sys.sysconfigures 
SELECT * FROM sys.sysconstraints 
SELECT * FROM sys.syscurconfigs 
SELECT * FROM sys.sysdatabases 
SELECT * FROM sys.sysdepends 
SELECT * FROM sys.sysdevices 
SELECT * FROM sys.sysfilegroups 
SELECT * FROM sys.sysfiles 
SELECT * FROM sys.sysforeignkeys 
SELECT * FROM sys.sysfulltextcatalogs 
SELECT * FROM sys.sysindexes 
SELECT * FROM sys.sysindexkeys 
SELECT * FROM sys.syslanguages 
SELECT * FROM sys.syslockinfo 
SELECT * FROM sys.syslogins 
SELECT * FROM sys.sysmembers 
SELECT * FROM sys.sysmessages 
SELECT * FROM sys.sysobjects 
SELECT * FROM sys.sysperfinfo 
SELECT * FROM sys.syspermissions 
SELECT * FROM sys.sysprocesses 
SELECT * FROM sys.sysprotects 
SELECT * FROM sys.sysreferences 
SELECT * FROM sys.sysremotelogins 
SELECT * FROM sys.sysservers 
SELECT * FROM sys.systypes 
SELECT * FROM sys.sysusers 


--数据库邮件视图 (Transact-SQL)
sysmail_allitems 
sysmail_event_log 
sysmail_faileditems 
sysmail_mailattachments 
sysmail_sentitems 
sysmail_unsentitems 


--动态管理视图和函数
--信息架构视图 (Transact-SQL)
SELECT * FROM INFORMATION_SCHEMA.CHECK_CONSTRAINTS 
SELECT * FROM INFORMATION_SCHEMA.COLUMN_DOMAIN_USAGE 
SELECT * FROM INFORMATION_SCHEMA.COLUMN_PRIVILEGES 
SELECT * FROM INFORMATION_SCHEMA.COLUMNS 
SELECT * FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE 
SELECT * FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE 
SELECT * FROM INFORMATION_SCHEMA.DOMAIN_CONSTRAINTS 
SELECT * FROM INFORMATION_SCHEMA.DOMAINS 
SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE  --主键
SELECT * FROM INFORMATION_SCHEMA.PARAMETERS 
SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS --外鍵
SELECT * FROM INFORMATION_SCHEMA.ROUTINE_COLUMNS 
SELECT * FROM INFORMATION_SCHEMA.ROUTINES 
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA 
SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS 
SELECT * FROM INFORMATION_SCHEMA.TABLE_PRIVILEGES 
SELECT * FROM INFORMATION_SCHEMA.TABLES 
SELECT * FROM INFORMATION_SCHEMA.VIEW_COLUMN_USAGE 
SELECT * FROM INFORMATION_SCHEMA.VIEW_TABLE_USAGE 
SELECT * FROM INFORMATION_SCHEMA.VIEWS 

--复制视图 (Transact-SQL)
IHextendedArticleView 
IHextendedSubscriptionView 
IHsyscolumns 
MSdatatype_mappings 
MSdistribution_status 
sysarticlecolumns--(系统视图)
sysarticles--(系统视图)
sysdatatypemappings 
sysextendedarticlesview 
sysmergeextendedarticlesview 
sysmergepartitioninfoview 
syspublications--(系统视图)
syssubscriptions--(系统视图)
--Notification Services 视图

相关实践学习
使用SQL语句管理索引
本次实验主要介绍如何在RDS-SQLServer数据库中,使用SQL语句管理索引。
SQL Server on Linux入门教程
SQL Server数据库一直只提供Windows下的版本。2016年微软宣布推出可运行在Linux系统下的SQL Server数据库,该版本目前还是早期预览版本。本课程主要介绍SQLServer On Linux的基本知识。 相关的阿里云产品:云数据库RDS SQL Server版 RDS SQL Server不仅拥有高可用架构和任意时间点的数据恢复功能,强力支撑各种企业应用,同时也包含了微软的License费用,减少额外支出。 了解产品详情: https://www.aliyun.com/product/rds/sqlserver
目录
相关文章
|
6月前
|
SQL 存储 关系型数据库
关系型数据库SQLserver基本 SQL 操作
【7月更文挑战第28天】
60 4
|
3月前
|
SQL 数据库
执行 Transact-SQL 语句或批处理时发生了异常。 (Microsoft.SqlServer.ConnectionInfo)之解决方案
执行 Transact-SQL 语句或批处理时发生了异常。 (Microsoft.SqlServer.ConnectionInfo)之解决方案
458 0
|
4月前
|
关系型数据库 MySQL 网络安全
5-10Can't connect to MySQL server on 'sh-cynosl-grp-fcs50xoa.sql.tencentcdb.com' (110)")
5-10Can't connect to MySQL server on 'sh-cynosl-grp-fcs50xoa.sql.tencentcdb.com' (110)")
|
5月前
|
SQL 运维 监控
SQL Server 运维常用sql语句(二)
SQL Server 运维常用sql语句(二)
44 3
|
5月前
|
SQL XML 运维
SQL Server 运维常用sql语句(三)
SQL Server 运维常用sql语句(三)
40 1
|
5月前
|
SQL 关系型数据库 MySQL
SQL数据库和 SQLserver数据库
【8月更文挑战第19天】SQL数据库和 SQLserver数据库
70 2
|
5月前
|
Java 应用服务中间件 Maven
从零到英雄:一步步构建你的首个 JSF 应用程序,揭开 JavaServer Faces 的神秘面纱
【8月更文挑战第31天】JavaServer Faces (JSF) 是一种强大的 Java EE 标准,用于构建企业级 Web 应用。它提供了丰富的组件库和声明式页面描述语言 Facelets,便于开发者快速开发功能完善且易于维护的 Web 应用。本文将指导你从零开始构建一个简单的 JSF 应用,包括环境搭建、依赖配置、Managed Bean 编写及 Facelets 页面设计。
111 0
|
5月前
|
SQL 关系型数据库 MySQL
【超全整理】SQL日期与时间函数大汇总会:MySQL与SQL Server双轨对比教学,助你轻松搞定时间数据处理难题!
【8月更文挑战第31天】本文介绍了在不同SQL数据库系统(如MySQL、SQL Server、Oracle)中常用的日期与时间函数,包括DATE、NOW()、EXTRACT()、DATE_ADD()、TIMESTAMPDIFF()及日期格式化等,并提供了具体示例。通过对比这些函数在各系统中的使用方法,帮助开发者更高效地处理日期时间数据,满足多种应用场景需求。
588 0
|
5月前
|
SQL 关系型数据库 MySQL
SQL Server、MySQL、PostgreSQL:主流数据库SQL语法异同比较——深入探讨数据类型、分页查询、表创建与数据插入、函数和索引等关键语法差异,为跨数据库开发提供实用指导
【8月更文挑战第31天】SQL Server、MySQL和PostgreSQL是当今最流行的关系型数据库管理系统,均使用SQL作为查询语言,但在语法和功能实现上存在差异。本文将比较它们在数据类型、分页查询、创建和插入数据以及函数和索引等方面的异同,帮助开发者更好地理解和使用这些数据库。尽管它们共用SQL语言,但每个系统都有独特的语法规则,了解这些差异有助于提升开发效率和项目成功率。
562 0
|
5月前
|
SQL 安全 Java
驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client
驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client
556 0