Select into in sql server

Home
Donate
All
People & Blogs
Entertainment
Music
Gaming
Education
Howto & Style
News & Politics
Science & Technology
Film & Animation
Sports
Comedy
Autos & Vehicles
Nonprofits & Activism
Travel & Events
Pets & Animals

select into existing table sql server
insert into select only some columns
select into copy table structure
select into schema only
select into from multiple tables
select into from two tables
select into from external database
select into from different server
select into from one server to another

In this video we will discuss the power and use of SELECT INTO statement in SQL Server.

The SELECT INTO statement in SQL Server, selects data from one table and inserts it into a new table.

SELECT INTO statement in SQL Server can do the following
1. Copy all rows and columns from an existing table into a new table. This is extremely useful when you want to make a backup copy of the existing table.
SELECT * INTO EmployeesBackup FROM Employees

2. Copy all rows and columns from an existing table into a new table in an external database.
SELECT * INTO HRDB.dbo.EmployeesBackup FROM Employees

3. Copy only selected columns into a new table
SELECT Id, Name, Gender INTO EmployeesBackup FROM Employees

4. Copy only selected rows into a new table
SELECT * INTO EmployeesBackup
FROM Employees WHERE DeptId = 1

5. Copy columns from 2 or more table into a new table
SELECT * INTO EmployeesBackup
FROM Employees
INNER JOIN Departments
ON Employees.DeptId = Departments.DepartmentId

6. Create a new table whose columns and datatypes match with an existing table.
SELECT * INTO EmployeesBackup
FROM Employees WHERE 1 = 2

7. Copy all rows and columns from an existing table into a new table on a different SQL Server instance. For this, create a linked server and use the 4 part naming convention
SELECT * INTO TargetTable
FROM [SourceServer].[SourceDB].[dbo].[SourceTable]

Please note : You cannot use SELECT INTO statement to select data into an existing table. For this you will have to use INSERT INTO statement.

INSERT INTO ExistingTable (ColumnList)
SELECT ColumnList FROM SourceTable

Text version of the video
http://csharp-video-tutorials.blogspot.com/2015/09/select-into-in-sql-server.html

Slides
http://csharp-video-tutorials.blogspot.com/2015/09/select-into-in-sql-server_14.html

All SQL Server Text Articles
http://csharp-video-tutorials.blogspot.com/p/free-sql-server-video-tutorials-for.html

All SQL Server Slides
http://csharp-video-tutorials.blogspot.com/p/sql-server.html

Full SQL Server Course
https://www.youtube.com/playlist?list=PL4cyC4G0M1RQ_Rm52cQ4CcOJ_T_HXeMB4

All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd

All Dot Net and SQL Server Tutorials in Arabic
https://www.youtube.com/c/KudvenkatArabic/playlists

By using our services, you agree to our Privacy Policy.
Powered by Wildsbet.

© 2021 vTomb

By using our services, you agree to our Privacy Policy.
Got it