0
0

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とPostgreSQLのテーブルコピー方法の違い

Posted at

今まではPostgreSQLをよく使ってきていました。
今後、MySQLやMariaDBのほうを主に使っていきそうなので、違いを早めに把握しておきたいと思います。

よく使うテーブルコピーです。
コピーしておくと作業前後でテーブルデータの差分比較ができるのでよく使っています。
(さらに作業前後でdumpも取ってます。)

MySQL

2行に分けて実行するようです。
LIKE の使い方が若干慣れないです。

-- テーブルコピー
CREATE TABLE new_table LIKE original_table;
INSERT INTO new_table SELECT * FROM original_table;

PostgreSQL

1行でできます。

-- テーブルコピー
CREATE TABLE new_table AS SELECT * FROM original_table;

雑感

データベースの修正は、いつも細心の注意が必要なので胃が痛いです。。。
上記は保険です。保険。

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?