Blogs Technet Com B Mdegre Archive 2009-09-04 SQL Server How
Blogs Technet Com B Mdegre Archive 2009-09-04 SQL Server How
Blogs Technet Com B Mdegre Archive 2009-09-04 SQL Server How
TechNet Blogs > Microsoft SQL Server > How to insert data from one table to another table
Common Tasks
Blog Home Email Blog Author About RSS for comments RSS for posts
RATE THIS
Search
Search TechNet with Bing Search this blog Search all blogs
Recent Posts
Command sp_cycle_agent_errorlog is failing Unable to install SCOM 2012 Reporting Services How configure correctly AlwaysOn readable secondary replica for applicationIntent How to create a dependency between
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
CREATE TABLE [tempdb].[dbo].[myTempTable]( [backup_set_id] [int] NOT NULL, [name] [nvarchar](128) NOT NULL, [filegroup_id] [int] NOT NULL, [filegroup_guid] [uniqueidentifier] NULL, [type] [char](2) NOT NULL, [type_desc] [nvarchar](60) NOT NULL, [is_default] [bit] NOT NULL, [is_readonly] [bit] NOT NULL, [log_filegroup_guid] [uniqueidentifier] NULL ) ON [PRIMARY] GO INSERT INTO [tempdb].[dbo].[myTempTable] ( [backup_set_id] ,[name] ,[filegroup_id] ,[filegroup_guid] ,[type] ,[type_desc] ,[is_default] ,[is_readonly] ,[log_filegroup_guid]) SELECT [backup_set_id] ,[name] ,[filegroup_id] ,[filegroup_guid] ,[type] ,[type_desc] ,[is_default] ,[is_readonly] ,[log_filegroup_guid] FROM [msdb].[dbo].[backupfilegroup] GO SELECT * FROM [tempdb].[dbo].[myTempTable] ; GO DROP TABLE [tempdb].[dbo].[myTempTable] ;
How to create a dependency between two or more Availability Groups AlwaysOn warning: The current WSFC cluster quorum vote configuration is not recommended for this availablity group
Tags
Alw aysOn Av ailability Group
AMO
Analysis Services
Cluster
TIP
Connectiv ity
DBA
DC High Availability
Installation
MSCS Performance
Kerberos
Powershell
Replication
Security
SQL
Server
SSAS
SSIS
T-SQL
Windlows
Cluster
Archives
September 2013 (1) May 2013 (1) April 2013 (2) March 2013 (2) December 2012 (1)
pdfcrowd.com
With this method you don't need to create the table before the insert. Table will be created when data from one table will be inserted from another table. This new table will be created with same data types as selected columns. SELECT INTO can be used to combine data from several tables or views into one table. It can also be used to create a new table that contains data selected from a linked server. Sample:
December 2012 (1) October 2012 (1) September 2012 (1) August 2012 (1) June 2012 (3) April 2012 (6) March 2012 (6) February 2012 (9) January 2012 (3) December 2011 (3) November 2011 (6) October 2011 (7) September 2011 (6) July 2011 (9) June 2011 (6) March 2011 (3) January 2011 (4) December 2010 (3) November 2010 (3) September 2010 (6) August 2010 (6) July 2010 (3) June 2010 (3) May 2010 (2) March 2010 (4) February 2010 (4) January 2010 (2) December 2009 (4) November 2009 (2) October 2009 (4) September 2009 (4) August 2009 (4) July 2009 (4)
SELECT [backup_set_id] ,[name] ,[filegroup_id] ,[filegroup_guid] ,[type] ,[type_desc] ,[is_default] ,[is_readonly] ,[log_filegroup_guid] INTO [tempdb].[dbo].[myTempTable] FROM [msdb].[dbo].[backupfilegroup] GO SELECT * FROM [tempdb].[dbo].[myTempTable] ; GO DROP TABLE [tempdb].[dbo].[myTempTable] ;
SELECT INTO is non-logged operation when the db is in bulk_logged mode.You can use BCP too... Read the the following article for more info. http://support.microsoft.com/?scid=kb;en-us;Q272093 INSERT INTO is recommended over SELECT INTO since the later requires more lock resources.
Don't ask you which one is the best. You have to keep in mine that this both solution are different and adapted to a specific value.
pdfcrowd.com
Leave a Comment
Name
Comment
Post
Comments
Torsten Hi, how do you specify the sort order, as mentioned "- Sort order, if you want to copy the rows in a particular order." INSERT INTO [tempdb].[dbo].[myTempTable] ( ..) SELECT ... FROM [msdb].[dbo].[backupfilegroup] ORDER BY [column1] Won't change anything. 7 Feb 2013 7:47 AM
pdfcrowd.com
I need this, because my table has foreign key relations on itself (col1=col2). so some rows need to be inserted before others.
you just have to add the ORDER BY clause after SELECT * FROM [tempdb].[dbo].[myTempTable] ; and you can chose by with columns. Let me know if you need any help.
Tradem arks
5.6.426.415
pdfcrowd.com