例如根据对应ID更新对应col的值update A set A.col = B.col from A,B where A.id = b.id
select 1 就是一列常数1 select top 1选第一条 游标: DECLARE authors_cursor CURSOR FOR SELECT * FROM authors OPEN authors_cursor FETCH NEXT FROM authors_cursor
这个呀,楼主可以去看看SQL Server的联机丛书,里面就有关于update语句的详细描述。
定义游标 在程序中是.movefirst,.movenext操作在程序sql server中为 1.定义游标,打开游标,如5楼所述fetch next from 游标名 into @变量... --将游标定义的字段取出赋给变量 while @@fetch_status=0 begin --处理语句 fetch next from 游标名 into @变量... --再取下一条记录 end close 游标名 --关闭游标 deallocate 游标名 --释放已定义的游标
二.update a set x=x2
from xx a
where exists(select 1 from xxx wwhere a.x=x)
能举个例子吗
我对sql不太熟
select 1
代表什么意思
因为我都是用
select top 1 *
这样的方式
不知是不是一样的效果呢
set A.col = B.col
from A,B
where A.id = b.id
select top 1选第一条
游标:
DECLARE authors_cursor CURSOR
FOR SELECT * FROM authors
OPEN authors_cursor
FETCH NEXT FROM authors_cursor
在程序中是.movefirst,.movenext操作在程序sql server中为
1.定义游标,打开游标,如5楼所述fetch next from 游标名 into @变量... --将游标定义的字段取出赋给变量
while @@fetch_status=0
begin
--处理语句
fetch next from 游标名 into @变量... --再取下一条记录
end
close 游标名 --关闭游标
deallocate 游标名 --释放已定义的游标