SQL Server元数据查询
1、查询触发器的信息
-
--查询触发器的信息
-
select name, --触发器名称
-
(select name from sys.objects
-
where object_id = t.parent_id)as tb_name --表的名称
-
from sys.triggers t
-
-
-
--查询触发器的代码
-
select *
-
from sys.sql_modules
-
where object_id = object_id('触发器的名称')
2、大综合
-
--目录视图,或者是系统视图
-
select *
-
from sys.objects
-
-
-
-
-
select *
-
from sys.views
-
-
-
select *
-
from sys.procedures
-
-
select *
-
from sys.triggers
-
-
-
-
-
-
--表
-
select *
-
from sys.tables
-
-
--列
-
select *
-
from sys.columns
-
-
-
--列的类型
-
select *
-
from sys.types
-
-
-
--主键约束
-
select *
-
from sys.key_constraints
-
-
-
--外键约束
-
select *
-
from sys.foreign_keys
-
-
-
select*
-
from sys.foreign_key_columns
-
-
-
--default约束
-
select*
-
from sys.default_constraints
-
-
-
--check约束
-
select *
-
from sys.check_constraints
-
-
-
--identity列
-
select*
-
from sys.identity_columns
-
-
-
--计算列
-
select *
-
from sys.computed_columns
-
-
-
-
-
--索引
-
select *
-
from sys.indexes
-
-
-
--索引列
-
select *
-
from sys.index_columns
-
-
-
--索引的使用统计
-
select *
-
from sys.dm_db_index_usage_stats
-
-
-
--索引的操作统计
-
select *
-
from sys.dm_db_index_operational_stats(
-
DB_ID('数据库名'),
-
OBJECT_ID('db.dbo.object'),
-
null,
-
null,
-
null)
-
-
-
--索引的物理统计
-
select *
-
from sys.dm_db_index_physical_stats(
-
DB_ID('数据库名'),
-
OBJECT_ID('db.dbo.object'),
-
null,
-
null)
-
-
-
-
--动态执行的信息
-
select *
-
from sys.dm_exec_sessions
-
-
select*
-
from sys.dm_exec_connections
-
-
select*
-
from sys.dm_exec_requests
-
-
select *
-
from sys.dm_exec_query_stats
-
-
select *
-
from sys.dm_exec_sql_text('sql_handle')
-
-
-
select*
-
from sys.dm_exec_query_plan('query_plan')
-
-
select *
-
from sys.dm_exec_plan_attributes('query_plan')
-
-
-
-
--sql缓存计划
-
select *
-
from sys.dm_exec_cached_plans
-
-
-
--通过指定计划句柄或 SQL 句柄从计划缓存中删除特定计划
-
dbcc freeproccache
-
-
-
--刷新针对 Microsoft SQL Server 实例执行的分布式查询所使用的分布式查询连接缓存
-
dbcc freesessioncache
-
-
-
--可以使用此命令从所有缓存中或者从指定的资源调控器池缓存中手动删除未使用的条目
-
dbcc freesystemcache('all')
-
-
-
-
-
--database缓存
-
select *
-
from sys.dm_os_buffer_descriptors
-
-
-
--清空database缓存
-
dbcc dropcleanbuffers
-
-
--内存分配
-
select *
-
from sys.dm_os_memory_clerks
-
-
-
-
--事务
-
select *
-
from sys.dm_tran_session_transactions
-
-
--会话的事务
-
select *
-
from sys.dm_tran_active_transactions
-
-
--数据库事务
-
select *
-
from sys.dm_tran_database_transactions
-
-
-
--锁
-
select *
-
from sys.dm_tran_locks
-
-
-
select *
-
from sys.dm_tran_current_transaction
-
-
-
-
--等待
-
select *
-
from sys.dm_os_wait_stats
-
-
-
--正在等待的task
-
select *
-
from sys.dm_os_waiting_tasks
-
-
-
-
--tempdb的空间使用情况
-
select *
-
from sys.dm_db_file_space_usage
-
-
select *
-
from sys.dm_db_session_space_usage
-
-
select *
-
from sys.dm_db_task_space_usage
-
-
-
-
--存储
-
select *
-
from sys.databases
-
-
select *
-
from sys.database_files
-
-
select *
-
from sys.master_files
-
-
-
-
select *
-
from sys.dm_io_virtual_file_stats(
-
DB_ID(),
-
1
-
);
-
-
select *
-
from sys.dm_io_pending_io_requests
-
-
-
--
-
select work_queue_count,
-
pending_disk_io_count,
-
failed_to_create_worker,
-
*
-
from sys.dm_os_schedulers
-
-
-
-
-
--备份
-
backup database master
-
to disk = 'c:\master.bak'
-
with format
-
-
-
--还原
-
--若要还原 master 数据库,服务器必须以单用户模式运行。
-
--有关在单用户模式下启动的信息,请参阅联机丛书中的"如何启动 SQL Server 实例(sqlservr.exe)"。
-
restore database master
-
from disk = 'c:\master.bak'
-
with replace --替换现有数据库
-
-
-
-
-
--详细的io开销
-
set statistics io on
-
-
-
--详细的cpu开销
-
set statistics time on
-
-
-
--实际的文本格式的,执行计划
-
set statistics profile on
-
-
-
-
--DBCC数据库命令控制台
-
dbcc checkdb('master')
-
-
-
-
-
--远程数据查询
-
-
--从sql server中查询
-
SELECT *
-
FROM
-
OPENROWSET('SQLOLEDB',
-
'server=192.168.1.16,1433;uid=sa;pwd=winchannel', --字符串
-
henkel.dbo.mdm_store) --直接写表的名称
-
-
-
--从Excel中查询,通过引用4.0的库
-
select *
-
from
-
openrowset('microsoft.jet.oledb.4.0',
-
'Excel 5.0;database=c:\t2.xls',
-
-
sheet1$)
-
-
-
--excel,12.0的库
-
select *
-
from
-
opendatasource('microsoft.ace.oledb.12.0',
-
'data source=c:\t.xls;Extended Properties=Excel 12.0')...[sheet1$]
SQL Server元数据查询的更多相关文章
- 人人都是 DBA(II)SQL Server 元数据
SQL Server 中维护了一组表用于存储 SQL Server 中所有的对象.数据类型.约束条件.配置选项.可用资源等信息,这些信息称为元数据信息(Metadata),而这些表称为系统基础表(Sy ...
- 探索SQL Server元数据(一)
简介 在数据库中,我们除了存储数据外,还存储了大量的元数据.它们主要的作用就是描述数据库怎么建立.配置.以及各种对象的属性等.本篇简单介绍如何使用和查询元数据,如何更有效的管理SQLServer 数据 ...
- SQL Server 元数据分类
SQL Server 中维护了一组表用于存储 SQL Server 中所有的对象.数据类型.约束条件.配置选项.可用资源等信息,这些信息称为元数据信息(Metadata),而这些表称为系统基础表(Sy ...
- Sql Server中查询今天、昨天、本周、上周、本月、上月数据
Sql Server中查询今天.昨天.本周.上周.本月.上月数据 在做Sql Server开发的时候有时需要获取表中今天.昨天.本周.上周.本月.上月等数据,这时候就需要使用DATEDIFF()函数及 ...
- Sql Server参数化查询之where in和like实现详解
where in 的参数化查询实现 首先说一下我们常用的办法,直接拼SQL实现,一般情况下都能满足需要 string userIds = "1,2,3,4"; using (Sql ...
- 【转】Sql Server参数化查询之where in和like实现之xml和DataTable传参
转载至: http://www.cnblogs.com/lzrabbit/archive/2012/04/29/2475427.html 在上一篇Sql Server参数化查询之where in和li ...
- 【转】Sql Server参数化查询之where in和like实现详解
转载至:http://www.cnblogs.com/lzrabbit/archive/2012/04/22/2465313.html 文章导读 拼SQL实现where in查询 使用CHARINDE ...
- SQL Server中查询用户的对象权限和角色的方法
--SQL Server中查询用户的对象权限和角色的方法 -- 查询用户的object权限 exec sp_helprotect NULL, 'sa' -- 查询用户拥有的role exec sp_h ...
- 优化SQL Server数据库查询方法
SQL Server数据库查询速度慢的原因有很多,常见的有以下几种: 1.没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷) 2.I/O吞吐量小,形成了瓶颈效应. 3.没有创建计算列 ...
随机推荐
- 解决request.getSession().getServletContext().getRealPath("/")为null问题
今天把程序部署到服务器,发现异常,FileNotFound异常,很快定位到getServletContext().getRealPath("/");返回空的问题.这个问题通常是传递 ...
- OpenGL ES: (5) OpenGL的基本概念、OpenGL ES 在屏幕产生图片的过程、OpenGL管线(pipeline)
一. OpenGL的基本概念 OpenGL 的结构可以从逻辑上划分为下面 3 个部分: 图元(Primitives) 缓冲区(Buffers) 光栅化(Rasterize) 图元(Primitives ...
- Flutter -------- 新手 WanAndroid 项目练习
一个简单Flutter项目wanandroid,先前用Kotlin来开发过,适合新手练习. 用到的库 包含功能: http+数据解析 网络请求数据列表展示 Banner轮播 WebView跳转详情 D ...
- 下周文件ie 谷歌兼容性处理
https://blog.csdn.net/u014628388/article/details/81738704 问题描述window.URL.createObjectURL()可以直接生成blob ...
- 人性化的HTTP命令行工具——HTTPie
Httpie 是什么 Httpie (aych-tee-tee-pie)是一个 HTTP 的命令行客户端.其目标是让 CLI 和 web 服务之间的交互尽可能的人性化.你可以用它很方便的用 http ...
- 1264 - Out of range value for column
现象:新建数据库,字段类型是tinyint,然后插入数据,数值为128,报标题错误 原因:如果在新建数据库的时候没有指定为unsigned,那么就是有符号的,所以tinyint的范围是-128~127 ...
- Linux系统调优——磁盘I/O(三)
(1).查看I/O运行状态相关工具 1)查看文件系统块大小 对于ext4文件系统,查看文件系统块大小 [root@CentOS6 ~]# tune2fs -l /dev/sda1 | grep siz ...
- 配置ssh免密,仍需要密码
配置ssh免密码登录后,仍提示输入密码 解决方法: 首先我们就要去查看系统的日志文件 tail /var/log/secure -n 20 Authentication refused: bad ...
- hadoop(四)MapReduce
如果将 Hadoop 比做一头大象,那么 MapReduce 就是那头大象的电脑.MapReduce 是 Hadoop 核心编程模型.在 Hadoop 中,数据处理核心就是 MapReduce 程序设 ...
- 【Tools】三款笔记本电脑硬件检测工具-官网下载
一.CPU-Z 下载地址: https://www.cpuid.com/softwares/cpu-z.html 描述: CPU-Z已经是大名鼎鼎了.这里就不多说了. 二.Cinebench 下 ...
