- 博客(59)
- 资源 (12)
- 收藏
- 关注
原创 查询并行计划的SQL语句
sys.dm_exec_query_plan以 XML格式返回计划句柄指定的批查询的显示计划,下面的语句就是通过查询XML获得并行计划信息。 SELECT TOP 10 p.*, q.*, qs.*, cp.plan_handle FROM sys.dm_exec_cached_planscp CROSS apply sys.dm_exec_query_
2012-07-31 16:37:37 1574
原创 SubQuery or Join?
很多开发都喜欢用Subquery而不喜欢用Join,对于他们来讲Subquery更容易实现。但是很多情况下用Join性能要比用Subquery好。 首先我们看一下Subquery: 子查询也称为内部查询或内部选择,而包含子查询的语句也称为外部查询或外部选择。许多包含子查询的Transact-SQL语句都可以改用联接表示。其他问题只能通过子查询提出。在 Transact-SQL 中,
2012-07-31 11:07:33 2964 2
原创 利用Flashback轻松找回误删除数据
测试:1.首先创建一张表TESTcreate table test (name int)2.插入两条数据:insert into test values (1);insert into test values (1);3.对表启动移动行ALTERTABLE table ENABLE ROW MOVEMENT;4.删除表:drop table
2012-07-30 17:22:29 1237
原创 调整数据库兼容降级解决应用程序不支持高版本SQL Server
曾经遇到过一个问题,我们的数据库是高版本的,但是开发商说他们的软件对于高版本的数据库支持的不好。当时我问了他们有没有使用什么特殊的功能,比如SQL Server旧版本中的功能而在新版本中不支持的,他们确定是没有的,只是使用了T-SQL做的开发。我猜应该是一些旧的SQL语句在新的版本中无法运行了。如果只是T-SQL的问题可以尝试将数据库降级(比如100-90),这样高版本数据库就
2012-07-30 17:20:43 2706
原创 查看SQL Server日志 Part 1
曾经有朋友问我数据被删除了,不借助第三方工具能不能查是什么时候发生的。 SQL Server提供了一个undocumented的函数fn_dblog可以让我们查看活动的transaction log。语法如下:::fn_dblog(@StartingLSN,@EndingLSN)如果参数都为NULL默认是抓取所有的交易信息。 使用这个函数我们可以查询DML,DDL信息,比如数据删除
2012-07-30 10:04:43 12955 2
原创 Transaction log impact of active transactions
SELECT DTST.[session_id], DES.[login_name]AS[Login Name], DB_NAME(DTDT.database_id)AS [Database], DTDT.[database_transaction_begin_time]AS [Begin Time], --DATEDIFF(ms,DTDT.[database_transa
2012-07-29 19:59:20 1288
原创 Schema Changes History数据从哪里来?
SQL Server提供了Schema Changes History report可以用来追踪DDL相关信息。 但是Schema Changes History report的数据是从哪里来的呢? 首先我启动SQL Profiler trace然后打开Schema Changes History report(Management studio->Report->Standard rep
2012-07-29 09:38:47 1134
原创 使用文件和文件组备份可以恢复表数据吗?
以前有人问过我SQL Server backup命令是不是支持单表备份,SQL Server是没有Backup table命令的。当时我的建议是用SSIS导出到文件系统,其他数据库或者用文件组备份。现在想想单纯靠文件组备份不一定解决表还原问题。 对于文件组还原要求所有的文件组都要在同一个时间点上,这样才能保证数据库的连续性。如果我们发现文件组中的数据被被删除,那么我们需要首先恢复文件组备份
2012-07-29 07:33:34 1624
原创 小技巧 SQL execution loop
我们做测试的时候通常需要连续执行很多条相同的语句,我以前一直是通过While循环去做的,但是有一个更简单的办法,只需要用Go就可以实现了。 代码如下: use DBA gocreate table test(namevarchar(10))on [group]goinsert into testvalues ('allen')go 1000
2012-07-28 17:48:51 979
原创 使用Filtered Indexes提高查询性能
通常我们会遇到这样的情况,一张表中包含上百万条的数据,但是每次我们只查询一小部分的数据。 比如一列只有少部分NULL值,每次我们都需要将Null值找出来进行处理。或者我们有状态标志位,需要取Flag对数据处理。 由于数据大部分是重复的,所以对于整个列做索引代价是非常大的,而且对查询性能提升可能不大。 庆幸的是微软提供了Filtered index。Filtered index引使用
2012-07-27 20:19:32 1477
翻译 log backup chain被打断后是不是需要从一个完整备份重新开始?
一般我们的理解是logbackup chain被打破后一定需要一个完整备份然后才能开始新的日志备份,其实不一定需要完整备份,差异备份也是可以的。 首先我们先做个测试:创建数据库做完整备份和日志备份,然后将恢复模式变成简单恢复模式。 CREATEDATABASE LogChainTest;GOALTER DATABASE LogChainTest SET RECO
2012-07-27 17:18:26 1264
原创 Thread数目会超过MAXDOP的限制?
今天测试数据库的并行计划,对数据库做了一些调整。将MAXDOP的数量更改为1。但是发现还是有很多SQL语句有超过5个Thread.后来查到一篇文章说根本的原因在于MAXDOP的限制只会作用在执行计划的每个operator上,而不会作用在整个执行计划上。于各种各样的原因,我们可能需要通过sp_configure来设置最大并行度,也就是Max Degree of Parallelism (MA
2012-07-26 17:04:59 1665
转载 数据库硬件选择
虽然大家使用的数据库可能不一样,但是整体的思路都是一样的。下面的文章对于选择数据库硬件有指导意义:So you need to purchase a new database server, and you really don’t know where to start..Because their maybe different recommendations for differ
2012-07-26 17:03:34 984
原创 数据仓库开发的一般流程
DEP1 — 重复的标准开发—为进行重复性的分析处理(通常称为提交标准报告),通常的需求-驱动处理出现了。这意味着下列的步骤(前面描述的)会重复进行:M1 —会谈,数据收集,J A D,战略计划,现有系统。M2 —规模估计,阶段划分。M3 —需求形式化。P1 —功能分解。P2 — 0层上下文。P3 — 1 - n层上下文。P4 —每个部件的D F D。P5 —算法规
2012-07-26 17:02:16 1106
原创 Checkpoint是不是只写提交的Transcation页
很多人都以为Checkpoint只是将已经完成Transcation的脏页写入磁盘,其实不是这样的: One commonmisconception about checkpoints is that they only write out pages with changesfrom committed transactions. This is not true—a checkpo
2012-07-26 10:18:28 1072
原创 如何将高版本的数据库还原到低版本服务器?
今天在论坛看到帖子问可不可以将SQL Server 2008的数据库欢迎到SQL Server 2005,这个SQL Server是不支持的。但是可以通过其他的方式实现。首先在SQL Server 2008上导出数据库脚本然后在SQL Server 2005上创建对象,然后用导入导出工具将数据导入2005就完成了。 在导出脚本的过程中有一个选项要注意“Script for server v
2012-07-25 20:56:54 2282
原创 存储过程性能查询语句
sys.dm_exec_procedure_stats返回缓存存储过程的聚合性能统计信息,所以用这个函数我们可以查询缓存的存储过程性能,然后针对耗资源的部分进行优化。 SELECT DB_NAME(database_id) DBName,OBJECT_NAME(object_id) SPName, datediff(second, last_execution_time,get
2012-07-25 20:24:39 1216
原创 配置Log shipping失败Could not retrieve copy settings for secondary ID
配置Log Shipping的时候Copy和Restore的Job一直失败,错误如下:***Error: Couldnotretrieve copy settingsforsecondary ID '[removed]'.(Microsoft.SqlServer.Management.LogShipping)*** ***Error: The specified agent_id
2012-07-25 17:26:40 1560
转载 衡量IO性能的几个指标
前言作为一个数据库管理员,关注系统的性能是日常最重要的工作之一,而在所关注的各方面的性能只能IO性能却是最令人头痛的一块,面对着各种生涩的参数和令人眼花缭乱的新奇的术语,再加上存储厂商的忽悠,总是让我们有种云里雾里的感觉。本系列文章试图从基本概念开始对磁盘存储相关的各种概念进行综合归纳,让大家能够对IO性能相关的基本概念,IO性能的监控和调整有个比较全面的了解。在这一部分里我们先舍弃各种结
2012-07-25 17:24:29 1174
原创 rsInvalidPolicyDefinition role assignment is not valid.
由于旧的Reporting是32位的运行数据量大的Report很吃力,所以打算把新的Reporting servcie 2008用起来。 发布了一个新的Report然后尝试给用户分配权限,但是遇到了下面的错误:" role assignment is not valid. The role assignment is either empty or it specifies a u
2012-07-25 17:07:55 1092
原创 数据库连接使用SQL Server 别名
很多人都遇到过下面的问题:1.使用Log shipping,如果主服务器出问题以后应用程序如何转到辅助服务器?2.如果将数据库迁移到其他服务器,我不想修改程序该如何实现? 针对上面的两个问题我们可以使用SQL Server 别名: SQL Server Configuration Manager->SQL Native Client Configuration->newAl
2012-07-25 12:50:45 2333
转载 使用sys.dm_io_virtual_file_stats了解你的数据库IO
因为sys.dm_io_virtual_file_stats返回数据和日志文件的 I/O 统计信息,包括对文件发出的读取/写入次数以及总字节数,所以这个函数既可以看到IOPS也可以看到吞吐量,还可以计算出单个IO的大小。另外也可以看到IO的等待时间。能够帮助我们很好的了解数据库的IO状况。配合Perfmon一起使用可以很快的找到IO瓶颈。下面的文章来自微软的以为高级工程师:http
2012-07-25 12:25:45 3740
原创 SSIS Job失败作业通知
作为DBA我们需要监控各个作业的正常运行,而且需要能够及时的了解作业失败的原因。 对于SSIS作业,我们可以通过下面的步骤建立Mail通知。Step1:启用SSIS Logging:可以帮助我们捕获SSIS失败的信息(Right click on the white pane)Right click on the white paneStep 2: 选择 Loggings
2012-07-25 12:24:47 2309
原创 数据库恢复过程中查看恢复数据
相信很多人都遇到过数据被误删除然后要求DBA将数据还原回来,但是用户只知道发生的大概时间。这个时候查看备份可能看到有两个备份的时间跟错误发生的时间差不多。如果你还原到最后一个的话,可能查看数据发现已经出问题了,那么你得重新来一遍。如果Log很多的话这个是很花时间的。今天看到ORACLE的恢复原理中有这么一句话:Beforeusing the OPEN RESETLOGS c
2012-07-25 12:23:26 1017
转载 Top 25 DBA Worst Practices
Not considering service levelagreements (SLAs) when designing a database environment and/or not consideringthe need for scheduled downtime for service pack/hotfix application,Defining "disaster" too
2012-07-25 12:22:32 686
转载 SSIS设计模式捕获变化数据
对于用SSIS设计数据仓库ETL很有用,值得一看。 转自SQLServerCeWithin Integration Services there is no single out of the box components to handle CDC. However there are various mechanisms to achieve this either by buildi
2012-07-25 12:21:30 1445
原创 Reporting service runningvalue 函数解决累计值问题
Reporting有一个函数可以提供自动累加功能,比如周四运行Report的时候就要将周一到周三的数据自动加总。 可以这样实现:1. 首先根据Stock Code和Location做Group2.然后新加一个栏位用runningvalue针对于上面的Group做Sum很方便的就做好了这个ReportCode:=runningvalue(Fields!BalanceAmout
2012-07-25 12:21:01 2887
原创 SQL Server TB 级别数据库文件快速初始化
当创建大数据库时,为了减少碎片,我们一般都会安装最终的使用大小创建,但是初始化数据和日志文件时会覆盖以前删除的文件遗留在磁盘上的任何现有数据,花费很多的时间。 不过SQL Server 提供了即时文件初始化功能,借助这个功能可以在瞬间对数据文件进行初始化即时文件初始化功能仅在向 SQL Server (MSSQLSERVER) 服务帐户授予了 SE_MANAGE_VOLUME_N
2012-07-25 12:20:15 1207
原创 SQL Truncate table 权限
对于一些很大的表,如果要删除数据用Truncate table比Delete效果要好。TRUNCATE TABLE (Transact-SQL)Removes all rows from a table without logging the individual row deletions. TRUNCATE TABLE is similar to the DELETE
2012-07-25 12:19:38 3796
原创 从Workgroup查询AD用户信息
以前写过一段脚本是从AD域中查询AD用户信息。但是如果从WorkGroup上就无法得到结果了。下面的一段脚本可以实现从WorkGroup查询域账户信息。 注意:运行之前先将DC服务器以及账户名和密码替换,然后保存成VBS。如果要查询其他信息可以更改对应的Filter,category和Class. Option Explicit Dim objRootDSE, strDNS
2012-07-25 11:16:37 1512
原创 使用计算列提高查询性能
一般在写SQL的时候应该避免在条件中使用函数,因为这样就不能有效的使用索引,从而无法生成高效的执行计划。 SQL Server提供了计算列可以帮助我们解决这个问题。 我们举个普通的例子。有很多公司使用SQL Server Collcation为大小写敏感的,因为没有办法控制用户的输入(当然在程序中进行转化也是可以的,比如全部转为大写,但是当时设计的时候很多程序员都没有考虑到),所以再做查询的时
2012-07-25 09:40:01 2105 2
原创 sysprocess中看到的HostName不一定是真正的HostName
最近在监控Long running的SQL,发现有一些用户在用Office拉数据。因为在Office里边没有做限制,所以每次都是将所有运营公司的数据抓一遍,而且运行很频繁,造成了我们ERP系统性能下降。根据Host_Name找到对应的开发人员,他们说自己根本就没在跑。这个就奇怪了,到底这个Host Name从哪里来的呢? 查看了一下Office的数据源,发现是用DSN配置的,里边有
2012-07-24 14:43:30 963
转载 数据库采用SSD效率会高吗?
NOR和NAND都是闪存技术的一种,NOR是Intel公司开发的,它有点类似于内存,允许通过地址直接访问任何一个内存单元,缺点是:密度低(容量小),写入和擦除的速度很慢。NAND是东芝公司开发的,它密度高(容量大),写入和擦除的速度都很快,但是必须通过特定的IO接口经过地址转换之后才可以访问,有些类似于磁盘。 我们现在广泛使用的U盘,SD卡,SSD都属于NAND类型,厂商将flash m
2012-07-24 14:37:23 5599 1
原创 SQL Server更改表数据类型View中Column数据类型没有相应改变
今天有个供应商问我一个问题如果更改表中一个字段的数据类型是不是View中的字段类型也响应自动更改。当时我想应该是会自动更改的。但是供应商说他们试过了不会更改的,问我除了重新建有没有什么办法。当时想到了刷新View的存储过程sp_refreshview,让他们试一下。执行之后View中的数据类型就被更新了。通过这个例子可以看到View中的字段类型是不会同步的除是schema-boun
2012-07-24 14:35:56 1172
原创 写WMI脚本工具
平时我们都会用到脚本调用WMI对服务器管理,微软提供了一个工具magical 可以让我们很方便的编写WMI脚本。这个工具打开以后直接根据WMI Class生产对于的查询脚本,我们只需要做少量的修改就可以了,看截图:(超级简单吧,下载地址:http://www.microsoft.com/en-us/download/details.aspx?id=3284)
2012-07-24 14:28:48 964
原创 用邮件发送运行时间久的SQL语句
ALTER proc [dbo].[usp_EmailLongRunningSQL]asbegindeclare@LongRunningQueries AS TABLE( lrqId int IDENTITY(1,1)PRIMARY KEY, spid int NULL, batch_duration bigintNULL, program_name
2012-07-24 14:27:49 941
原创 如何维护SQL Defalt Trace历史信息
Default Trace用途默认跟踪可确保数据库管理员在问题首次出现时即具有诊断该问题所需的日志数据,从而为数据库管理员提供了故障排除帮助。由于Default Trace保存了大量有用的信息,可以快速帮助我们做Audit或者Troubleshooting,所以保留历史信息也是很有用的。解决方法:1.首先创建数据表用来存储Trace信息,然后将现有的Defatult trace
2012-07-24 14:26:49 961
原创 Windows Server 2008如何更改ie安全性
关闭IE SEC 服务器系统要求很高的安全性,所以微软给IE添加了安全增强。这就使得IE在Internet区域的安全级别一直是最高的,而且无法进行整体调整。 点击快速运行栏的“服务器管理器”,开启服务器管理器,勾选“登录时不要显示此控制台”,点击“配置IE ESC”,将对“管理员”和“用户”设置成“禁用”以上就设置OK了!
2012-07-24 14:25:59 1490
原创 集中管理SQL Server Event Logs
前很多工具是可以做到监视SQL Server Event log并且通知对应的人,但是都是需要钱的,通过下面的Code也可以实现相应的功能,而且不需要花老板的钱。Step 1 - 创建数据库-----------------------------------USE[MASTER]GO-----------------------------------CREATEDATABASE
2012-07-24 14:25:11 1210
转载 如何处理SQL Server死锁问题
Good articles to troubleshooting deadlock issue in SQL Server:deadlock is defined in the dictionary as "a standstill resulting from the action of equal and opposed forces," and this turns out to be
2012-07-24 14:24:33 8935
The Guru's Guide to SQL Server Architecture and Internals.chm
2009-10-13
Sqlserver性能调整
2009-09-27
使用CPU计数器监视SQL Server性能的
2009-09-27
inside-microsoft-r-sql-server-tm-2005-the-storage-engine
2009-09-27
SQL SERVER 2005
2009-09-27
SQL+Server+2005技术内幕-存储引擎1-5章.pdf
2009-09-24
Microsoft Press - Inside Microsoft SQL Server 2005 Query Tuning and Optimization (Sep 2007).chm
2009-09-24
Inside Microsoft SQL Server 2005: T-SQL Programming
2009-09-24
SQL.Server.2005.Administration
2009-05-25
TSQL Query Tuning
2009-05-25
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人