简体   繁体   English

更新数据库中的所有表

[英]Update all the tables in a database

When a user changes his username, I need all the tables to updated to replace his old name with his new one. 当用户更改用户名时,我需要更新所有表以将其旧名称替换为新名称。

I have tried: 我努力了:

mysqli_query($con,"UPDATE * SET UserName='".$username2."'
                 WHERE UserName='".$username."'"); 

But this appears to have only changed one table ( I don't know why it picked this specific table; it is not the first or the last in alphabetical sorting order). 但这似乎只更改了一个表(我不知道为什么选择了这个特定表;它不是字母排序顺序中的第一个或最后一个)。 I tried more than once and the same table kept changing. 我尝试了不止一次,并且同一张桌子一直在变化。

First of all, Why would you have 'usename' stored at multiple places ? 首先,为什么要将“用户名”存储在多个位置? Its a bad design. 这是一个糟糕的设计。

If you still had to do it, then use Primary Key - Foreign Key relation. 如果仍然需要这样做,则使用主键-外键关系。 And on update cascade option. 以及更新级联选项。 See Here: http://dev.mysql.com/doc/refman/5.6/en/innodb-foreign-key-constraints.html 看到这里: http : //dev.mysql.com/doc/refman/5.6/en/innodb-foreign-key-constraints.html

Another option is to have Triggers. 另一种选择是使用触发器。 So that when you update a table in question, the trigger fires and it can perform whatever task you have assigned. 这样,当您更新有问题的表时,触发器将触发,并且触发器可以执行您分配的任何任务。 See Here: http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html 看到这里: http : //dev.mysql.com/doc/refman/5.0/en/create-trigger.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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