Tujuannya adalah untuk membuat table backup dari table asli, sehingga ketika ada problem sewaktu mengutak-atik table asli, kita tinggal me-restore data dari table backup ke table asli.
Menggunakan CREATE TABLE LIKE
Untuk membuat table duplikasi di MySQL, anda bisa menggunakan perintah atau sintak di bawah ini:CREATE TABLE nama_table_tujuan LIKE nama_table_asal;
Penjelasan:
- nama_table_tujuan adalah nama table copy-an atau backup.
- nama_table_asal adalah nama table asal.
Dibawah ini adalah langkah-langkah untuk Meng-copy Table di MySQL:
- Login ke Database MySQL.
 # mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.36 MySQL Community Server (GPL) Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
 Pilih database yang akan digunakan, misalkan akademik.
 mysql> use akademik; Database changed 
 
- Buat table TEST_TABLE
 mysql> create table TEST_TABLE( -> kolom_1 varchar(30) -> ); Query OK, 0 rows affected (0.26 sec)
 
- Insert Data ke table TEST_TABLE
 mysql> insert into test_table(kolom_1) values ('Dodol Garut'); Query OK, 1 row affected (0.07 sec)
 
- Tampilkan data dari table TEST_TABLE 
 mysql> select * from test_table; +-------------+ | kolom_1 | +-------------+ | Dodol Garut | +-------------+ 1 row in set (0.00 sec) 
 
- Buat table TEST_TABLE_COPY dengan meng-copy table TEST_TABLE
 mysql> create table test_table_copy like test_table; Query OK, 0 rows affected (0.09 sec) 
 Untuk menampilakn table yang telah dibuat, anda bisa menggunakan perintah di bawah ini.
 mysql> show tables; +--------------------+ | Tables_in_akademik | +--------------------+ | karyawan | | test_baru | | test_table | | test_table_copy | +--------------------+ 4 rows in set (0.00 sec) 
 
- Insert Data ke table TEST_TABLE_COPY menggunakan data dari table TEST_TABLE.
 mysql> insert into test_table_copy -> select * from test_table; Query OK, 1 row affected (0.07 sec) Records: 1 Duplicates: 0 Warnings: 0
 
- Tampilkan data dari table TEST_TABLE_COPY
 mysql> select * from test_table_copy; +-------------+ | kolom_1 | +-------------+ | Dodol Garut | +-------------+ 1 row in set (0.00 sec) 
Referensi
Sekian tutorial singkat tentang Bagaimana Cara Meng-Copy atau Duplikasi Table di MySQL. Semoga bermanfaat & Happy Learning database MySQL.
Apabila anda menyukai tutorial ini, silahkan anda share tutorial ini dengan teman-teman anda yang membutuhkan.
Salam,
Naura-Lab.


 
 
 
 
 
 
 
 
Post a Comment