我尝试为 MS SQL 创建一个存储过程
CREATE PROCEDURE YEARENDPROCESSING
AS
DECLARE @VAR AS VARCHAR(9)
DECLARE ACURSOR CURSOR FOR
SELECT COLUMN FROM TABLEA
OPEN ACURSOR
FETCH NEXT FROM ACURSOR INTO @VAR
while @@FETCH_STATUS = 0
BEGIN
INSERT INTO TABLEB SELECT * FROM TABLEC WHERE TABLEC.COLUMNC = @VAR
FETCH NEXT FROM ACURSOR INTO @VAR
END
CLOSE ACURSOR
DEALLOCATE ACURSOR
假设 TableC 列和 TableB 具有相同的列,我得到的结果是 X 行受到影响但在实际表中我什么也看不到。
我有新发现
CREATE PROCEDURE YEARENDPROCESSING
AS
DECLARE @VAR AS VARCHAR(9)
DECLARE ACURSOR CURSOR FOR
SELECT COLUMN FROM TABLEA
OPEN ACURSOR
FETCH NEXT FROM ACURSOR INTO @VAR
while @@FETCH_STATUS = 0
BEGIN
INSERT INTO TABLEB SELECT * FROM TABLEC WHERE TABLEC.COLUMNC = @VAR
DELETE TABLEF where columnf = @VAR
FETCH NEXT FROM ACURSOR INTO @VAR
END
CLOSE ACURSOR
DEALLOCATE ACURSOR
插入会影响 x 行,删除会影响 x 行
但实际情况是在物理表本身中看不到插入结果。我可以看到删除删除查询的结果。有谁知道为什么?