ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
how to know Who Is Blocking Your SQL Server?
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: how to know Who Is Blocking Your SQL Server?
Answer
# 1
If you have ever monitored any blocking problems in SQL
Server, you know that sp_who only shows you the spid (SQL
Server's internal Process ID) that is causing the blocking
for each spid that is blocked. Often a blocked spid is shown
as causing blocking for another spid. To see the spid (or
spids) that started the whole mess off, execute the
following SQL: 

SELECT p.spid
,convert(char(12), d.name) db_name
, program_name
, convert(char(12), l.name) login_name
, convert(char(12), hostname) hostname
, cmd
, p.status
, p.blocked
, login_time
, last_batch
, p.spid
FROM      master..sysprocesses p
JOIN      master..sysdatabases d ON p.dbid =  d.dbid
JOIN      master..syslogins l ON p.suid = l.suid
WHERE     p.blocked = 0
AND       EXISTS (  SELECT 1
          FROM      master..sysprocesses p2
          WHERE     p2.blocked = p.spid )

We built this into our own version of sp_who, called
sp_hywho. See the listing below. Code for sp_hywho:

if exists (select * from sysobjects 
   where id = object_id('dbo.sp_hywho') 
   and sysstat & 0xf = 4)
   drop procedure dbo.sp_hywho
GO

Create Procedure sp_hywho
(    @vcDBName sysname = NULL )
AS

SET NOCOUNT ON

IF EXISTS ( SELECT 1
   FROM   master..sysprocesses p
   WHERE   p.blocked = 0 
   AND   EXISTS ( SELECT 1
      FROM   master..sysprocesses p2
      WHERE   p2.blocked = p.spid ) )
BEGIN
   PRINT "Blocking caused by:"
   PRINT ""
   SELECT   p.spid
   ,convert(char(12), d.name) db_name
   , program_name
   , convert(char(12), l.name) login_name
   , convert(char(12), hostname) hostname
   , cmd           
   , p.status        
   , p.blocked
   , login_time                  
   , last_batch 
   , p.spid
   FROM   master..sysprocesses p
   JOIN   master..sysdatabases d ON p.dbid =  d.dbid 
   JOIN   master..syslogins l ON p.suid = l.suid 
   WHERE   p.blocked = 0 
   AND   EXISTS ( SELECT 1
      FROM   master..sysprocesses p2
      WHERE   p2.blocked = p.spid ) 
   AND   (p.dbid = DB_ID( @vcDBName ) OR @vcDBName IS NULL)
   ORDER BY 2,IsNull(Ltrim(program_name),"ZZZZZZZZZ"),4,5
   PRINT ""
END

SELECT   p.spid
,convert(char(12), d.name) db_name
, program_name
, convert(char(12), l.name) login_name
, convert(char(12), hostname) hostname
, cmd           
, p.status        
, p.blocked
, login_time                  
, last_batch 
, p.spid
FROM   master..sysprocesses p
JOIN   master..sysdatabases d ON p.dbid =  d.dbid 
JOIN   master..syslogins l ON p.suid = l.suid 
WHERE   (p.dbid = DB_ID( @vcDBName ) OR @vcDBName IS NULL)
ORDER BY 2,IsNull(Ltrim(program_name),"ZZZZZZZZZ"),4,5


SET NOCOUNT OFF

GO

if exists (select * from sysobjects 
   where id = object_id('dbo.sp_hywho') 
   and sysstat & 0xf = 4)
   GRANT EXEC ON dbo.sp_hywho TO PUBLIC
GO
 
Is This Answer Correct ?    0 Yes 0 No
Guest
 
  Re: how to know Who Is Blocking Your SQL Server?
Answer
# 2
Simply execute the sp_who or sp_who2 stored procedure.
In sp_who result set observe the blk column.In sp_who2 
result set observe the blkby column.In both result sets we 
got spids who blocking the server.
 
Is This Answer Correct ?    0 Yes 0 No
Mobin Sathupally
 
 
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
How to Debug a Stored Procedure? Allianz3
what is curser.  7
How to retrieve duplicate rows in a table? How to delete the duplicate entries in a table? Leo-Technologies9
What is SQL server agent? SAP-Labs2
How to Execute an Operating System Command From Within SQL Server ?  2
What is normalization and what are the different forms of normalizations?  1
1.what is the difference between view and cursor? 2.If we do any change in view will it affect the database,similarly when we do changes in cursor will it affect the databse?with certain example?Thanks  2
Can you create UNIQUE and PRIMARY KEY constraints on computed columns in SQL Server 2000? Infosys1
How to Run a Query on a Remote SQL Server?  1
Where do you think the users names and passwords will be stored in sql server?  2
What all db objects can be found in MSDB database of a SQL Server instance? Accenture1
What are the main control-of-flow T-SQL constructs?  1
What is The Use Of TIMESTAMP DataType in SQL Server 2005?  2
How will oyu test the stored procedure taking two parameters namely first name and last name returning full name?  3
What is deadlock and how to avoid the deadlocks. Wipro2
What are primary keys and foreign keys?  3
i want table name basis on column name.  2
What are the type of joins? When do we use Outer and Self joins?  3
create index a on employee(dno) In this,which index was created?  1
how to change column into row in sql ESS1
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com