The SQL SELECT INTO statement is used to select data from a SQL database table and to insert it to a different table at the same time.
The general SQL SELECT INTO syntax looks like this:
SELECT Column1, Column2, Column3, ,Column n INTO Table2 FROM Table1 |
The list of column names after the SQl Select command determines which columns will be copied, and the table name after the SQL INTO keyword specifies to which table to copy those rows.
If we want to make an exact copy of the data in our Company table, we need the following SQL SELECT INTO statement:
SELECT * INTO Company_copy FROM Company |
The second example i am posting using adventure works database which is sample database from microsoft and can be downloaded from www.codeproject.com for free and can be installed in microsoft sql server 2005/2008.
SELECT * INTO Emp_Table from person.contact |
This command will make a copy of person.contact table into a new table (Emp_table) .

















No comments:
Post a Comment