MERGEテーブルにはINSERTは使用できない。

mysql> CREATE TABLE animals_merge (
-> id MEDIUMINT NOT NULL AUTO_INCREMENT,
-> name CHAR(30) NOT NULL,
-> PRIMARY KEY (id)
-> ) ENGINE = MERGE;
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO animals_merge (name) VALUES (“dog”),(“cat”),(“penguin”),
-> (“lax”),(“whale”),(“ostrich”);
ERROR 1036 (HY000): Table ‘animals_merge’ is read only

mysql> alter table animals_merge engine=MYISAM;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> INSERT INTO animals_merge (name) VALUES (“dog”),(“cat”),(“penguin”),
(“lax”),(“whale”),(“ostrich”);
Query OK, 6 rows affected (0.00 sec)
Records: 6 Duplicates: 0 Warnings: 0

mysql> select * from animals_merge;
+—-+———+
| id | name |
+—-+———+
| 1 | dog |
| 2 | cat |
| 3 | penguin |
| 4 | lax |
| 5 | whale |
| 6 | ostrich |
+—-+———+
6 rows in set (0.01 sec)

mysql> alter table animals_merge engine=MERGE;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0

※ MERGEに戻すとデータが入っていない。

mysql>

mysql> select * from animals_merge;
Empty set (0.00 sec)

次回は本来の使い方である、2つ以上のテーブルでMERGEテーブルを
作成してみます。

Comments are closed.

Post Navigation