IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[temp_GetDatabaseName]') AND type in (N'U'))
drop table temp_GetDatabaseName
create Table temp_GetDatabaseName (
spid int,
ecid int,
status nvarchar(100),
loginame nvarchar(100),
hostName nvarchar(255),
blk int,
dbname nvarchar(255),
cmd nvarchar(1000),
request_id int --此字段在SQL 2000 中不存在,只存在于SQL2005
)
declare @dataBaseName nvarchar(128)
insert into temp_GetDatabaseName exec sp_who @@spid
select @dataBasename = dbName from temp_GetDatabaseName
print @dataBasename
drop table temp_GetDatabaseName
create Table temp_GetDatabaseName (
spid int,
ecid int,
status nvarchar(100),
loginame nvarchar(100),
hostName nvarchar(255),
blk int,
dbname nvarchar(255),
cmd nvarchar(1000),
request_id int --此字段在SQL 2000 中不存在,只存在于SQL2005
)
declare @dataBaseName nvarchar(128)
insert into temp_GetDatabaseName exec sp_who @@spid
select @dataBasename = dbName from temp_GetDatabaseName
print @dataBasename