declare @newtablename sysname = 'newtablename';
create table dbo.atesttable(id int);
exec sp_rename 'dbo.atesttable', @newtablename;
select
suser_sname([Transaction SID]) as thelogin,
(select name from sys.database_principals where sid = [Transaction SID]) as thedbuser,
[Begin Time], [End Time],
cast([rowlog contents 0] as nvarchar(max)),
cast([rowlog contents 1] as nvarchar(max))
from sys.fn_dblog(null, null)
where [Transaction ID] in
(
select [Transaction ID]
from sys.fn_dblog(null, null)
where [Lock Information] like '%' + cast(object_id(@newtablename) as varchar(50)) + '%'
intersect
select [Transaction ID]
from sys.fn_dblog(null, null)
where convert(nvarchar(max), [rowlog contents 0]+[rowlog contents 1]+[rowlog contents 2]+[rowlog contents 3]+[rowlog contents 4], 2)
like '%' + convert(nvarchar(max), cast(@newtablename as varbinary(200)), 2) + '%'
--where cast([rowlog contents 1] as nvarchar(max)) like '%' + left(@newtablename, 10) + '%'
);
exec ('drop table ' + @newtablename)
go