# How to create a table TAB2 having same attributes & columns as for table TAB1

DB2DatabaseBig Data Analytics

#### Oracle DB Online Training

41 Lectures 8.5 hours

#### Oracle DB 12c Online Training

33 Lectures 7 hours

#### Cosmos DB

30 Lectures 1 hours

DB2 gives us an option to copy the structure of an existing table to a new table. To copy the attributes and column of table TAB1 to a new table TAB2 we can use the following command−

CREATE TABLE DBSET1.TAB2
LIKE DBSET1.TAB1

The CREATE TABLE reserved words are followed by table name. The table name needs to be qualified by a database in which it will reside. In this case this new table is TAB2 and its database is DBSET1.

The LIKE parameter is used after that followed by the name of the original table qualified by its database i.e. DBSET1.TAB1

The important point to note here is, primary and foreign keys are not inherited automatically and we have to define them using the ALTER table command on the new table.

Updated on 12-Sep-2020 14:13:49