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的更多相关文章

  1. Oracle - PL/SQL Commands

    第一章:日志管理 1.forcing log switches sql> alter system switch logfile; 2.forcing checkpoints sql> a ...

  2. 常用sql commands以及mysql问题解决日志

    mysql workbench常用命令快捷键 ctrl+T ->创建新的sql query tab ctrl+shift+enter->执行当前的sql命令 https://dev.mys ...

  3. Postgresql Useful SQL/Commands

    Update records ' and a.subscriber_id=b.subscriber_id; Connections select count(*) from pg_stat_activ ...

  4. 【转】PowerShell 连接SQL Server 数据库 - ADO.NET

    转至:http://www.pstips.net/connect-sql-database.html PowerShell 通过ADO.NET连接SQL Server数据库,并执行SQL脚本.工作中整 ...

  5. 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. ...

  6. 执行原始的 SQL 查询

    The Entity Framework Code First API includes methods that enable you to pass SQL commands directly t ...

  7. Oracle 通过sql profile为sql语句加hint

    sql profile最大的优点是在不修改sql语句和会话执行环境的情况下去优化sql的执行效率,适合无法在应用程序中修改sql时.sql profile最常用方法大概是:--创建产生sql tuni ...

  8. sql - and - or

    sql - and SQL AND links together two or more conditional statements for increased filtering when run ...

  9. 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 ...

随机推荐

  1. Stm32_调试出现 Error:Flash Download Failed-"Cortex-M3"

    rror:Flash Download Failed-"Cortex-M3"出现一般有两种情况: 1.SWD模式下,Debug菜单中,Reset菜单选项(Autodetect/HW ...

  2. Hadoop MRUnit使用(一)

    之前在写MR job的时候,由于要在云梯,或者一淘的开发集群上运行:所以处理方法是,在本地打成jar包,然后scp到客户端网关机上,然后在提交job运行.这样的问题时,有时候如果遇到一些逻辑上的问题, ...

  3. linux下解决端口被占用的问题

    以端口9877为例,先查看是否有进程占用该端口 netstat -tln | grep 9877 然后查看占用该端口的进程的进程id lsof -i :9877 最后kill 命令结束该进程: kil ...

  4. Tips about Object-oriented programming

    1, Return subinterface For example, we have a parent interface: public interface A<T extends A< ...

  5. Camel routes in Spring config file

    The normal spring bean definition configuration file, the xsi:schemaLocation only has two: beans and ...

  6. 【Oracle XE系列之四】创建OracleXE表空间详解

    创建OracleXE表空间示例 sqlplus /nolog connect sys as sysdba SQL> create tablespace OPFOCN  datafile 'C:\ ...

  7. Bootstrap组件On和Off语法

    $(document).on('click.bs.carousel.data-api','td',function(e){}) $(document).off('.carousel.data-api' ...

  8. Smart210学习记录------paltform总线

    转自http://blog.csdn.net/xiaochongtou123/article/details/7752328 1.概述: 通常在Linux中,把SoC系统中集成的独立外设单元(如:I2 ...

  9. matlab产生正态分布样本

    mvnrnd - Multivariate normal random numbers This MATLAB function returns an n-by-d matrix R of rando ...

  10. You must install 'hg' on your build machine

    /***************************************************************************************** * You mus ...