Table replication statements for MySQL and PostgreSQL

Source: Internet
Author: User

In MySQL, copy the existing table structure to a new table:

Method 1:

Create Table custnew1 like MERs MERS;

In this method, only the structure of the table to be copied and the structure of the new table can be used to add new columns while creating the table. However, the new table retains the index structure of the copied table.

 

Method 2:

Create Table custnew2 (ID int auto_increment not null primary key) Select * from MERs MERS;

This method allows you to add new columns, but it does not retain the index structure of the copied table. The preceding statement not only copies the structure of the table to be copied, but also copies the data. If you do not want to copy data, add the 'where' clause:

Create Table custnew2 (ID int auto_increment not null primary key) Select * from MERs where 1 <> 1;

 

Copy an existing table structure in PostgreSQL:

Select * into custnew from MERs where 1 <> 1;

The above statement only copies the table structure. If you want data to come together, delete the WHERE clause. It also does not retain the index.

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.