SQL文でバックアップ
登録日:2025-03-11
更新日:2025-05-14
mysql
テーブル構造、テーブル内のデータがすべて同じバックアップテーブルができます。
create table バックアップテーブル名 as select * from テーブル名;
(例) create table b_user as select * from user
またwhere句をつけることで絞り込んだデータでバックアップテーブルを作成できます。
create table バックアップテーブル名 as select * from テーブル名 where 条件;
(例) create table b_user as select * from user where name = hogehoge
NEW!!
CREATE TABLE newtable LIKE oldtable;
INSERT INTO newtable SELECT * FROM oldtable;