Sequelize migration - 游标

时间:2015-07-06 09:13:57

标签: mysql node.js sequelize.js

无论如何

sequelize migration中使用光标?我正在尝试创建DML脚本,想法是循环表中的值即。一天使用游标,然后将值插入其他表即。光标内的用餐日。

table : day
dayId
dayName

table : meal
mealId
mealName

table : mealday
mealdayId
dayId
mealId

我应该在游标内使用的insert语句是:

insert into mealday (dayId,mealId) 
select **dayIdFromCursor**,mealId from meal

1 个答案:

答案 0 :(得分:0)

作为一种解决方法,我可以简单地重复insert语句7次(日表中的天数)和硬代码dayId

insert into mealday (dayId,mealId) 
select 1,mealId from meal

insert into mealday (dayId,mealId) 
select 2,mealId from meal

...

insert into mealday (dayId,mealId) 
select 7,mealId from meal