I’m trying to find locks in a database by using sp_lock. However the sp_h
elp
give me an object name as a number. Does anyone have any script which
provide the tables name itself.
Best regards,
Ron
sp_lock to get the object number and then to translate the number to table
name.
SELECT TABLE_CATALOG, TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = OBJECT_NAME(85575343)See if this helps: http://vyaskn.tripod.com/code.htm#sp_lock2
--
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
<Ron>; "hayim" <Ronhayim@.discussions.microsoft.com> wrote in message
news:26AFF5F6-E19A-4D6D-AD8D-D61774DC9B13@.microsoft.com...
> I'm trying to find locks in a database by using sp_lock. However the
sp_help
> give me an object name as a number. Does anyone have any script which
> provide the tables name itself.
> Best regards,
> Ron
> sp_lock to get the object number and then to translate the number to table
> name.
> SELECT TABLE_CATALOG, TABLE_NAME
> FROM INFORMATION_SCHEMA.TABLES
> WHERE TABLE_NAME = OBJECT_NAME(85575343)
>|||If you use the below script, make sure you follow Vyas's directions on his
webpage -- i.e. run it in the database whose locks you are interested in.
If you run it from a different database the script is likely to display the
wrong object names. This is because the object_name function operates in
the context of the current database while sp_lock displays locks from all
databases. Thus if you have locks on tables DB1.dbo.Foo and DB2.dbo.Bar and
lets say that these two tables happen to have the same object id in their
respective databases, then if you run sp_lock2 from DB1 it will display Foo
for both locks; if you run it from DB2 it will display Bar for both locks;
and if you run it from master it will display the name of whatever table in
master has the corresponding object id, or null if master does not have a
table with that id.
Santeri (Santtu) Voutilainen
This posting is provided "AS IS" with no warranties, and confers no rights.
"Narayana Vyas Kondreddi" <answer_me@.hotmail.com> wrote in message
news:uNl$cVyXFHA.3188@.TK2MSFTNGP09.phx.gbl...
> See if this helps: http://vyaskn.tripod.com/code.htm#sp_lock2
> --
> Vyas, MVP (SQL Server)
> SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
>
> <Ron>; "hayim" <Ronhayim@.discussions.microsoft.com> wrote in message
> news:26AFF5F6-E19A-4D6D-AD8D-D61774DC9B13@.microsoft.com...
> sp_help
>