DECLARE @Hid varchar(50), @Hname varchar(50)
declare contact_cursor cursor for --声明游标
select hotel_id,h_name from hotel where hotel_id<25
open contact_cursor --打开游标
fetch next from contact_cursor into @Hid,@Hname --游标指针下移一行
while @@fetch_status=0 --FETCH语句执行成功
begin
print @Hid + @Hname
fetch next from contact_cursor into @Hid,@Hname
end
CLOSE contact_cursor --关闭游标
DEALLOCATE contact_cursor --释放游标
fetch next from contact_cursor into @Hid,@Hname
这段语句就是把 hotel_id 和 h_name 字段赋值给 @Hid,@Hname
print @Hid + @Hname
就是把hotel表里的hotel_id和h_name字段打印出来