MSSQL查找进程造成死锁_把这个进程杀掉
create proc [dbo].[sp_lockinfo]
@kill_lock_spid bit=0, --是否杀掉阻塞的进程,1 杀掉, 0 仅显示
@show_spid_if_nolock bit=0, --如果没有阻塞的进程,是否显示正常进程信息,1 显示,0 不显示
@dbname sysname='' --如果为空,则查询所有的库,如果为null,则查询当前库,否则查询指定库
as
set nocount on
declare @count int,@s nvarchar(2000),@dbid int
if @dbname='' set @dbid=db_id() else set @dbid=db_id(@dbname)
select id=identity(int,1,1),标志,
进程ID=spid,线程ID=kpid,块进程ID=blocked,数据库ID=dbid,
数据库名=db_name(dbid),用户ID=uid,用户名=loginame,累计CPU时间=cpu,
登陆时间=login_time,打开事务数=open_tran, 进程状态=status,
工作站名=hostname,应用程序名=program_name,工作站进程ID=hostprocess,
域名=nt_domain,网卡地址=net_address
into #t from(
select 标志='阻塞的进程',
spid,kpid,a.blocked,dbid,uid,loginame,cpu,login_time,open_tran,
status,hostname,program_name,hostprocess,nt_domain,net_address,
s1=a.spid,s2=0
from master..sysprocesses a join (
select blocked from master..sysprocesses
where blocked>0
and(@dbid is
相关文档:
select语句前加:
declare @d datetime
set @d=getdate()
并在select语句后加:
select [语句执行花费时间(毫秒)]=datediff(ms,@d,getdate())
转自:动态网制作指南 www.knowsky.com
这是简易的查看执行时间的方法。
===========================================(一下内容转自:CSDN)
MSSQL Server中通过查 ......
1.
--将汉字转换为拼音首字母
CREATE function GetAllPY(@str nvarchar(4000))
returns nvarchar(4000)
--WITH ENCRYPTION
as
begin
declare @intLen int
declare @strRet nvarchar(4000)
declare @temp nvarchar(100)
set @intLen &nb ......
--字段添加说明
EXEC sp_addextendedproperty 'MS_Description', '要添加的说明', 'user', dbo, 'table', 表名, 'column', 列名
--删除字段说明
EXEC sp_dropextendedproperty 'MS_Description', 'user', dbo, 'table', 表名, 'column', 字段名
--查看字段说明
SELECT
[Table Name] = i_s.TAB ......
@echo off
:dosmenu
REM 选择菜单
echo Windows 服务启动或关闭 By hope 2008年2月7日
echo.
echo [1]启动Sql Server2005 [2]关闭Sql Server2005
echo [3]启动Oracle9i [4]关闭Oracle9i
echo.
echo ......
Sql2005中使用ow_number() partition进行分组实验,
SQL:
select * from stu
select id,row_number() over (partition by snm order by id) from stu
结果:
id snm
----------------
111 111V
111 111W
222 222N
333 3123
444 3123
555 3123
666 3232
777 3232
--分组后的结果
id &n ......