subhadip.ghosh Posted March 11, 2013 Share Posted March 11, 2013 (edited) 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 March 11, 2013 by subhadip.ghosh Link to comment Share on other sites More sharing options...
subhadip.ghosh Posted March 11, 2013 Author Share Posted March 11, 2013 Hey can anyone please reply? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 11, 2013 Share Posted March 11, 2013 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 More sharing options...
subhadip.ghosh Posted March 16, 2013 Author Share Posted March 16, 2013 Thanks for your reply. that is whar I was thinking ,the table must exists in case we use the below SELECT *INTO new_table_name [iN externaldatabase]FROM old_tablename Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now