Create table (structure) from existing table

后端 未结 15 1293
遇见更好的自我
遇见更好的自我 2020-11-27 13:46

How to create new table which structure should be same as another table

I tried

CREATE TABLE dom AS SELECT * FROM dom1 WHERE 1=2

bu

相关标签:
15条回答
  • 2020-11-27 14:15

    If you want to create a table with the only structure to be copied from the original table then you can use the following command to do that.

    create table <tablename> as select * from <sourcetablename> where 1>2;
    
    

    By this false condition you can leave the records and copy the structure.

    0 讨论(0)
  • 2020-11-27 14:16
    Copy the table structure:-
    select * into newtable from oldtable where 1=2;
    
    Copy the table structure along with table data:-
    select * into newtable from oldtable where 1=1;
    
    0 讨论(0)
  • 2020-11-27 14:18

    Its probably also worth mentioning that you can do the following:

    Right click the table you want to duplicate > Script Table As > Create To > New Query Editor Window

    Then, where is says the name of the table you just right clicked in the script that has been generated, change the name to what ever you want your new table to be called and click Execute

    0 讨论(0)
提交回复
热议问题