473,789 Members | 3,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Update multiple tables in a single SQL update Statement?

vj
How to Update multiple tables in a single SQL update Statement?

Is there any way out?

vj.

Nov 12 '05 #1
1 22885
vj wrote:
How to Update multiple tables in a single SQL update Statement?

Is there any way out?

vj.

with u1 as (select * from new table(update t1 include (pk2 int, c2 int)
set (c1, pk2, c2)
= (select c1, pk2, c2 from s where t1.pk = s.pk1)
where exists (select 1 from s where t1.pk = s.pk1))),
u2 as (select * from new table(update t2
set c2 = (select c2 from u1 where t2.pk = u1.pk2)
where exists (select 1 from u1 where t2.pk = u1.pk2)))
select count(*) from u2;

Would be nicer with select from merge... one of these days... *sigh*

Of course you can also use

--#SET TERMINTAOR %
BEGIN ATOMIC
FOR x AS SELECT * FROM S DO
UPDATE t1 SET c1 = x.c1 ... ;
UPDATE t2 SET c2 = x.c2 ... ;
END FOR;
END%

(one statement - check the explain :-)

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1991
by: Dave [Hawk-Systems] | last post by:
have a data table that records entries by date(unix timestamp) and customer number. each custnum will have several entries showing a running ledger type snapshot. we have the need to get the most recent entry from not one, but all unique customers, in the most cost effective manner. Table "summary" Attribute | Type | Modifier -----------+---------+---------- custnum | integer | date | integer |
0
1894
by: PMB | last post by:
Thank you in advance for any and all assistance. I have a small program that I'm tracking accounts rec. and I want to keep data, stored by day and have a month end. I have a form called TransactionsNew that has a child form called TransactionsNewDetails. I get a total from the child form to the parent form just fine. What I want to do is take four fields and update three tables. How do I do
1
3102
by: CS | last post by:
I need to update multiple tables from one form using a command button. The info from the different text boxes should then go into the tables. Can someone help me with some example code on how to do this.
0
1156
by: Remy | last post by:
Hi I have an ASP.NET 2.0 DetailView that displays data that has been joined over more than one table. Is it somehow possible to then also Update Data over multiple Tables without using a Stored Procedure? Thanks Remy
5
2391
by: Proaccesspro | last post by:
I have an Access database that contains multiple tables. How can I update a field in all of the tables with a search and replace funtion? In other words, one of the forms has a button that will allow the user to update a primary key that may have been mis-keyed from the start. The idea is that the user would have the ability to correct the mistake by searching for the incorrect key and replacing it with the correct key. To do this, 5 or so...
4
2347
by: dstorms | last post by:
I'm trying to run an update query on multiple tables, and since Access doesn't allow me to update tables from a union query, I'm writing a module as a workaround. So I've set up a temporary recordest (rstName) from the union query (qryEqiupEmplOnly), and construced a Do-Loop that updates the corresponding table. Unfortunately the Update SQL code prompts a compile error "Expected End of statement" and highlights "rstName" (line 28) as the...
2
3067
by: Presto | last post by:
I am making a front end mdb so users can enter new members data. I can then import this into the master database on the backend and erase the existing info on the front end to keep the data reasonably secure. ( I borrowed the code from http://www.databasedev.co.uk/unbound-forms-add-data.html example) I have 4 tables that will be updated from this form: Members ContactInfo Payments
1
3981
by: DMAGIC448 | last post by:
I am trying to figure out how to add records to multiple tables w/ one form. I am making a database for a Home DayCare and I want to add/update records for 5 tables (Student info, Parent 1 Info, Parent 2 info, EC Info, & Vac Info) w/ 1 form. The unique identifier is the students SSN. So how do I tell MS Access to add a records on each table for the matching fields. I've alread made the the form I just need to know how to get MS Access to...
0
9665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10408
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.