Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.3.0 |  CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 



CREATE TABLE LIKE

Description

You can create a table that has the same schema as an existing table by using the CREATE TABLE...LIKE statement.

Column attribute, table constraint, and index are replicated from the existing table. An index name created from the existing table changes according to a new table name, but an index name defined by a user is replicated as it is. Therefore, you should be careful at a query statement that is supposed to use a specific index created by using the USING INDEX.

You cannot create the column definition because the CREATE TABLE...LIKE statement replicates the schema only.

Syntax

CREATE {TABLE | CLASS} <new_table_name> LIKE <old_table_name>

  • new_table_name : A table name to be created.
  • old_table_name : The name of the original table that already exists in the database. The following tables cannot be specified as original tables in the CREATE TABLE…LIKE statement.
    • Partition table
    • Table that contains an AUTO_INCREMENT column
    • Table that uses inheritance or methods  
Example

CREATE TABLE a_tbl(

id INT NOT NULL DEFAULT 0 PRIMARY KEY,

phone VARCHAR(10));

INSERT INTO a_tbl VALUES(1,'111-1111'), (2,'222-2222'), (3, '333-3333');

 

--creating an empty table with the same schema as a_tbl

CREATE TABLE new_tbl LIKE a_tbl;

SELECT * FROM new_tbl;

 

There are no results.

 

;schema a_tbl

 

=== <Help: Schema of a Class> ===

 

 

 <Class Name>

 

     a_tbl

 

 <Attributes>

 

     id                   INTEGER DEFAULT 0 NOT NULL

     phone                CHARACTER VARYING(10)

 

 <Constraints>

 

     PRIMARY KEY pk_a_tbl_id ON a_tbl (id)

 

Current transaction has been committed.

 

;schema new_tbl

 

=== <Help: Schema of a Class> ===

 

 

 <Class Name>

 

     new_tbl

 

 <Attributes>

 

     id                   INTEGER DEFAULT 0 NOT NULL

     phone                CHARACTER VARYING(10)

 

 <Constraints>

 

     PRIMARY KEY pk_new_tbl_id ON new_tbl (id)

 

 

Current transaction has been committed.