SQL to create a new table from an existing table

Source: Internet
Author: User

SQL creates a new table from an existing table, the new table structure is the same as the existing table structure, but not the data in the existing table!

The execution of DML statements depends on the database type:

SQLITE-----Copy table structure and data to the new table create table Table_new as SELECT * from table_old;-----Copy table structure only to new table CREATE TABLE table_new as SELECT * F ROM table_old WHERE 1=0;oracle:-----Copy table structure and data to new table CREATE table T_new as SELECT * from Table_old;          -----Copy only the table structure to the new table create table T_new as SELECT * from Table_old WHERE 1=0; MYSQL:-----Copy table structure and data to a new table CREATE TABLE t_new SELECT * FROM t_old-----Copy table structure only to new table CREATE TABLE t_new SELECT * from T_old WHERE 1=2 ---No db instance, find data DB2:-----Copy table structure and data to new table CREATE table Table_name_new as (SELECT * from Table_name_old) DEFINITION only;-- Inserting data insert INTO t_new (SELECT * from Table_name_old); SQL Server:-----Copy table structure and data to new table select * into t_new from t_old;-----Copy table structure only to new table                 SELECT * to T_new from T_old WHERE 1=2;



SQL to create a new table from an existing table

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.