2

嗨,我有两张桌子,即

sms(Message,sms_index...columns) 
c_paid_bribe(c_addi_info,....)

我想要做的是将 sms 表的 Message 列的值插入到 c_paid_bribe 表的 c_addi_info 列中,只要将新值插入到 sms 表中。我试过这个

$query=mysql_query("insert into bd_paid_bribe(c_addi_info) select Message from sms");

但是当插入一个新值并且我运行 .php 文件时,已经存在的值也再次插入到表中.....

4

2 回答 2

1
Q: what i want to do is to insert the values of Message column of sms table into c_addi_info column of c_paid_bribe table automatically whenever a new value is inserted into sms table. 

答:如果您想在另一个表发生更改时更新一个表(并且,无论出于何种原因,您不能简单地在应用程序中执行此操作),然后使用“触发器”:

http://net.tutsplus.com/tutorials/databases/introduction-to-mysql-triggers/

Q: But when a new value is inserted and i run the .php file the already existed values are also inserting into the table again.....

A:你想要一个“upsert”。例如:

如果存在,我如何在 MySQL 中更新,如果不插入(又名“upsert”或“merge”)?

于 2012-04-14T05:47:24.403 回答
0

您要做的只是在一个事务中进行两个查询。这就是交易的用途。有关如何执行此操作的示例,请参见此处: PHP + MySQL 事务示例

于 2012-04-14T05:54:18.977 回答