我刚刚完成了在MySql中的查询中不能使用IF语句之后从地板上摘下我的下巴。没有IF语句,任何人都可以得到什么?!查询中的MySql IF语句
我想要做的是编写一个DML脚本,如果它不存在,则向表添加约束。就像这样:
if (select count(*) from information_schema.table_constraints
where constraint_name='fk_user_user_status') = 0
then
alter table `user`
add constraint fk_user_user_status foreign key (status_id)
references user_status(id);
end if;
在MySql中如何做到这一点?
在此先感谢!
相关:http://stackoverflow.com/questions/3919226/mysql-add-constraint-if-not-exists – viaclectic 2011-03-26 08:54:26