MariaDB Tutorial
MariaDB Useful Resources
Selected Reading
- MariaDB - Useful Functions
- MariaDB - Backup Loading Methods
- MariaDB - Backup Methods
- MariaDB - SQL Injection Protection
- MariaDB - Managing Duplicates
- MariaDB - Sequences
- MariaDB - Table Cloning
- MariaDB - Temporary Tables
- Indexes & Statistics Tables
- MariaDB - Alter Command
- MariaDB - Transactions
- MariaDB - Regular Expression
- MariaDB - Null Values
- MariaDB - Join
- MariaDB - Order By Clause
- MariaDB - Like Clause
- MariaDB - Delete Query
- MariaDB - Update Query
- MariaDB - Where Clause
- MariaDB - Select Query
- MariaDB - Insert Query
- MariaDB - Drop Tables
- MariaDB - Create Tables
- MariaDB - Data Types
- MariaDB - Select Database
- MariaDB - Drop Database
- MariaDB - Create Database
- MariaDB - Connection
- MariaDB - PHP Syntax
- MariaDB - Administration
- MariaDB - Installation
- MariaDB - Introduction
- MariaDB - Home
MariaDB Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
MariaDB - Table Cloning
MariaDB - Table Cloning
Some situations require producing an exact copy of an existing table. The CREATE...SELECT statement cannot produce this output because it neglects things pke indexes and default values.
The procedure for a duppcating a table is as follows −
Utipze SHOW CREATE TABLE to produce a CREATE TABLE statement that details the entire structure of the source table.
Edit the statement to give the table a new name, and execute it.
Use an INSERT INTO...SELECT statement if you also need the table data copied.
mysql> INSERT INTO inventory_copy_tbl ( product_id,product_name,product_manufacturer,ship_date) SELECT product_id,product_name,product_manufacturer,ship_date, FROM inventory_tbl;
Another method for creating a duppcate uses a CREATE TABLE AS statement. The statement copies all columns, column definitions, and populates the copy with the source table s data.
Review its syntax given below −
CREATE TABLE clone_tbl AS SELECT columns FROM original_tbl WHERE conditions];
Review an example of its use below −
CREATE TABLE products_copy_tbl AS SELECT * FROM products_tbl;Advertisements