Mysql如何实现在插入数据时更新其中一个字段?


图片描述

我的sql语句如图,如何在insert的时候更新其中的project_id字段呢?

php thinkphp mysql

断てるもDなし 8 years, 11 months ago

这是要写触发器么。。。

我高我自豪 answered 8 years, 11 months ago

先插入insert 如果成功则 返回自增ID,再执行update 这样可以啊,执行2条SQL就行

MrAllen answered 8 years, 11 months ago

直接给你个例子,相信你能看懂,
insert into users (id,username,password) select null,username,'3333' from users where id=1

W.... answered 8 years, 11 months ago

ON DUPLICATE KEY UPDATE 语法,这个要配合唯一索引使用

Leomg answered 8 years, 11 months ago

Your Answer