首页 > 数据库技术 > 详细

数据库sql

时间:2015-08-14 11:19:54      阅读:163      评论:0      收藏:0      [点我收藏+]

--查询数据库中所有的表名及行数

SELECT a.name, b.rows
FROM sysobjects AS a INNER JOIN sysindexes AS b ON a.id = b.id
WHERE (a.type = u) AND (b.indid IN (0, 1))
ORDER BY a.name,b.rows DESC

 

--查询死锁

SELECT SPID=p.spid, 
DBName = convert(CHAR(20),d.name), 
ProgramName = program_name, 
LoginName = convert(CHAR(20),l.name), 
HostName = convert(CHAR(20),hostname), 
Status = p.status, 
BlockedBy = p.blocked, 
LoginTime = login_time, 
QUERY = CAST(TEXT AS VARCHAR(MAX)) 
FROM MASTER.dbo.sysprocesses p 
INNER JOIN MASTER.dbo.sysdatabases d 
ON p.dbid = d.dbid 
INNER JOIN MASTER.dbo.syslogins l 
ON p.sid = l.sid 
CROSS APPLY sys.dm_exec_sql_text(sql_handle) 
WHERE p.blocked = 0 
AND EXISTS (SELECT 1 
FROM MASTER..sysprocesses p1 
WHERE p1.blocked = p.spid)

KILL 70 

 


数据库sql

原文:http://www.cnblogs.com/cn-chenhao/p/4729233.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!