查看sql server lock
drop table #t
create table #t(req_spid int,obj_name sysname)
declare @s nvarchar(4000)
,@rid int,@dbname sysname,@id int,@objname sysname
declare tb cursor for
select distinct req_spid,dbname=db_name(rsc_dbid),rsc_objid
from master..syslockinfo where rsc_type in(4,5)
open tb
fetch next from tb into @rid,@dbname,@id
while @@fetch_status=0
begin
set @s='select @objname=name from ['+@dbname+']..sysobjects where id=@id'
exec sp_executesql @s,N'@objname sysname out,@id int',@objname out,@id
insert into #t values(@rid,@objname)
fetch next from tb into @rid,@dbname,@id
end
close tb
deallocate tb
select 进程id=a.req_spid
,数据库=db_name(rsc_dbid)
,类型=case rsc_type when 1 then 'NULL 资源(未使用)'
when 2 then N'数据库'
when 3 then N'文件'
when 4 then N'索引'
when 5 then N'表'
when 6 then N'页'
when
相关文档:
如果你经常遇到下面的问题,你就要考虑使用SQL Server的模板来写规范的SQL语句了:
SQL初学者。
经常忘记常用的DML或是DDL SQL 语句。
在多人开发维护的SQL中,每个人都有自己的SQL习惯,没有一套统一的规范。
在SQL Server Management Studio中,已经给大家提供了很多常用的现成SQL规范模板。
SQL Server Management ......
转自:http://hi.baidu.com/arslong/blog/item/b23307e76252342cb8382001.html
Item01
连接字符串中常用的声明有:
服务器声明:Data Source
、Server
和Addr
等。
数据库声明:Initial Catalog
和DataBase
等。
集成Windows
账号的安全性声明:Integrated
Security
和Trusted_Connection
等。
使用数据库 ......
--SQL高级程序设计:子查询
use AdventureWorks
GO
SELECT DISTINCT EmployeeID from HumanResources.JobCandidate WHERE EmployeeID IS NOT NULL;
SELECT e.EmployeeID,FirstName,LastName
from HumanResources.Employee e
INNER JOIN Person.Contact c
ON e.ContactID = c.ContactID
WHERE e.EmployeeID IN ......
//取出源数据
select groupname,totalnum,inputdate,groupid into #temp from
(select count(*)as totalnum,p.groupid,g.groupname,convert(nvarchar(10),inputdate,120) as 'inputdate'
from person p left join admin_group g on p.groupid = g.groupid and deleteflag = '0'
where p.inactive=' ......
通配符 说明
_ 与任意单字符匹配
% 与包含一个或多个字符的字符串匹配
[ ] 与特定范围(例如,[a-f])或特定集(例如,[abcdef])中的任意单字符匹配。
[^] 与特定范围(例如,[^a-f])或特定集(例如,[^abcdef])之外的任意单字符匹配。 ......