使用waitfor time和waitfor delay在一定时间间隔下定时执行批处理
使用waitfor time和waitfor delay[@more@][case 1]WAITFOR TIME '01:20:04'begin declare @i int = 0 while (@i < 3) begin insert into ContentType_Log(TypeID,TypeName,LastUpdateDate) select TypeID,TypeName,getdate() as LastUpdateDate from TypeTable set @i = @i + 1 WAITFOR DELAY '00:00:10' endendGO[case 2]WAITFOR TIME '01:23:34'GObegin insert into ContentType_Log(TypeID,TypeName,LastUpdateDate) select TypeID,TypeName,getdate() as LastUpdateDate from TypeTable WAITFOR DELAY '00:00:10' endGO 3
Troubleshooting: Connecting to SQL Server When System Administrators Are Locked Out
http://msdn.microsoft.com/en-us/library/dd207004%28v=sql.105%29.aspx[@more@][run as Admin]Microsoft Windows [Version 6.1.7601]Copyright (c) 2009 Microsoft Corporation. All rights reserved.C:Windowssystem32>C:Windowssystem32>net stop mssqlserverThe SQL Server (MSSQLSERVER) service is stopping.The SQL Server (MSSQLSERVER) service was stopped successfully.C:Windowssystem32>net start mssqlserver /mThe SQL Server (MSSQLSERVER) service is starting.The SQL Server (MSSQLSERVER) service was sta
Database Unit Testing
Database Unit TestingDAL(Database Access Layer) Unit Testing[@more@]1. Database Unit Testinghttp://www.databasejournal.com/features/mssql/article.php/3844791/Database-Unit-Testing.htmhttp://www.cnblogs.com/harrychinese/articles/TutorialQuickStart.htmlhttps://anydbtest.codeplex.com/releases/view/609812. DAL(Database Access Layer) Unit Testinghttp://www.codeproject.com/Articles/12334/Armadillo-Unit-Testing-of-inline-SQL-with-a-little?q=c%23+db+unit+test+framework#intro
偶发的存储过程调用性能问题的一次调优过程
某存储过程调用频繁,绝大部分调用在1秒内结束。在每30分钟内,有30到40次调用超过10秒。从业务上我们知道这个过程调用很频繁,但到是什么程度,我们还不清楚。另外,从执行计划上来看,已经最优,没有优化SQL的空间了。下面是在这种情况下的调优过程。[@more@]1. 系统检测 (1)取系统等待并且阻塞的进程 SET NOCOUNT ON SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED GO CREATE TABLE #block( [current_time] [datetime] NOT NULL, [resource_type] [nvarchar](60) NOT NULL, [requ
获取SQL Server中连接的客户端IP地址
有时候需要获取连接到SQL Server服务器上的客户端IP地址,用什么办法呢?[@more@]SELECT *FROM sys.dm_exec_connections WHERE session_id = @@SPID 这个办法不适用于SQL2005和以前版本。 如果是SQL Server2008,还可以用CONNECTIONPROPERTY方法获取: SELECT CONNECTIONPROPERTY('net_transport') AS net_transport, CONNECTIONPROPERTY('protocol_type') AS protocol_type, CONNECTIONPROPERTY('auth_scheme') AS auth_scheme, CONNECTIONPROPERTY('local_net_address') AS lo
SQL Server中常用全局变量和系统信息
在SQL Server中,全局变量是一种特殊类型的变量,服务器将维护这些变量的值。全局变量以@@前缀开头,不必进行声明,它们属于系统定义的函数。还有一些系统信息的获取方法,例如服务器上次启动时间。[@more@]全局变量名称描述@@CONNECTIONS返回 SQL Server 自上次启动以来尝试的连接数。@@CPU_BUSY返回 SQL Server 自上次启动后的工作时间。@@CURSOR_ROWS返回连接上打开的上一个游标中的当前限定行的数目,确定当其被调用时检索了游标符合条件的行数。@@DATEFIRST针对会话返回 SET DATEFIRST 的当前值,SET DATEFIRST 表示指定的每周的第一天
SQL Server中查询用户的对象权限和角色的方法
SQL Server中查询用户的对象权限和角色的方法[@more@] -- 查询用户的object权限exec sp_helprotect NULL, 'UserName' -- 查询用户拥有的roleexec sp_helpuser 'UserName' -- 查询哪些用户拥有指定的系统roleexec sp_helpsrvrolemember 'sysadmin' -- 可查询嵌套roleWITH tree_roles as(SELECT role_principal_id, member_principal_idFROM sys.database_role_membersWHERE member_principal_id = USER_ID('UserName')UNION ALLSELECT c.role_principal_id,c.member_principal_idFROM sys.database_role_members as cinner join tree_r
SQL Server 2005/2008 对With Encryption选项创建的存储过程解密
1. 创建sp__windbi$decrypt 2. 使用DAC(专用管理员连接)连接到数据库 3. 调用解密[@more@]http://www.cnblogs.com/kiant71/archive/2009/09/10/1752016.html
SQL Server 索引使用分析 - SARG(Searchable Arguments)
SARG的定义:用于限制搜索的一个操作,因为它通常是指一个特定的匹配,一个值得范围内的匹配或者两个以上条件的AND连接。形式如下:列名 操作符 <常数 或 变量> 或 <常数 或 变量> 操作符列名[@more@]很多人不知道SQL语句在SQL SERVER中是如何执行的,他们担心自己所写的SQL语句会被SQL SERVER误解。比如:select * from table1 where name=''zhangsan'' and tID > 10000和执行:select * from table1 where tID > 10000 and name=''zhangsan''一些人不知道以上两条语句的执行效率是否一样,因为如果简单的从语句先
Sql server 2005中output用法解析
SQL Server 2005中的output子句,可以使你从修改语句(INSERT、UPDATE、DELETE)中将数据返回到表变量中。带结果的 DML 的有用方案包括清除和存档、消息处理应用程序以及其他方案。 [@more@]一、关于output子句 SQL Server 2005中的output子句,可以使你从修改语句(INSERT、UPDATE、DELETE)中将数据返回到表变量中。带结果的 DML 的有用方案包括清除和存档、消息处理应用程序以及其他方案。这一新的 OUTPUT 子句的语法为: OUTPUT INTO @table_variable 可以通过引用插入的表和删除的表来访问被修改的行的旧/新映像,其方式与访问触发
A Guide for SQL Server Backup Application Vendors
Summary: SQL Server 2005 provides support for Volume Shadow Copy Service (VSS) by providing a writer (the SQL writer) so that a third-party backup application can use the VSS framework to back up database files. This paper describes the SQL writer component and its role in the VSS snapshot creation and restore process for SQL Server databases. It also captures details on how to configure and use the SQL writer to work with backup applications in the VSS framework. On This Page Intr
SQL Server Transaction Log Fragmentation: a Primer
Generally, you will have no need to worry about the number of virtual log files in your transaction log. However, if you use the default settings for 'auto-grow', you can end up with such 'fragmentation' in your transaction log as to affect performance noticably. How can this be avoided? How can you tell it's a problem? What do you do about it? Greg explains.[@more@]http://www.simple-talk.com/sql/database-administration/sql-server-transaction-log-fragmentation-a-primer/
Database Testing: How to Regression Test a Relational Database
Why test an RDBMS? What should we test? When should we test? How should we test?Who should test? Introducing database testing into your organization Database testing and data inspection Best practices [@more@]http://www.agiledata.org/essays/databaseTesting.html#Tools
用CLR函数把HTMLCode转换为原字符
1. HTMLCode格式2. 转换方法3. 部署方法4. 调用方法[@more@]1. HTMLCoding格式因为安全方面的原因,网页提交html特殊字符例如<, >,', "等和汉字时,常常被编码为HTMLCode格式。例如:[ ' ] - ’[ " ] - ”[ < ] - <[ > ] - >[中国] - & #20013;& #22269;C#引用System.Web.dll,调用HttpUtility.HtmlDecode转换成原文。具体:VS.net建立Database项目而不是CLR项目,否则,不能Reference System.Web.dll到项目中;创建CLR Funcation,调用 HttpUtility.HtmlDecode转换成原文
使用CLR函数压缩(Gzip)ntext类型字段
Gzip to StringString to Gzip[@more@]using System;using System.Data;using System.Data.SqlClient;using System.Data.SqlTypes;using Microsoft.SqlServer.Server;using System.IO;using System.IO.Compression;using System.Text;public partial class Gzip{ [Microsoft.SqlServer.Server.SqlFunction] public static SqlChars GzipToString(SqlBytes gBytes) { byte[] bytes = gBytes.Value; bytes = Decompress(bytes); string str = Encoding.GetEncoding(936).GetString(bytes); SqlChars s
Monitoring Tempdb in SQL Server 2005
from: http://www.sqllion.com/2009/05/monitoring-tempdb-in-sql-server-2005/[@more@]As the tempdb database is the common global resource for all the operations going on in SQL Server, so the DBA has to be bit cautious about the use of it. Because any unexpected operations by the applications running under the SQL Server instance or any uneven query by the user can eat all the space available to thetempdb resulting decrease in the performance of all other applications running under the same instanc
sql server系统表与系统视图详细说明
SQL Server系统表系统视图,可分为:目录视图 信息架构视图 兼容性视图 复制视图 动态管理视图和函数 [@more@]系统表:sysaltfiles 主数据库 保存数据库的文件 syscharsets 主数据库字符集与排序顺序sysconfigures 主数据库 配置选项syscurconfigs 主数据库当前配置选项sysdatabases 主数据库服务器中的数据库syslanguages 主数据库语言syslogins 主数据库 登陆帐号信息sysoledbusers 主数据库 链接服务器登陆信息sysprocesses 主数据库进程sysremotelogins主数据库 远程登录帐号syscolumns 每个数据库 列sysconstrains 每个数据库 限制sys
A significant part of sql server process memory has been paged out. This may result in performance d
A good article about "A significant part of sql server process memory has been paged out. This may result in performance degradation. Duration 0 seconds. Working set (KB) 25432, committed (KB) 11296912, memory utilization 0%"[@more@]If you are using SQL Sever Server standard edition 64 bit on a Windows 2003 64bit, you will frequently encounter this problem where SQL Server says:A significant part of sql server process memory has been paged out. This may result in performance degradatio
三种东西永远不要放到数据库里
我已经在很多演讲里说过,改进你的系统的最好的方法是先避免做“蠢事”。我并不是说你或你开发的东西“蠢”,只是有些决定很容易被人们忽略掉其暗含的牵连,认识不到这样做对系统维护尤其是系统升级带来多大的麻烦。作为一个顾问,像这样的事情我到处都能见到,我还从来没有见过做出这样的决定的人有过好的结果的。[@more@]我已经在很多演讲里说过,改进你的系统的最好的方法是先避免做“蠢事”。我并不是说你或你开发的东西“蠢”,只是有些决定很容易被人们忽略掉其暗含 的牵连,认识不到这样做对系统维护尤其是系统升级带来多大的麻烦。
浅析SQL Server datetime数据类型设计与优化误区
今天我们将探讨SQL Server datetime数据类型设计与优化误区,希望这些基础性的知识能对大家有所帮助。原文链接:http://www.cnblogs.com/gaizai/archive/2010/11/26/1888505.html[@more@]一、场景在SQL Server 2005中,有一个表TestDatetime,其中Dates这个字段的数据类型是datetime,如果你看到表的记录如下图所示,你最先想到的是什么呢?(图1:数据列表)你看到这些数据,是不是觉得这样的设计既浪费了存储空间,又使得这个列的索引增大,查询起来更慢,你也想使用一些其它的数据类型来代替这个datetime吧?其实大家都是这么想的,这个