TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

MySQL

MySQL Replicate Table using Existing Table

Overview

In this tutorial, we will learn to replicate table using existing table in MySQL. A new database table can be created using values from an existing table. This helps in saving the time in creating a new table from scratch, when the data needed already exists.

Syntax

CREATE TABLE <new_table_name>
SELECT query

It is good practice to familiarize with the existing table before replicating it. We can use the SHOW CREATE TABLE statement, which is explicitly for reviewing the CREATE TABLE statement used for building the table.

 

SHOW CREATE TABLE Command

For example, to create a new table R_Actor from an existing table Actor from the sakila database. The statement below creates a new table called R_Actor using the output from the SELECT query
and populates it with the data from the existing Actor table.

mysql> CREATE TABLE R_Actor
              -> SELECT * FROM
              -> Actor;

Query OK, 200 rows affected (0.19 sec)
Records: 200 Duplicates: 0 Warnings: 0

We can verify the table creation using the following statements:
The SHOW TABLES, DESCRIBE and SELECT statements confirm the creation of the new table and the table contents.

mysql>SHOW TABLES;

mysql>DESCRIBE <table_name>;

mysql>SELECT * FROM R_Actor;

Replicate Table MySQL

The table created with the CREATE TABLE.. SELECT is created based on the output
of the SELECT query. In this method table options will not be copied.

—

MySQL Tutorials

MySQL Tutorials on this website:

https://www.testingdocs.com/mysql-tutorials-for-beginners/

For more information on MySQL Database:

https://www.mysql.com/

Related Posts

DataGrip Desktop Shortcut

MySQL /

Launch DataGrip on Windows

DataGrip Download

MySQL /

Install DataGrip IDE on Windows 11

MySQL Workbench Windows 11

MySQL /

New MySQL Connection in Workbench

MySQL Command-line Client

MySQL /

Command-Line MySQL Client

Start MySQL Client

MySQL /

Start MySQL Client on Windows 11

‹ MySQL SELECT LIMIT Statement› MySQL CREATE TEMPORARY TABLE Statement

Recent Posts

  • Update draw.io on Windows
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com