DECLARE FLAG CURSOR scroll dynamic /*scroll表示可随意移动游标指针(否则只能向前),dynamic表示可以读写游标(否则游标只读)*/
FOR SELECT ORDER_NUM FROM ORDERS
OPEN FLAG
DECLARE @order_num int
DECLARE @n int /*定义用户变量*/
SET @n = 1
FETCH NEXT FROM FLAG INTO @order_num
UPDATE ORDERS SET no = @n WHERE CURRENT OF FLAG
WHILE @@fetch_status=0
BEGIN
FETCH NEXT FROM FLAG INTO @order_num
UPDATE ORDERS SET no = @n WHERE CURRENT OF FLAG
SET @n = @n + 1
END
CLOSE FLAG
DEALLOCATE FLAG