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$]
原文:https://www.cnblogs.com/lonelyxmas/p/12020025.html