justin berfield dating anyone - Sql updating multiple tables simultaneously

Should any right be infringed, it is totally unintentional.

Drop me an email and I will promptly and gladly rectify it.

There are some questions where the answer is no and that is totally fine.

sql updating multiple tables simultaneously-63

I have 2 tables that I need to update: Table A consists of: ID, person Name, Date, status Table B consist of: Person ID, Date, status For every row in A there can be multiple rows in B with the same person ID I need to "loop" over all results from A that the status=2 and update the date and status to 1.

Also, for every row in A that status=2 I need to update all the rows in B that has the same person ID (i.e, A. Person ID) – I need to update date and status to 1 as well. = 2 ) Change item B.status to 1 Change item = Get Date() DECLARE @err int BEGIN TRANSACTION UPDATE B SET status = 1, date = GETDATE() FROM B INNER JOIN A ON B. ID WHERE A.status = 2 SET @err = @@ERROR IF @err = 0 BEGIN UPDATE A SET status = 1, date = GETDATE() WHERE status = 2 SET @err = @@ERROR END IF @err = 0 COMMIT ELSE ROLLBACK Question has been asked before: How to update two tables in one statement in SQL Server 2005? XXXXXX' FROM Table1 T1, Table2 T2 WHERE T1= T2and T1= '011008'; UPDATE Table2 SET Table2.

If not, I would love to know the reason, you want to update two more tables in a single statement. SQLAuthority.com)I’m stunned that this needs discussing in 2017.

There’s probably an article from 20 years covering this.

I wish to use a more convenient approach for good practice. Book ID is very important, without it The Books table update would happen to all rows and not only for the row with the specified id. There's also a couple restrictions for ordering and limiting on multiple table updates you can read about here: ctrl f "join").

Last modified 18-Jan-2020 03:43