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.没有创建计算列 ...
随机推荐
- [原][资料整理][osg]osgDB文件读取插件,工作机制,支持格式,自定义插件
参考: osgPlugins相关 osg读取文件的原理(插件工作机制) 当使用osgDB读取文件时,会自动根据文件的扩展名来到插件目录中寻找相应的插件,来实现. 比如: osgviewer cow.o ...
- flutter State管理
import 'package:flutter/material.dart'; import 'package:scoped_model/scoped_model.dart'; class State ...
- shell编程系列17--文本处理三剑客之awk动作中的表达式用法
shell编程系列17--文本处理三剑客之awk动作中的表达式用法 awk动作表达式中的算数运算符 awk动作中的表达式用法总结: 运算符 含义 + 加 - 减 * 乘 / 除 % 模 ^或** 乘方 ...
- django实战总结2
https://www.jianshu.com/p/9b3bfe934511 https://www.cnblogs.com/1Q84mi/p/xadmin002.html https://blog. ...
- Python3基础 只有int类型,没有long类型
Python : 3.7.3 OS : Ubuntu 18.04.2 LTS IDE : pycharm-community-2019.1.3 ...
- Oracle中RAISE异常
转: Oracle中RAISE异常 由三种方式抛出异常 1. 通过PL/SQL运行时引擎 2. 使用RAISE语句 3. 调用RAISE_APPLICATION_ERROR存储过程 当数据库或PL/S ...
- RabbitMQ 入门教程(PHP版) 第一部分:Hello World
abbitMQ是一个消息代理.它的核心原理非常简单:接收和发送消息.你可以把它想像成一个邮局:你把信件放入邮箱,邮递员就会把信件投递到你的收件人处.在这个比喻中,RabbitMQ是一个邮箱.邮局.邮递 ...
- PDMan 数据库建模工具
PDMan是一款开源免费的数据库模型建模工具,支持Windows,Mac,Linux等操作系统,是PowerDesigner之外,更好的免费的替代方案.他具有颜值高,使用简单的特点.包含数据库建模,灵 ...
- 了解美杜莎(Medusa)
(1).美杜莎介绍 Medusa(美杜莎)是一个速度快,支持大规模并行,模块化的暴力破解工具.可以同时对多个主机,用户或密码执行强力测试.Medusa和hydra一样,同样属于在线密码破解工具.Med ...
- SQL语句 update 字段=字段+字符串 拼接
update user_info set user_name = concat(user_name,'呵呵呵') where user_name = '哈哈哈';