Select into is used to make a new table which will contain the data that is the result set of the query in which it is used. Select Into is generally used to make a backup of a particular data set.
Syntax of Select into statement
SELECT expressions
INTO New_table
FROM table
[WHERE conditions]
|
Parameters or Arguments
Expressions
Name of the columns or calculations that we want to retrieve.
New_table
The new table to create with the selected expressions and their associated definitions New_table must not exist in the database. If the table exists it will throw the errors.
Table
Name of the table from which we want retrieve the data. There must be at least one table listed in the FROM clause.
WHERE conditions
Where clause is Optional. If we want to select the record based on the condition then we need to use where. The conditions that must be met for the records to be selected.
Let’s see the example
Here I am using AdventureWorksDW2008R2
select * into Test1
from DimEmployee
|
See the result.
Test1 table created on the database
See the records
Now see the example of where clause.
select * into Test2
from DimEmployee
where FirstName like 'a%'
|
I am creating a table Test2 which has only the list of employee whose Name start from A.
Where clause we are using for condition.
No comments:
Post a Comment
If you have any doubt, please let me know.