我剛剛完成了在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