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. servlet filter可以用注解

    现在好像可以在新建一个servlet.filter等的的时候在选项中设置urlmapping,通过注解的方式来监控action,以及设置初始参数initparameter.

  2. 【python】import 模块、包、第三方模块

    xx.py文件,称为模块(module),把不同模块归整到一起的文件夹,叫做包(package) 不同包下的模块可以重名,但是都不能和系统内建模块重名 包里面一定要有个__init__.py文件,否则 ...

  3. Python单元测试——unittest

    unittest是python自带的一个模块 python344\Lib\unittest 官方参考文档: http://docs.python.org/2.7/library/unittest.ht ...

  4. 从对SAE的一次授权安全评估浅谈云安全

      EMail: jianxin#80sec.comSite: http://www.80sec.comDate: 2011-12-20From: http://www.80sec.com/ [ 目录 ...

  5. Server.Transfer和Response.Redirect区别

    根本上,Response是叫浏览器去重新转向到指定的网页,而Server自然是发生在服务器端为主了,因此会有以下区别:1. Server.Transfer只能够转跳到本地虚拟目录指定的页面,而Resp ...

  6. jquery.autocomplete自动补全功能

    项目实例: 一:js //SupplierAutoComplete.js $().ready(function () { $("#txtSupplier").autocomplet ...

  7. IOS7新特性 edgesForExtendedLayout

    edgesForExtendedLayout是一个类型为UIExtendedEdge的属性,指定边缘要延伸的方向. 因为iOS7鼓励全屏布局,它的默认值很自然地是UIRectEdgeAll,四周边缘均 ...

  8. dubbo管理控制台安装和使用

    dubbo管理控制台安装和使用 标签: dubbo 2014-08-19 16:31 2436人阅读 评论(1) 收藏 举报  分类: dubbo(6)  版权声明:本文为博主原创文章,未经博主允许不 ...

  9. dedecms头部标签(标题,关键词,描述标签)(借用)

    先说说dedecms头部标题,关键词,描述标签的作用我相信网络上也有很多这样的信息,那为什么我还要写这个?因为这个对我们初学者来说还是比较重要的,因为做SEO就要用到这些标签.首先我写下首页头部标签我 ...

  10. codeforce Group Photo 2 (online mirror version)

    题目大意: 有n个矩形在地上排成一列,不可重叠,已知他们的宽度w和高度h,现在使至多[n / 2]个矩形旋转90度,问最后可以用多小的矩形恰好覆盖这n个矩形,求满足条件的最小矩形面积. n, w, h ...