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                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
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 1 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 ?    4 Yes 0 No
Mobin Sathupally
 
 
 
  Re: how to know Who Is Blocking Your SQL Server?
Answer
# 3
Solution #1

Simply execute the sp_who2 active and check out the blocked 
by column to check the blocked spid and blocked by spid

Solution #2

select * from sys.sysprocesses where blocked <>0
 
Is This Answer Correct ?    1 Yes 0 No
Xavier K.
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
How do you find the error, how can you know the number of rows effected by last SQL statement?  2
How will oyu test the stored procedure taking two parameters namely first name and last name returning full name?  3
write coding for importing sql data into a word excel... Oracle1
what is physical sort data and logical sort data in index?  2
What are the different types of backup avaible in SQL SErver Emphasis5
Is it possible to create tables in stored procedures using a variable for the table name?  2
what is a cursor and what is its use?  1
wat will be the sql query to extract only last 3 records from table supose table hving thousands for records  16
Which institute is best for SQL Server 2005 Training?  5
In performance wise distinct is good or group by is good? eg:select name from emp group by name; select distinct name from emp; Infosys4
Delete duplicate rows from a table without primary key by using a single query Table Employee empname salary A 200 B 300 A 200 C 400 D 500 D 500 Output should be A 200 B 300 C 400 D 500  2
How many max. conditions can b written under the WHERE clause? Like select * from [tabnam] WHERE (cond1...or..cond2....or...cond3...and.....so on.....??? (upto how much extent))????? SAP-Labs2
What is referential integrity? What are the advantages of it? Digital-Domain3
When do you create cluster and noncluster index? Satyam4
what is hash table Teledata2
What is the difference between login and a user? TCS7
I have student marks in a student table. I need second highest mark .Then what will the query for this? Wipro23
can you any body tell me simple recovery,full recovery,bulk logged recovery where can use?  1
Why Do you want to work in this company? HCL3
what is bit data type? and what are the information that can be stored inside a bit column?  2
 
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