home
training courses
why choose us?
solutions
support
company
LearnItFirst User Forum
Welcome Guest
Search
|
New Posts
|
Members
|
Log In
|
Register
SQL Server Forum - LearnItFirst.com
»
Transact-SQL Programming
»
DML (SELECT, INSERT, UPDATE, DELETE) Questions
»
insert data into 2 tables
insert data into 2 tables
Options
Previous Topic
·
Next Topic
frank.svs
Posted:
Tuesday, August 04, 2009 8:34:05 PM
Rank: Newbie
Joined: 11/20/2007
Posts: 8
Points: -76
Where do you live?: india
Hi All,
In SQL Server, Can we load data into two table from a single table in a single shot?
something like we do it as below:
select * into <tname2> from <tname1>
IS there any way to achieve this?
Thanks in advance.
Back to top
Scott Whigham
Posted:
Monday, August 10, 2009 12:48:08 PM
Rank: Super Mod
Joined: 3/20/2006
Posts: 476
Points: 1,053
Where do you live?: Dallas, TX
Whoa - sorry about that, Frank - I had it in my head that I had replied to this but I don't see it now
Anyway - I'm not 100% clear on your question. The sample code you wrote would only load one table - it's a standard SELECT INTO statement - yet your question seems to be asking if you can insert into two separate tables at the same time. I'm answering this as though this is a SELECT INTO statement just because of your sample code but please correct me if I've answered the wrong question!
Your syntax - the SELECT INTO - does not allow you to just "insert" into a separate table; it requires that the table does NOT exist prior to execution and it will create the table, then insert the rows into it. Example:
Code:
SELECT * INTO MyNewTable FROM dbo.MyExistingTable
In this example, dbo.MyNewTable does not exist prior to running this statement but it will be (a) created, and then (b) the results of the query SELECT * FROM dbo.MyExistingTable will be inserted into it.
Back to top
Users browsing this topic
Guest
Forum Jump
SQL Server Database Administration
- General SQL Database Question & Answer
- Backup, Recovery and Disaster Recovery
- SQL Server Security
- Integration Services (SSIS) and DTS
Transact-SQL Programming
- DML (SELECT, INSERT, UPDATE, DELETE) Questions
- Stored Procedures, Triggers, & Functions
SQL Server Scripts, Code Samples and SSMS Custom Reports
- All SQL Server Versions
- SQL Server 2005/2008
- SQL Server Management Studio Custom Reports
Customer Service
- Video Requests
You
cannot
post new topics in this forum.
You
cannot
reply to topics in this forum.
You
cannot
delete your posts in this forum.
You
cannot
edit your posts in this forum.
You
cannot
create polls in this forum.
You
cannot
vote in polls in this forum.
SQL Server 2005 DBA Training Videos
SQL Server 2008 DBA Training Videos
Email this topic
RSS Feed
Watch this topic
Print this topic
Normal
Threaded