Update Table 1 if update or delete happens in another Table - sql

I have two tables namely futureOrder_Table and orders. I want to update the date field in futureOrder_Table table when there is a update or delete in order table delivery column. Basically if the order table date changes i also wanna change it in futureTable

Related

how to update the table from the new rows that come to another table every day in sql

I have Table A and its connected to some server that give him the new transactions every day . I created a table B and inserted the data from table A, How I can write a query that make Table B get updated every day from table A with the new transactions.
I have not tried a query
have createdon and updatedon columns on both tables and update the columns whenever records are inserted and updated. This way createdon,updateon columns can be used to retrieve the records

one-to-one tables relationship, linked by the autonumber in the main table

I have a main table that contain the customers details, I built another table that contain for example a yes/no fields about if the customer paid his taxes, the two tables is linked with autonumber from the main table.
I want always to keep them both with the same amount of records (that means every customer has a record in the second table even if the second table has empty record with data only in the primary key field)
I need that cause with missing records I cannot run update query to auto fill the second table and i got an error of validation rule violation.
I use this sql:
update clients LEFT JOIN MonthlyTbl ON clients.SerialNo = MonthlyTbl.serialno
set sReport04='ready';
I have almost 700 records in the main table and only 80 records in the second, and when I run the sql it updates only 80!!!!
Thanks for Help
Please use below query,
update clients set sReport04='ready' where SerialNo in
(select serialno from MonthlyTbl);
here is the right answer
first run the sql:
INSERT INTO monthlytbl ( serialno )
SELECT clients.serialno FROM clients
WHERE (((clients.[serialno]) Not In (select serialno from monthlytbl)));
and then:
select sreport04 from monthlytbl
set sReport04='ready';

SQL query to update one for one

I have table A with one to many relationship to table B. Whenever I do an update I create new record in table A with a new batch of records related created in table B. I had a bug in my code so when new items where being created the order of them was being reversed. I need to write a SQL query to update items in table B related to second item in table A to be the same as the ones related to first item in table A. I hope it makes any sense, will try to illustrate:
A1 -> B - 1234
A2 -> B - 4321
I want to update second set of values from table B to be the same as the ones related to A1 (1234)
You should not think of records order in database table. The only way to specify order of rows is ORDER BY clause in SELECT statement.
Make row_order or idx column in table B and put there required value for each item.
In some cases you will also get different order of B items for the first/source A record when selecting them without specifying order in ORDER BY clause.
Relational database table has no notion about neither row order nor column order.

How do I only update rows in table A with the data which has changed in table B

I'm inserting data into table A. After a few days have past the data in the Table A might be out of date from the live system.
What I want to do is load the rows that would have changed from the live system into say a temp table and update only the rows which have to corresponding GUID to update with the correct data.
I need help with how the update statement should be formatted.
This would update only the column name Table A with column name of TableB with UID matches on both table: Give a try
update set a.name=b.name from TestA a INNER JOIN TestB b on a.UID=b.UID;

Deleting using a join without where

I have two tables. adjustments and transactions. I want to delete all loan adjustments contained in transactions.
There are three corresponding fields to it. Date. ID. Value.
There are no fks. I used a delete join but it didn't work.
However when using a join it asks for me to specify data for trans.id. Trans.date. Trans.value. Is there anyway to forgo the where as I want to delete all of the related entries from adjustments in transactions.
If you want to delete all the row from Transactions table referencing in Adjustments table. There should be a column in Transactions table which references to some column in Adjustments table.
Suppose the ID column in your Transactions table References some ID column in Adjustments table then you would write this delete query something like this...
DELETE FROM Transactions
WHERE EXISTS ( SELECT 1
FROM Adjustments
WHERE ID = Transactions.ID)

Categories