Nested Cursors in Mysql

后端 未结 3 1303
灰色年华
灰色年华 2020-12-24 03:08

I have three tables.
Project(Id), attribute(Id), project_attribute(Id, project_id, attribute_id).

I want to create records in project_at

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-24 03:19

    Quite bluntly, nested cursors are (usually) a terrible idea. You can get what you want directly, without using a cursor, by using a normal CROSS JOIN.

    INSERT INTO proj_attr (project, attribute)
        SELECT p.id AS projectid, a.id AS attributeid
        FROM project p CROSS JOIN attribute a;
    

提交回复
热议问题