mysql - update tables data from updated table - using merge-sql server and my sql -
i have 2 tables @ least 25 columns.
- customers
- updated_customers
the columns names same.
every day have changes in columns added, deleted , changed want use merge update customers (target table) updated_customers (source table).
merge code is:
merge customers trg using ( select [customerid] ,[type] ,[first_name] ,[last_name] ,[email] ,[phone] ,[sale_status] ,[verification] ,[campname] updated_customers ) src on src.[ customerid] =trg.[ customerid] when matched update set trg.[ customerid]=src.[ customerid] ,trg.[ type]=src.[ type] ,trg.[ first_name]=src.[ first_name] ,trg.[ last_name]=src.[ last_name] ,trg.[ email]]=src.[ email]] ,trg.[ phone]=src.[ phone] ,trg.[ sale_status]=src.[ sale_status] ,trg.[ verification]=src.[ verification] ,trg.[ campname]=src.[ campname] when not matched insert(trg.[customerid],trg.[ type]…) values(src.[ customerid],src.[type]…); end merge customers trg using ( select distinct [customerid] updated_customers) src on src.[customerid] =trg.[customerid] when not matched insert(customerid, …..) values(src.[customerid],…)); end
how can columns @ once?
check changes in row-
if nothing changed – nothing.
if changed – update changes , mark in way.
if added (that not problem).
i have @ least 10 tables same.
Comments
Post a Comment