› MySQL 5.5 Community Server
› MySQL 5.6 Community Server
› Percona Configuration Wizard
› XtraBackup 搭建主从复制
Great Sites on MySQL
› Percona
› MySQL Performance Blog
› Severalnines
推荐管理工具
› Sequel Pro
› phpMyAdmin
推荐书目
› MySQL Cookbook
MySQL 相关项目
› MariaDB
› Drizzle
参考文档
› http://mysql-python.sourceforge.net/MySQLdb.html
Plumes
V2EX  ›  MySQL

如何保持一张表中的两列内容一致?

  •  
  •   Plumes · Aug 28, 2015 · 3761 views
    This topic created in 4046 days ago, the information mentioned may be changed or developed.
    历史遗留原因导致两个系统现在要共用一个数据库,为了减少工作量想把本来在两个系统中含义一样但名字不同的字段同时保留,但时刻保持内容一致,请问能做到么?
    Supplement 1  ·  Aug 28, 2015
    重新理了一下系统架构,用视图完美解决
    12 replies  •  2015-08-28 18:18:29 +08:00
    johnnyb
        1
    johnnyb  
       Aug 28, 2015   ❤️ 1
    视图?
    Honwhy
        2
    Honwhy  
       Aug 28, 2015 via Android
    视图?
    jhdxr
        3
    jhdxr  
       Aug 28, 2015
    LS+1 ,或者触发器?
    jimrok
        4
    jimrok  
       Aug 28, 2015
    事务?
    Plumes
        5
    Plumes  
    OP
       Aug 28, 2015
    @jhdxr mysql 的触发器是不能操作触发器本身所绑定的表的
    Plumes
        6
    Plumes  
    OP
       Aug 28, 2015
    @johnnyb 能详细说一下么?
    jhdxr
        7
    jhdxr  
       Aug 28, 2015   ❤️ 1
    @Plumes
    ```
    if new.a != old.a then
    set new.b=new.a;
    else
    set new.a=new.b;
    end if
    ```
    a 和 b 是那两个要保持一致的字段,为什么不行?
    Plumes
        8
    Plumes  
    OP
       Aug 28, 2015
    @jhdxr 确实可用,感谢已送,不过当时我看到的是这句话 “ MySQL triggers can't manipulate the table they are assigned to ”,是我理解错误了么?
    tabris17
        9
    tabris17  
       Aug 28, 2015
    用视图啊
    jhdxr
        10
    jhdxr  
       Aug 28, 2015   ❤️ 1
    @Plumes 这句话的意思是,例如你对 table_example 添加触发器,不能写
    update table_example set a = new.a where b = new.b
    这样子的语句。
    (也就是说,不能在表的触发器内,触发这张表别的行的变更
    luzjoy
        11
    luzjoy  
       Aug 28, 2015
    触发器 速度比较快
    realpg
        12
    realpg  
       Aug 28, 2015
    TRIGER
    修改某个字段自动同步修改另外一个
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2536 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 08:41 · PVG 16:41 · LAX 01:41 · JFK 04:41
    ♥ Do have faith in what you're doing.