Write a query to create an empty table from an existing table?

Answer: An empty table is a table with same structure as the given table. But it does not contain records.

To create an empty table, we have to run a SELECT query so that no records are returned. But we can use the result of this query in CREATE statement to create an empty table.

To get no records in SELECT query, we can give a false condition like 1 > 2 in WHERE clause.

Query will be as follows:

CREATE TABLE Test_table AS
SELECT * from Src_table
WHERE 1 > 2;

Read the full book at www.amazon.com
Posted in SQL, SQL Interview Questions

Leave a Reply

Your email address will not be published. Required fields are marked *

*