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:
1 2 3 4 5 6 |
Use [TestDB] GO CREATE TABLE [dbo].[MyTable] (Name VARCHAR(25)) GO INSERT INTO [dbo].[MyTable] VALUES ('Nurullah CAKIR'),('Faruk ERDEM') |
1 2 3 |
SELECT [Name] INTO MyTableNew FROM MyTable GO SELECT * FROM MyTableNew |
1 2 3 |
SELECT [Name] INTO TestDB2.dbo.MyTableNew FROM TestDB.dbo.MyTable GO SELECT * FROM TestDB2.dbo.MyTableNew |
1 2 3 |
SELECT [Name] AS [Name_Surname] INTO MyTableNew FROM MyTable GO SELECT * FROM MyTableNew |
1 2 3 |
SELECT [Name] AS [Name_Surname] INTO MyTableNew FROM MyTable Where 1=0 GO SELECT * FROM MyTableNew |