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.没有创建计算列 ...
随机推荐
- Jenkins定时任务的配置
在任务配置中,在 构建触发器(Build Triggers)-->勾选"定时构建"-->在输入框中配置触发时间表达式 以上配置,类似cron表达式,表示在5月27日23 ...
- pip错误 ImportError: No module named 'pip_internal'
ubuntu16.04 - wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate sudo python get-pip.p ...
- [Eclipse]已经写好的代码怎样切换为unix下的换行符?
问题:使用eclise提交文件到github,每行文件后面都有^M字符 切换换行符的显示格式, 但是这样只能对新文件起作用,修改旧文件:
- ISO/IEC 9899:2011 条款6.7.2——类型说明符
6.7.2 类型说明符 语法 1.type-specifier: void char short int long float double signed unsigned _Bool _Comple ...
- 使用java移位运算符进行转化
import java.util.Scanner; public class Main { public static void main(String[] args) { new Main().sy ...
- k8s、jenkins集成
参考连接 http://www.uml.org.cn/jchgj/201804252.asp https://huanqiang.wang/2018/03/30/Jenkins-Gitlab-Kube ...
- curl命令测试网络请求中DNS解析、响应时间
https://blog.csdn.net/dreamer2020/article/details/78152576
- C# 获取或设置指定 config 文件的值
ExeConfigurationFileMap 这个类提供了修改.获取指定 config 的功能:新建一个 ExeConfigurationFileMap 的实例 ecf :并设置 ExeConfig ...
- 使用mousedown、mousemove、mouseup实现拖拽效果
如何实现一个元素的拖拽效果,使用原生的js实现,习惯了jquery的同学们,你们自己写了吗?N久使用mvvm框架,不写jquery的东西,感觉自己完全不会了. 话不多说,直接上code.本例子以简单的 ...
- Nginx之开启压缩
参考:https://blog.csdn.net/php12345679/article/details/80843939 https://blog.csdn.net/pf1234321/articl ...
