求一触发器实现TABLE中某一字段类似orcal的rownum功能? 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果是ms 2005row_number() over (order by col desc) --在触发器中搞对性能有很大影响.一般前台软件都有这个功能吧create trigger tr_表 on 表for insert,deleteasupdate 表set 字段=(select count(*) from 表 b where a.id>=b.id)from 表 a 如果是 ms 2000select *,(select count(1) from tblname where a.id>=id) as num from tblname a select *,(select count(1) from article_tbl a where a.art_id >= a.art_id) as num from article_tbl aart_id title desc times CreateDate num2 test1 test1 NULL 2007-07-19 00:00:00.000 210 test2 test2 NULL 2007-07-20 00:00:00.000 211 test3 test3 NULL 2007-07-23 00:00:00.000 2我想要的结果是art_id title desc times CreateDate num2 test1 test1 NULL 2007-07-19 00:00:00.000 110 test2 test2 NULL 2007-07-20 00:00:00.000 211 test3 test3 NULL 2007-07-23 00:00:00.000 3当删除其中一条记录时,num也自动更新:art_id title desc times CreateDate num2 test1 test1 NULL 2007-07-19 00:00:00.000 111 test3 test3 NULL 2007-07-23 00:00:00.000 2 select *,(select count(1) from article_tbl a where a.art_id >= a.art_id) as num from article_tbl aart_id title desc times CreateDate num2 test1 test1 NULL 2007-07-19 00:00:00.000 310 test2 test2 NULL 2007-07-20 00:00:00.000 311 test3 test3 NULL 2007-07-23 00:00:00.000 3我想要的结果是art_id title desc times CreateDate num2 test1 test1 NULL 2007-07-19 00:00:00.000 110 test2 test2 NULL 2007-07-20 00:00:00.000 211 test3 test3 NULL 2007-07-23 00:00:00.000 3当删除其中一条记录时,num也自动更新:art_id title desc times CreateDate num2 test1 test1 NULL 2007-07-19 00:00:00.000 111 test3 test3 NULL 2007-07-23 00:00:00.000 2 请教各位几个数据库方面的问题 如何把sql2000创建中的数据库在sql2005中使用 在SQL语句中,能把一个字段中的数据,半角转换成全角麽? 简单问题:统计 从字符串转化为datetime出错 请教:SQL—SERVER无法启动 一个多记录存取的问题。第一次提问,不懂规矩,请多包涵。 无法创建SQLSERVER注册!急,在线等,谢谢。 请问:怎么限定一个一个字段(int类型)的值必须在某个范围之类,如果超过这个范围,改动和插入都出错?谢谢! 数据库操作用中文有冲突吗? 存储过程入参为数组如何分离并循环? 求一个数据库修改的问题
row_number() over (order by col desc)
for insert,delete
as
update 表
set 字段=(select count(*) from 表 b where a.id>=b.id)
from 表 a
select *,(select count(1) from tblname where a.id>=id) as num from tblname a
art_id title desc times CreateDate num
2 test1 test1 NULL 2007-07-19 00:00:00.000 2
10 test2 test2 NULL 2007-07-20 00:00:00.000 2
11 test3 test3 NULL 2007-07-23 00:00:00.000 2我想要的结果是
art_id title desc times CreateDate num
2 test1 test1 NULL 2007-07-19 00:00:00.000 1
10 test2 test2 NULL 2007-07-20 00:00:00.000 2
11 test3 test3 NULL 2007-07-23 00:00:00.000 3当删除其中一条记录时,num也自动更新:
art_id title desc times CreateDate num
2 test1 test1 NULL 2007-07-19 00:00:00.000 111 test3 test3 NULL 2007-07-23 00:00:00.000 2
art_id title desc times CreateDate num
2 test1 test1 NULL 2007-07-19 00:00:00.000 3
10 test2 test2 NULL 2007-07-20 00:00:00.000 3
11 test3 test3 NULL 2007-07-23 00:00:00.000 3我想要的结果是
art_id title desc times CreateDate num
2 test1 test1 NULL 2007-07-19 00:00:00.000 1
10 test2 test2 NULL 2007-07-20 00:00:00.000 2
11 test3 test3 NULL 2007-07-23 00:00:00.000 3当删除其中一条记录时,num也自动更新:
art_id title desc times CreateDate num
2 test1 test1 NULL 2007-07-19 00:00:00.000 111 test3 test3 NULL 2007-07-23 00:00:00.000 2