Please send your Questions & Answers or Feedback to "mohan@javabook.org"

How to Create a Table from an Existing Table?

The most common way to create a table is with the CREATE TABLE command. However, some database management systems provide an alternative method of creating tables, using the format and data of an existing table. This method is useful when you want to select the data out of a table for temporary modification. It can also be useful when you have to create a table similar to the existing table and fill it with similar data.

 

Syntax:

 

CREATE TABLE new_table_name

(

  field1, field2, field3) AS (SELECT  field1, field2, field3

    FROM old_table_name <WHERE...>

);

 

This syntax allows you to create a new table with the same data types as those of the fields that are selected from the old table. It also allows you to rename the fields in the new table by giving them new names.

Related Posts Plugin for WordPress, Blogger...
Flag Counter