34,590
社区成员
发帖
与我相关
我的任务
分享
SELECT book.bname ,
book.author ,
book.publish
FROM borrow
INNER JOIN reader ON borrow.rno = reader.rno
INNER JOIN book ON borrow.bno = book.bno
WHERE reader.rname = '李莎'
eclare @name nvarchar(35)
declare @number int
declare my_cursor cursor for --定义游标cursor1
select TOP 5 [name],[number] from [spt_values] --使用游标的对象(跟据需要填入select文)
open my_cursor --打开游标
fetch next from my_cursor into @name,@number --将游标向下移1行,获取的数据放入之前定义的变量@id,@name中
while(@@fetch_status=0) --判断是否成功获取数据
begin
www.2cto.com
--update [spt_values] set [name]=@name+'1'
--where [number]=@number+1 --进行相应处理(跟据需要填入SQL文)
print @name
print @number
print '===='
fetch next from my_cursor into @name,@number --将游标向下移1行
end
close my_cursor --关闭游标
deallocate my_cursor
游标的使用例子
1.输入SQL语句,实现查询借过“软件工程”和“操作系统”两本书的所有读者的信息
select rno,rname --你需要这样标明:表名.字段名字
from borrow(消息 209,级别 16,状态 1,第 1 行
列名 'rno' 不明确。)
inner join reader on borrow.rno=reader.rno
inner join book on borrow.bno=book.bno
where bname='软件工程' and bname='操作系统'
2.输入SQL语句,实现删除“数据结构”的所有借书记录
delete borrowno,bno,rno,pubdate --这后面鞋子段是什么意思 我老师从来没这样教过 我也没见人这样写过 今天第一次
from borrow (消息 102,级别 15,状态 1,第 1 行
',' 附近有语法错误。)
inner join book on borrow.bno=book.bno
where bname='数据结构'
3.输入T-SQL语句,利用游标循环遍历图书表的每条记录,然后关闭并释放游标
declare mycursor cursor for select * from book
open mycursor
fetch @@fetch_status=0 (提示这行有问题)
begin
fetch next from mycursor
end
close mycursor
deallocate mycursor
这个问题 去看看游标的语法吧