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.没有创建计算列 ...
随机推荐
- 多层nginx中的压缩问题 api接口>1M数据的返回浏览器 网关
基础 前端异步请求,局部刷新,加大最大等待时间 nginx开启压缩 进阶 多级nginx的压缩 实践测试: 每级都要开启压缩 gizp on: 最外层开启,但最内层没有开启 最外层没有开启 最外层.最 ...
- Vue-CLI 标准开发工具-快速准备环境和创建项目
https://cli.vuejs.org/zh/ 淘宝镜像安装: npm install -g cnpm --registry=https://registry.npm.taobao.org 2.x ...
- Js-事件分发与DOM事件流
原文地址:https://www.jianshu.com/p/dc1520327022 Js事件分发与DOM事件流 对JavaScript分发事件不熟悉,网上查阅相关资料整理后,记录一下对Javasc ...
- AI学习网址记录
https://ai.yanxishe.com/ https://ai.yanxishe.com/page/blogDetail/14365 GAN网络 对抗式生成网络-图像超分辨及图像修复 完全可见 ...
- TypeScript封装统一操作Mysql Mongodb Mssql的底层类库demo
/* 功能:定义一个操作数据库的库 支持 Mysql Mssql MongoDb 要求1:Mysql MsSql MongoDb功能一样 都有 add update delete get方法 注意:约 ...
- centos6环境远程执行shell脚本报错not a valid identifier的问题处理
# 通过jenkins的apache用户rsync同步php代码到远程服务器报错如下: SSH: EXEC: STDOUT/STDERR from command [/bin/sh /usr/loca ...
- python的url正则表达式
网上有很多的正则表达式版本,大部分都不好使,下面这个比较好用: http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F] ...
- osg::Node clone
深度拷贝 node.clone(osg::CopyOp::DEEP_COPY_ALL) osg::ref_ptr<osg::Node> deepnode = (osg::Node *)( ...
- this page isn't working (ERR_EMPTY_RESPONSE)
特定情况触发了PHP的Call to undefined function(函数不存在)的Fatal error(致命错误),PHP异常终止执行,Apache收到PHP的异常信号时,认为PHP处理请求 ...
- 原生JavaScript常用本地浏览器存储方法一(方法类型)
有时需要将网页中的一些数据保存在浏览器端.好处就是当下次访问页面时,直接就可以从本地读取数据,不需要再次向服务器请求数据.目前常用的有以下几种方法: 1.cookie cookie会随着每次HTTP请 ...
