我需要执行的数据库操作步骤如下:
1、一个web页面带有uid和str两个参数,当用户访问的时候先
"select key from T1 where userid =" & uid
2、如果纪录存在比较str和rs("key"),如果str中包含字符串rs("key")
"select id from T2 where str = '" & str & "'"
3、如果T2表中纪录存在则
"update T2 set num=num+1, vtime=now() where str='" & str & "'"
如果T2标中纪录不存在则
"insert into T2(str,num,vtime) values('"&str&"',1,now())"
4、获得T2表中对应纪录的id字段值(自增量字段)在并T3表中插入访问纪录
"insert into T3(vid,vtime) values("&id&",now())"
1、一个web页面带有uid和str两个参数,当用户访问的时候先
"select key from T1 where userid =" & uid
2、如果纪录存在比较str和rs("key"),如果str中包含字符串rs("key")
"select id from T2 where str = '" & str & "'"
3、如果T2表中纪录存在则
"update T2 set num=num+1, vtime=now() where str='" & str & "'"
如果T2标中纪录不存在则
"insert into T2(str,num,vtime) values('"&str&"',1,now())"
4、获得T2表中对应纪录的id字段值(自增量字段)在并T3表中插入访问纪录
"insert into T3(vid,vtime) values("&id&",now())"
@uid int,
@str varchar(200)
as
if not exists (select 1 from t1 where userid=uid and @str like '%'+key+'%')
return -1declare @id int
select @id=id from T2 where str=@str
if @id is null
begin
insert into T2(str,num,vtime) values(@str,1,getdate())
select @id=SCOPE_IDENTITY()
else
update T2 set num=num+1, vtime=getdate()
where str=@strinsert into T3(vid,vtime) values(@id,getdate())go
as
begin
if exists(select 1 from T1 where userid=@uid and charindex([key],@str))
begin
if exists(select id from T2 where str=@str)
update T2 set num=num+1,vtime=getdate() where str=@str
else
insert into T2(str,num,vtime) values(@str,1,getdate())
insert into t3(vid,vtime) select id,getdate() from T2 where str=@str
end
end
go
@uID int,
@str varchar(100)
As
Begin
if Exists(Select * From T1 Where userid=@uid and charindex([key],@str))
Begin
if Exists(Select * From T2 Where str=@str)
update T2 set num=num+1, vtime=getdate() where str=@str
else
insert into T2(str,num,vtime) values(@str,1,getdate())
insert into T3(vid,vtime) Select id,getdate() From T2 where str=@str
End
End
exec test @uID=2,@str='test'