我需要从stdnt表中删除特定学生,并将该学生数据插入包含“ leaving_date”字段的新表stdnt_log中,这将是记录的删除日期

sql = "INSERT INTO stdnt_log SELECT rollno, name, grade, leaving_date FROM stdnt WHERE rollno = ?";

sql = "DELETE FROM stdnt WHERE rollno = ?";

最佳答案

如果可以/想要应用,则更简单的选项是更改stdnt表并添加另一列:deactivation_date

alter table stdnt add deactivation_date date;


停用某人后,只需更新该列即可:

update stdnt set
  deactivation_date = sysdate
  where student_id = some_value;


活跃的学生将是

select * from stdnt where deactivation_date is null;


易于实现,易于维护。退税?表会越来越大,但是嘿,这是Oracle,它可以毫无问题地处理成千上万的行。

09-11 18:15