Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2008
    Posts
    8

    Unanswered: Query to create table from existing table

    Hi,
    Can anyone tell me what is the query to create a table say myempfile from an existing table e.g myempdata. I want the column names and data type of myempfile to be same as myempdata but i dont want the values of myempdata in myempfile. The new table should be empty with the same structure as myempdata.

    Regards
    Seena

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    CTAS is the answer:
    Code:
    CREATE TABLE myempfile AS
      SELECT * FROM myempdata
      WHERE 1 = 2;
    WHERE clause is here in order to create an empty table (you could use any "invalid" condition); without it, you'd get data along with table structure.

    Note that constraints (different from NOT NULL) are NOT created in a new table.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •