如果写这样一个有条件插入数据表的SQL

yeshucheng 2010-07-02 02:27:40
例如表:a
编号 版本号 文件名称 是否下载
1 1.0 x.data 1
2 1.0 y.sql 1
3 1.0 z.zip 1

上面是每次下载一个相应的文件,例如点击下载了文件x.data时,就在表a中就插入相应的这样一条记录,而只有满足:
1.x.data,y.sql,z.zip这三个文件是同一个版本号,而且是否下载标志位都为1的时候,才再到另一个日志表中插入:
insert into loger(id,version,downloaddate) values(1,'1.0','当前时间')。

不知道我是否阐述清楚了?
...全文
125 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
永生天地 2010-07-02
  • 打赏
  • 举报
回复
也许这样可以
create trigger tri_a 
on a
for insert
as
begin
set nocount on
insert into loger(id,version,downloaddate)
select id,d.版本号,getdate()
from inserted d
where (select count(1) from a
where d.版本号=版本号 and 文件名称 in( 'x.data','y.sql','z.zip')
)=3
end
claro 2010-07-02
  • 打赏
  • 举报
回复
.......
feixianxxx 2010-07-02
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 guguda2008 的回复:]

引用 3 楼 feixianxxx 的回复:

SQL code
写个触发器 ...

create trigger trInsA on a
after insert
as
begin
insert into loger(id,version,downloaddate)
select 1,d.版本号,getdate()
from inserted d
where exi……
[/Quote]
猜啊 ~ 大家猜 才是真的猜
bancxc 2010-07-02
  • 打赏
  • 举报
回复
nb 这你都能读懂[Quote=引用 3 楼 feixianxxx 的回复:]
SQL code
写个触发器 ...

create trigger trInsA on a
after insert
as
begin
insert into loger(id,version,downloaddate)
select 1,d.版本号,getdate()
from inserted d
where exists(sele……
[/Quote]
guguda2008 2010-07-02
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 feixianxxx 的回复:]

SQL code
写个触发器 ...

create trigger trInsA on a
after insert
as
begin
insert into loger(id,version,downloaddate)
select 1,d.版本号,getdate()
from inserted d
where exists(select * fro……
[/Quote]
TND这样你都能看懂?
feixianxxx 2010-07-02
  • 打赏
  • 举报
回复
写个触发器 ...

create trigger trInsA on a
after insert
as
begin
insert into loger(id,version,downloaddate)
select 1,d.版本号,getdate()
from inserted d
where exists(select * from a where d.版本号=版本号 and 文件名称 like '%.data' and 是否下载=1)
and exists(select * from a where d.版本号=版本号 and 文件名称 like '%.sql' and 是否下载=1)
and exists(select * from a where d.版本号=版本号 and 文件名称 like '%.zip' and 是否下载=1)
end

try ~
jwdream2008 2010-07-02
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 guguda2008 的回复:]
不清楚。。。。你想干什么。。。。
[/Quote]
guguda2008 2010-07-02
  • 打赏
  • 举报
回复
不清楚。。。。你想干什么。。。。

27,582

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧