简体   繁体   中英

How do i update columns of two tables?

I have the following structure for Sales and Invoices tables

Sales

  SaleNo int PK
  SaleDt Datetime PK
  Qnty
  UP

Invoices

InvoiceNo int  PK
InvoiceDT Datetime PK
SaleNo int   PK FK
SaleDT datetime PK FK

I want to update the SaleDT of the two table and I need to set it to value '2013-01-31 08:25:38.217'. How do I do this?

try this..

-- First update value in one table, then in other

UPDATE        S
SET           S.SaleDT = 'your value'
FROM          SALE S
INNER JOIN    INVOICE I
ON            S.SaleNO = I.SaleNo


UPDATE      I
SET         I.SaleDT = 'your value'
FROM SALE   S
INNER JOIN  INVOICE I
ON          S.SaleNO = I.SaleNo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM