使用外键约束将值插入mysql

时间:2016-11-08 09:55:02

标签: php mysql

我有2个表格:'spen_recipe'和'spen_recipe_type',如下所示

enter image description here

我想根据pk和fk约束同时将值插入spen_recipe和spen_recipe_type。

请建议我查询。

这就是我的尝试:

insert into spen_recipe
 (`user_id`,`recipe_name`,`recipe_title`,`recipe_type`,`cooking_time`,`preparation_time`,`serving_to`,`recipe_desc`,`recipe_photo`,`created_at`,`modified_at`,`published_at`)
values
('2','recipe2','title2',(select `recipe_type_id` from spen_recipe_type),'20','30','4','desc1','image1','2016-11-05 11:21:43','2016-11-05 11:22:43','2016-11-05 11:21:43');

但是需要建议如何从spen_recipe_type中选择recipe_type_id之后继续,因为这两个表在列中都有空值,两者都是空的。

首先要插入spen_recipe_type还是spen_recipe?

0 个答案:

没有答案
相关问题