开发者

Moving information from one table to another and then deleting that data from its origin

I'm making a roster creation tool and one part of the tool is to remove the graduated students from the roster pool and put them into another table called CompletedArchive. After they are copied to the other table I want them to be deleted from the RosterPool table.

INSERT INTO CompletedArchive ( Rate, FullName, Last4, Graduated )
SELECT RosterPool.Rate, RosterPool.FullName, RosterPool.Last4, RosterPool.Graduated
FROM R开发者_运维百科osterPool
WHERE ((RosterPool.Graduated)="Yes");

I cannot find out where to add the DELETE statement and not get an error. Any help is appreciated!


You have to run two different commands here:

INSERT INTO CompletedArchive ( Rate, FullName, Last4, Graduated )
SELECT RosterPool.Rate, RosterPool.FullName, RosterPool.Last4, RosterPool.Graduated
FROM RosterPool
WHERE ((RosterPool.Graduated)="Yes");

and then

DELETE FROM RosterPool
WHERE ((RosterPool.Graduated)="Yes");

Also, make sure you run the two commands within the same transaction. That way you will have the chance to rollback if anything goes wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜