首页 > 数据库技术 > 详细

数据库表将历史数据分表存储SQL语句

时间:2021-06-02 09:51:54      阅读:17      评论:0      收藏:0      [点我收藏+]

1、MySQL

CREATE TABLE newtable LIKE oldtable;-- 创建表结构

INSERT INTO newtable SELECT * FROM oldtable where create_time>=‘2020-01-01 00:00:00‘ and  create_time<=‘2020-12-31 23:59:59‘;-- 将旧表中2020年的数据插入到新表中

DELETE FROM oldtable where create_time>=‘2020-01-01 00:00:00‘ and  create_time<=‘2020-12-31 23:59:59‘;-- 删除旧表2020年的数据

2、SQL-SERVER

select * into newtable  from oldtable where 1=0;-- 创建表结构

select * into newtable  from oldtable where create_time>=‘2020-01-01 00:00:00‘ and  create_time<=‘2020-12-31 23:59:59‘;-- 创建新表,并将旧表中2020年的数据插入到新表中

DELETE FROM oldtable where create_time>=‘2020-01-01 00:00:00‘ and  create_time<=‘2020-12-31 23:59:59‘;-- 删除旧表2020年的数据

3、ORACLE

create table newtable  as select * from oldtable where 1=0;-- 创建表结构

create table newtable  as select * from oldtable where  create_time>=‘2020-01-01 00:00:00‘ and  create_time<=‘2020-12-31 23:59:59‘;-- 创建新表,并将旧表中2020年的数据插入到新表中

DELETE FROM oldtable where create_time>=‘2020-01-01 00:00:00‘ and  create_time<=‘2020-12-31 23:59:59‘;-- 删除旧表2020年的数据

create table newtable  as select * from oldtable where 1=0;

数据库表将历史数据分表存储SQL语句

原文:https://www.cnblogs.com/xlj227/p/14839760.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!