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 ...
随机推荐
- rcc
一.在STM32中,有五个时钟源,为HSI.HSE.LSI.LSE.PLL. 全名: high speed external ①HSI是高速内部时钟,RC振荡器,频率为8MHz. ②HSE是高 ...
- hdu 2082
ps:get到了母函数...看了好久的模板与介绍....似懂非懂..决定要多找些题来试试... 代码: #include "stdio.h" #include "stri ...
- Chapter 3: Connector(连接器)
一.概述 Tomcat或者称之为Catalina(开发名称),可以简化为两个主要的模块,如下图: 多个Connector关联一个Container.之所以需要多个Connector,是为了处理多种协议 ...
- js中的apply调用
今天看了阮一锋老师的一篇文章,感觉很明了对闭包的理解,尤其是文章中的apply的介绍 apply()是函数对象的一个方法,它的作用是改变函数的调用对象,它的第一个参数就表示改变后的调用这个函数的对象. ...
- Construct a basic automation test framework
Elements in an automation test framework: actor,---simulate trader, have its own name, can get contr ...
- Finding Nemo_BFS
Description Nemo is a naughty boy. One day he went into the deep sea all by himself. Unfortunately, ...
- The Cow Lineup_找规律
Description Farmer John's N cows (1 <= N <= 100,000) are lined up in a row.Each cow is labeled ...
- 【转】Fiddler 教程
原文转自:http://www.cnblogs.com/tankxiao/archive/2012/02/06/2337728.html Fiddler是最强大最好用的Web调试工具之一,它能记录所有 ...
- [转载]python 爬虫总结
1.基本抓取网页 get方法 import urllib2 url = "http://www.baidu.com" response = urllib2.urlopen(url) ...
- Debian 入门安装与配置1
Debian 入门安装与配置1 最近安装了多个发行版本的Linux,包括Ubuntu.Fedora.Centos和Debian,发现只有Debian在界面和稳定性等综合特性上表现最优,自己也最喜欢,所 ...