|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
×
用触发器实现用户登录记录下登录信息(sysprocesses)
如果你非要用触发器,不妨看看select * from sysprocesses的内容。可以给sysprocesses表加个触发器来完成你的要求。如果你用7.0,可以看看Microsoft提供的sp_who的过程!如下:
create procedure sp_who --- 1995/11/28 15:48
@loginame sysname = NULL --or 'active'
as
declare @spidlow int,
@spidhigh int,
@spid int,
@sid varbinary(85)
select @spidlow = 0
,@spidhigh = 32767
if ( @loginame is not NULL
AND upper(@loginame) = 'ACTIVE'
)
begin
select spid ,status
,loginame=rtrim(loginame)
,hostname ,blk=convert(char(5),blocked)
,dbname= db_name(dbid),cmd
from master.dbo.sysprocesses
where spid >= @spidlow and spid <= @spidhigh AND
upper(cmd) <> 'AWAITING COMMAND'
return (0)
end
if (@loginame is not NULL
AND upper(@loginame) <> 'ACTIVE'
)
begin
if (@loginame like '[0-9]%') -- is a spid.
begin
select @spid = convert(int, @loginame)
select spid, status,
loginame=rtrim(loginame),
hostname,blk = convert(char(5),blocked),
dbname=db_name(dbid),
cmd
from master.dbo.sysprocesses
where spid = @spid
end
else
begin
select @sid = suser_sid(@loginame)
if (@sid is null)
begin
raiserror(15007,-1,-1,@loginame)
return (1)
end
select spid, status,
loginame=rtrim(loginame),
hostname ,blk=convert(char(5),blocked),
dbname=db_name(dbid),
cmd
from master.dbo.sysprocesses
where sid = @sid
end
return (0)
end
/* loginame arg is null */
select spid,
status,
loginame=rtrim(loginame),
hostname,
blk=convert(char(5),blocked),
dbname=db_name(dbid),
cmd
from master.dbo.sysprocesses
where spid >= @spidlow and spid <= @spidhigh
return (0) -- sp_who |
|