Get the App
SLTechnology News&Howtos  ›  Database  › 

MSSQL and MYSQL replicate table structure and data

Shulou Source: shulou.com Published: 2022-06-01 18:27:34 09月14日 Update

MSSQL:

Copy only the table structure:

Select * into new.table from old.table where vend_id=10;-the condition cannot be established. The primary key and other information should be rebuilt.

Copy the old table data to an existing new table (assuming the structure is the same):

Insert into new.table (field 1.) Select * from old.table [where]

Copy the entire table, primary key and other information to rebuild

Select * into new.table from old.table

MYSQL:

1. Only copy the table structure, the primary key and other information is not lost:

CREATE TABLE new.table LIKE old.table

Show create table old watch

This lists the creation commands for the old table. We just need to copy the command and change the name of table to create an identical table.

two。 Copy the old table data to the new table, rebuild the index, self-growth, etc.:

CREATE TABLE new.table SELECT * FROM old.table

3. Make a complete copy of a table:

First create an identical table structure, and then copy the data:

Create table new table name like old table name

Insert into new table name select * from old table name;-- copy all

New insert into table name (column 1, column 2, etc.) Select column 1, column 2. From old table name;-- partial copy

Tags: Structure data information commands identical name field copy condition index part build one grow Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Docker Shulou Tech Info Shulou Technology Redmi