Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 从更新的表更新表数据-使用合并sql server和my sql_Mysql_Sql Server_Merge - Fatal编程技术网

Mysql 从更新的表更新表数据-使用合并sql server和my sql

Mysql 从更新的表更新表数据-使用合并sql server和my sql,mysql,sql-server,merge,Mysql,Sql Server,Merge,我有两个至少有25列的表 顾客 最新客户 列名称相同 每天我在专栏里都有一些变化 有些是添加的,有些是删除的,有些是更改的 我想使用merge从更新的客户(源表)更新客户(目标表) 要执行此操作,请合并代码: merge into customers trg using ( select [customerid] ,[type] ,[first_name] ,[Last_Name] ,[Email] ,[Phone] ,[sale_st

我有两个至少有25列的表

  • 顾客
  • 最新客户
  • 列名称相同

    每天我在专栏里都有一些变化 有些是添加的,有些是删除的,有些是更改的 我想使用merge从更新的客户(源表)更新客户(目标表)

    要执行此操作,请合并代码:

    merge into customers trg
    using 
    (
    select 
        [customerid]
        ,[type]
        ,[first_name]
        ,[Last_Name]
        ,[Email]
        ,[Phone]
        ,[sale_status]
        ,[verification]
        ,[campName]
    From updated_customers ) src
    
    on src.[ customerid] =trg.[ customerid] 
    
    when matched then
    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 then
    insert(trg.[customerid],trg.[ type]…)
    values(src.[ customerid],src.[type]…);
    
    END
    
    
    merge into customers as trg
    using 
    (
    select 
        distinct [customerid]
        from updated_customers) src
    
        on src.[customerid] =trg.[customerid] 
    
        when not matched then
        insert(customerid, …..)
        values(src.[customerid],…));
    
    
    
     END
    
    如何一次对所有列执行此操作

    检查行中的更改-

    如果什么都没有改变,那就什么都不做

    如果更改–更新更改并以某种方式进行标记

    如果添加,则(这不是问题)


    我至少有10张桌子可以做同样的事情

    你说使用sql server和mysql是什么意思?我在Linux中有一个数据库(所以我使用mysql)-但我需要使用mssql(公司请求)-我有一个从mysql到mssql的复制,这需要很长时间。我需要更快,所以我想使用merge,只将新数据(更新的或只是新的)传输到mssql。我很高兴听到一些用其他方式做这件事的想法