sql commands
1,DBCC SQLPERF(logspace)
https://msdn.microsoft.com/en-us/library/ms189768.aspx
2,
1, LOGINFO(''HAHA3'')
2,
CREATE TABLE #tracestatus ( RecoceryUntitID INT, FileID INT, FileSize INT, StartOffset INT, FSeqNo INT, Status INT, Parity INT, CreateLSN VARCHAR(100) )
-- Execute the command, putting the results in the table INSERT INTO #tracestatus EXEC ('DBCC LOGINFO(''HAHA3'')')
-- Display the results SELECT sum(FileSize) FROM #tracestatus GO
3,
CREATE DATABASE [DBMaint2008]; GO USE [DBMaint2008]; GO )); GO -- Take a full backup BACKUP DATABASE [DBMaint2008] TO DISK = N'D:\SQLskills\DemoBackups\DBMaint_Full.bck' WITH INIT; GO -- Insert some rows INSERT INTO [TestTable] VALUES ('Transaction 1'); INSERT INTO [TestTable] VALUES ('Transaction 2'); GO -- Take a log backup BACKUP LOG [DBMaint2008] TO DISK = N'D:\SQLskills\DemoBackups\DBMaint_Log1.bck' WITH INIT; GO -- Insert some more rows INSERT INTO [TestTable] VALUES ('Transaction 3'); INSERT INTO [TestTable] VALUES ('Transaction 4'); RESTORE HEADERONLY FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\CVS.bak' WITH NOUNLOAD; GO SELECT name, physical_name AS CurrentLocation, state_desc FROM sys.master_files WHERE database_id = DB_ID(N'CVS'); , NORECOVERY, MOVE N ; GO RESTORE DATABASE [CVS] WITH RECOVERY; GO
4,HIGH CPU
use tempdb drop table query_snapshot1 drop table query_snapshot2 select * into query_snapshot1 from sys.dm_exec_query_stats waitfor delay '00:01:00' select * into query_snapshot2 from sys.dm_exec_query_stats select top 20 SUBSTRING(text, (c.statement_start_offset/2)+1, ((CASE c.statement_end_offset WHEN -1 THEN DATALENGTH(text) ELSE c.statement_end_offset END - c.statement_start_offset)/2) + 1) AS statement_text, c.diff_cpu, objectid, plan_handle from ( select a.sql_handle, b.total_worker_time- a.total_worker_time diff_cpu, b.plan_handle, b.statement_start_offset, b.statement_end_offset from tempdb..query_snapshot1 a, tempdb..query_snapshot2 b where a.sql_handle = b.sql_handle and a.statement_start_offset = b.statement_start_offset and a.statement_end_offset = b.statement_end_offset) c cross apply sys.dm_exec_sql_text(c.sql_handle) order by c.diff_cpu desc |
Query 1
select * from sys.dm_exec_query_plan(0x060001001C70C614506F946B0400000001000000000000000000000000000000000000000000000000000000) |
Query 2
select TOP 10 t.text,mg.cpu_time,mg.session_id, qp.query_plan,mg.last_wait_type,mg.percent_complete,
mg.command,mg.start_time,mg.reads,mg.writes ,mg.wait_time,mg.wait_type,mg.wait_resource
from sys.dm_exec_requests mg
CROSS APPLY sys.dm_exec_query_plan(mg.plan_handle) AS qp
CROSS APPLY sys.dm_exec_sql_text(mg.sql_handle) AS t
Order by mg.cpu_time desc
5,Repair Database
ALTER DATABASE [CVS] SET EMERGENCY; GO ALTER DATABASE [CVS] SET SINGLE_USER; GO DBCC CHECKDB (N'CVS', REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS, NO_INFOMSGS; GO ALTER DATABASE [CVS] SET Multi_USER; GO other reference http:-backing-up-the-tail-of-the-log/
6,XML
SELECT * FROM ( SELECT ITEMPATH, TIMEEND, TIMESTART,TIMEDATARETRIEVAL, TIMEPROCESSING,TIMERENDERING ,STATUS, ESTIMATEDMEMORYUSAGEKB=ADDITIONALINFO.value('(/ADDITIONALINFO/ESTIMATEDMEMORYUSAGEKB/PROCESSING)[1]', 'INT') FROM [DBO].[EXECUTIONLOG3] ) TMP ORDER BY ESTIMATEDMEMORYUSAGEKB DESC SELECT * FROM ( SELECT ITEMPATH, TIMEEND, TIMESTART,TIMEDATARETRIEVAL, TIMEPROCESSING,TIMERENDERING ,STATUS, SCALABILITYTIME=ADDITIONALINFO.value('(/ADDITIONALINFO/SCALABILITYTIME/PROCESSING)[1]', 'INT') FROM [DBO].[EXECUTIONLOG3] ) TMP ORDER BY SCALABILITYTIME DESC --WHERE SCALABILITYTIME >2 --column name is AdditionalInfo <AdditionalInfo> <ProcessingEngine>2</ProcessingEngine> <ScalabilityTime> <Pagination>0</Pagination> <Processing>0</Processing> </ScalabilityTime> <EstimatedMemoryUsageKB> <Pagination>2</Pagination> <Processing>10</Processing> </EstimatedMemoryUsageKB> <DataExtension> <SQL>2</SQL> </DataExtension> <Connections> <Connection> <ConnectionOpenTime>177</ConnectionOpenTime> <DataSets> <DataSet> <Name>DataSet1</Name> <RowsRead>1</RowsRead> <TotalTimeDataRetrieval>315</TotalTimeDataRetrieval> <ExecuteReaderTime>73</ExecuteReaderTime> </DataSet> </DataSets> </Connection> <Connection> <ConnectionOpenTime>177</ConnectionOpenTime> <DataSets> <DataSet> <Name>DataSet2</Name> <RowsRead>7</RowsRead> <TotalTimeDataRetrieval>284</TotalTimeDataRetrieval> <ExecuteReaderTime>91</ExecuteReaderTime> </DataSet> </DataSets> </Connection> </Connections> </AdditionalInfo>
7,
select spid,status,cmd from sys.sysprocesses where cmd='Backup Database'-- we can see the parallelism and worker threads from sys.sysprocesses, another two threads cannot SELECT * from [sys].[dm_exec_sessions] SELECT * from [sys].[dm_exec_requests]
8, dump files , thread id
select session_id, command, os_thread_id from sys.dm_exec_requests as r join sys.dm_os_workers as w on r.task_address = w.task_address join sys.dm_os_threads as t on t.thread_address = w.thread_address --where session_id =11 order by session_id --dbcc stackdump , ) go dbcc stackdump WAITFOR DELAY '00:01'; dbcc stackdump WAITFOR DELAY '00:01'; dbcc stackdump go , )
) set @databasename='QQQ' select database_name,type , recovery_model,bs.position,bf.backup_set_id,bm.media_set_id,name,logical_name,physical_name,physical_device_name, first_lsn,last_lsn,checkpoint_lsn,database_backup_lsn,backup_start_date,backup_finish_date from [msdb].dbo.backupset bs inner join msdb.dbo.backupfile bf on bs.backup_set_id=bf.backup_set_id inner join msdb.dbo.backupmediafamily bm on bs.media_set_id=bm.media_set_id where database_name=@databasename ORDER BY bs.backup_start_date RESTORE HEADERONLY FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\QQQ.bak' ; RESTORE HEADERONLY FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\QQQLOG.bak' ; RESTORE HEADERONLY FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\QQQLOG2.bak' ; BACKUP DATABASE [QQQ] TO DISK = N'D:\SQLskills\DemoBackups\DBMaint_Full.bck' WITH INIT; GO
query hint
USE [TEST1] GO /****** Object: Table [dbo].[Table_1] Script Date: 2016/6/26 13:54:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Table_1]( [ID] [int] IDENTITY(1,1) NOT NULL, [C1] [nchar](20) NULL, [C2] [nchar](10) NULL, [C3] [nchar](10) NULL, CONSTRAINT [PK_Table_1] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING ON GO /****** Object: Index [NonClusteredIndex-20160626-113649] Script Date: 2016/6/26 13:54:28 ******/ CREATE NONCLUSTERED INDEX [NonClusteredIndex-20160626-113649] ON [dbo].[Table_1] ( [C1] ASC, [C2] ASC, [C3] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO
select top 1 * from [dbo].[Table_1] WITH (INDEX([NonClusteredIndex-20160626-113649])) where c1='111111' and c3='1600000' ORDER by [C2] select top 2 * from [dbo].[Table_1] where c1='111111' and c3='1000000' ORDER by [C2] OPTION (MAXDOP 1)
http://blog.sqlauthority.com/2009/02/08/sql-server-introduction-to-force-index-query-hints-index-hint-part2/
sql commands的更多相关文章
- Oracle - PL/SQL Commands
第一章:日志管理 1.forcing log switches sql> alter system switch logfile; 2.forcing checkpoints sql> a ...
- 常用sql commands以及mysql问题解决日志
mysql workbench常用命令快捷键 ctrl+T ->创建新的sql query tab ctrl+shift+enter->执行当前的sql命令 https://dev.mys ...
- Postgresql Useful SQL/Commands
Update records ' and a.subscriber_id=b.subscriber_id; Connections select count(*) from pg_stat_activ ...
- 【转】PowerShell 连接SQL Server 数据库 - ADO.NET
转至:http://www.pstips.net/connect-sql-database.html PowerShell 通过ADO.NET连接SQL Server数据库,并执行SQL脚本.工作中整 ...
- PL/SQL : Procedural Language / Structual Query Language and it is an exrension to SQL.
SQL is not very flexible and it cannot be made to react differently to differing sutuations easily. ...
- 执行原始的 SQL 查询
The Entity Framework Code First API includes methods that enable you to pass SQL commands directly t ...
- Oracle 通过sql profile为sql语句加hint
sql profile最大的优点是在不修改sql语句和会话执行环境的情况下去优化sql的执行效率,适合无法在应用程序中修改sql时.sql profile最常用方法大概是:--创建产生sql tuni ...
- sql - and - or
sql - and SQL AND links together two or more conditional statements for increased filtering when run ...
- How to Kill All Processes That Have Open Connection in a SQL Server Database[关闭数据库链接 最佳方法] -摘自网络
SQL Server database administrators may frequently need in especially development and test environmen ...
随机推荐
- MapReduce实现TopK的示例
由于开始学习MapReduce编程已经有一段时间了,作为一个从编程中寻找自信和乐趣以及热爱编程的孩子来讲,手开始变得很“痒”了,很想小试一下身手.于是自己编写了TopK的代码.TopK的意思就是从原文 ...
- HDU 4737 A Bit Fun
题意:定义F(i,j)为数组a中从ai到aj的或运算,求使F(i,j)<m的对数. 思路:或运算具有单调性,也就是只增不减,如果某个时刻结果大于等于m了,那么再往后一定也大于等于m.所以可以用两 ...
- FragmentActivity+FragmentTabHost+Fragement instead of TabActibvity+TabHost+Activity
http://www.tuicool.com/articles/NzeMJz http://www.tuicool.com/articles/FJ7VBb FragmentTabHost切换Fragm ...
- hdu 2050
PS:真是醉了..之前觉得这题很难..然后在网上找到了大神给的深入解析,跪谢...这里贴大神博客的网址:http://blog.csdn.net/lishuhuakai/article/details ...
- 无法为表空间 ***中的段创建 INITIAL 区
这是由于表空间不足引起的. 具体错误: 解决方案:扩展表空间
- java互斥方法
synchronized, lock/unlock, volatile类型变量, atom类, 同步集合, 新类库中的构件: CountDownLatch\CyclicBarric\Semaph ...
- UVA821 floyd最短路+暴力
题意:给n条边,求每两个点之间的平均距离: 思路:数据是100条边,用floyd得到每两点之间的最短距离,然后遍历相加除以边的数目: #include <iostream> #includ ...
- 【LeetCode OJ】Triangle
Problem Link: http://oj.leetcode.com/problems/triangle/ Let R[][] be a 2D array where R[i][j] (j < ...
- HDU 3966 (树链剖分+线段树)
Problem Aragorn's Story (HDU 3966) 题目大意 给定一颗树,有点权. 要求支持两种操作,将一条路径上的所有点权值增加或减少ai,询问某点的权值. 解题分析 树链剖分模板 ...
- [转]Why Not Paxos
http://blog.csdn.net/cszhouwei/article/details/38374603 Why Not Paxos Paxos算法是莱斯利·兰伯特(LeslieLamport, ...