Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 4th, 2009, 08:40 PM
frank.svs frank.svs is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 30 frank.svs User rank is Corporal (100 - 500 Reputation Level)frank.svs User rank is Corporal (100 - 500 Reputation Level)frank.svs User rank is Corporal (100 - 500 Reputation Level)frank.svs User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 h 18 m 43 sec
Reputation Power: 4
T-SQL - Insert data into 2 tables in a single shot

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.

Reply With Quote
  #2  
Old August 27th, 2009, 12:00 PM
kcconnor's Avatar
kcconnor kcconnor is offline
Evil Republican...
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: Probably running over your cat right now...
Posts: 256 kcconnor User rank is Sergeant Major (2000 - 5000 Reputation Level)kcconnor User rank is Sergeant Major (2000 - 5000 Reputation Level)kcconnor User rank is Sergeant Major (2000 - 5000 Reputation Level)kcconnor User rank is Sergeant Major (2000 - 5000 Reputation Level)kcconnor User rank is Sergeant Major (2000 - 5000 Reputation Level)kcconnor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 22 h 36 m 13 sec
Reputation Power: 38
SELECT * INTO T2 FROM T1

This will create a copy of T1 and stick it into T2.

Often used by DBA's to create a backup of a single table prior to modifying the original table... just in case.

The INSERT statement must target a single table.
__________________
IF ADVICE = 'GOOD'
INSERT INTO scales (REPUTATION_POINTS, REASON)
VALUES (+1, 'BECAUSE ITS GOOD TO DO THAT')
END

Reply With Quote
  #3  
Old September 22nd, 2009, 07:41 PM
gregory.owen@hp gregory.owen@hp is offline
Maniac
ASP Free Novice (500 - 999 posts)
 
Join Date: Sep 2003
Location: Sweet Home, Oregon
Posts: 598 gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 14 h 46 m 46 sec
Reputation Power: 37
I suppose that depends on what you mean by "one shot" It is not possible to do it in a single statement (unless you use a trigger on the first table that does an insert into the second table.)

However, if "one shot" means that the insert into both tables happens or doesn't happen together in a single transaction, then sure it is possible:

Code:
BEGIN TRANSACTION
INSERT <table1>.....
INSERT <table2>.....
COMMIT TRANSACTION


While this is not a single statement, the inserts live or die together--either both tables get the data or neither of them get it, so it is "one shot" in that sense.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > T-SQL - Insert data into 2 tables in a single shot


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 9 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek