Jump to content

Create a table from another table


subhadip.ghosh

Recommended Posts

Hi All, As per idea i know that the whenever i want to create a new table from another existing table i will have to give the following command-- CREATE TABLE new_table AS (SELECT * FROM old_table); the above command will create a new table with the all the records present in the old table. and if I want to create only the new table without any records from old table I have to put a where clausewhich will never satisfy Like CREATE TABLE new_table AS (SELECT * FROM old_table where 1=2); But I saw a W3schools page where the below has been mentioned { The SELECT INTO statement selects data from one table and inserts it into a different table.The SELECT INTO statement is most often used to create backup copies of tables. SQL SELECT INTO Syntax We can select all columns into the new table: SELECT *INTO new_table_name [iN externaldatabase]FROM old_tablename } Page url is http://www.w3schools...select_into.asp I think before we take the backup using the above sql statement(marked in bold) the new table must be created earlier ? Please clarify... And one more I want ask the concept will be same for all relational database(eg SQL server,oracle,DB2 etc)

Edited by subhadip.ghosh
Link to comment
Share on other sites

I believe that does require that a table already exists. SELECT INTO will work with any database that supports it, if you're wondering if a certain database supports it then check the documentation for the database.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...