0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQLでのテーブルを入れ替えるメモ

0
Posted at

内容

現行テーブルを[テーブル名]_oldとして残し、[テーブル名]を作成する。

手順

①tmpテーブルを作成

Mysql
CREATE TABLE IF NOT EXISTS [テーブル名]_tmp LIKE [テーブル名];
(仮)TRUNCATE TABLE [テーブル名]_tmp;

②tmpテーブルにデータ投入

③oldテーブルを削除

Mysql
DROP TABLE IF EXISTS [テーブル名]_old;

④テーブルを入れ替える

Mysql
RENAME TABLE [テーブル名] TO [テーブル名]_old, [テーブル名]_tmp TO [テーブル名];
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?