Site icon Database Tutorials

Select Into Statement in SQL Server(TSQL)

 

We use the Select Into Statement to export the data in a table to another table. You can see a few examples below.

First, we are creating a table and inserting some data into it for using in our test:

Example1: We are creating a table named MyTableNew with the following script. We transfer the values in the Name column of the MyTable table to the MyTableNew table. If we put * instead of Name, it will transfer the values of all columns in the table to the new table.
Example 2: With the following script, we create a table named MyTableNew in the TestDB2 database and transfer the values in the Name column of the MyTable of the TestDB database to the MyTableNew of the TestDB2 database.
Example3: We are creating a table named MyTableNew with the following script. We pass the values in the Name column of the MyTable to the MyTableNew . Unlike the above examples, we created the Name column as Name_Surname in the new table.
Example4: If we just want to create the table and don’t want to transfer the data, we can do this with the help of the following script. In the example below, we can only export a specific set of data in the table by writing a condition in the Where condition.

Exit mobile version