SQLServer将表7天前所有数据备份后删除

  1. --拷贝表后清空数据
  2. select * into A4JBCSB_BAK from A4JBCSB;
  3. truncate table A4JBCSB_BAK;
  4. --插入
  5. set identity_insert A4JBCSB_BAK ON;
  6. INSERT INTO A4JBCSB_BAK([TRANSID]
  7.       ,[A0188]
  8.       ,[SIGNED]
  9.       ,[BILL_SUBMITTER]
  10.       ,[BILL_SUBMIT_DATE]
  11.       ,[BILL_CODE]
  12.       ,[CREATOR]
  13.       ,[CREATIONTIME]
  14.       ,[MODIFIER]
  15.       ,[MODIFIEDTIME]
  16.       ,[FORMTYPE]
  17.       ,[SP_FORM]
  18.       ,[A4JBCSB013]
  19.       ,[A4JBCSB014]
  20.       ,[A4JBCSB015]
  21.       ,[A4JBCSB016]
  22.       ,[A4JBCSB017]
  23.       ,[A4JBCSB018]
  24.       ,[A4JBCSB019]) select * from A4JBCSB WHERE DATEDIFF(dd,CREATIONTIME,GETDATE())>=7;
  25. set identity_insert A4JBCSB_BAK OFF;
  26. --删除
  27. delete from A4JBCSB WHERE DATEDIFF(dd,CREATIONTIME,GETDATE())>=7;

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: