怎么得知sql的执行效率?

bzscs 2003-12-20 10:21:56
我有两种不同的方式实现同一目的,例如:
UPDATE country SET hits=hits+1 WHERE country=@country
IF @@rowcount=0
INSERT INTO country (country,num) VALUES(@country,1)
-
句子的目的是如果已经存在某国家的记录,就给该记录表示访问次数的列加1,否则就新增一条记录,访问次数为1,下面也是一样的结果,但我怎么分析出哪一种方式更好?

select * from country where country=@country
if @@rowcount=0
INSERT INTO country (country,num) VALUES(@country,1)
else
UPDATE country SET hits=hits+1 WHERE country=@country
...全文
43 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
playyuer 2003-12-21
  • 打赏
  • 举报
回复
hits ?= num
playyuer 2003-12-21
  • 打赏
  • 举报
回复
INSERT INTO country (country,num)
select @country,1
from country
where country = @country

update country
set hits = hits + 1
WHERE country = @country


cgsun 2003-12-21
  • 打赏
  • 举报
回复
差不多
美丽心情 2003-12-21
  • 打赏
  • 举报
回复
来学习的~~
INSERT INTO country (country,num)
select @country,1
from country
where country = @country

update country
set hits = hits + 1
WHERE country = @country
没看懂~~
binshan 2003-12-20
  • 打赏
  • 举报
回复
在查询分析器里是很难测试出来的,除非有海量的数据,但从上面的语句看,我想是第一种较好,因为第二种必定比第一种多一次查询!
wzh1215 2003-12-20
  • 打赏
  • 举报
回复
把代码拷到sql分析器中:
用CTRL+L

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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