一个关于SQL的简单问题

来源:百度知道 编辑:UC知道 时间:2024/05/24 18:29:28
exists是什么意思

检测行是否存在. 比如:

if exists(select * from TABLE where ID=1)
update TBL set TIME=getdate() where ID=1
else
insert into (ID,TIME) values (1,getdate())

这句中, 用EXTSTS检测是否存在ID为1的记录, 存在, 就更新TIME为当前时间, 不存在, 就插入一条新记录, ID为1.

EXISTS 就是检测括号内指定的查询是否有记录.