【问题标题】:Updateable mysql views可更新的 mysql 视图
【发布时间】:2013-10-14 13:27:12
【问题描述】:

我可以就如何更新视图提供建议吗?这是我创建的视图.. 但是由于存储的功能它不能更新,对吗?加入查询是否也不能更新?和 if 函数?请帮帮我..对不起我的英语。

CREATE 
    ALGORITHM = UNDEFINED 
    DEFINER = `root`@`localhost` 
    SQL SECURITY DEFINER
    VIEW `view_attendance_dgv` AS
    select 
        `tbl_stockholders`.`user_id` AS `user_id`,
        `tbl_images`.`image_template` AS `Image Template`,
        finger_name(`tbl_fingerprints`.`finger`) AS `Enrolled Finger`,
        `tbl_users`.`last_name` AS `Last Name`,
        `tbl_users`.`first_name` AS `First Name`,
        `tbl_users`.`middle_name` AS `Middle Name`,
        if((`tbl_stockholders`.`attendance_status` = 0),
            'Absent',
            'Present') AS `Attendance Status`,
        if((`tbl_stockholders`.`voting_status` = 0),
            'Not Voted',
            'Voted') AS `Voting Status`
    from
        ((((`tbl_stockholders`
        join `tbl_shares` ON ((`tbl_stockholders`.`user_id` = `tbl_shares`.`user_id`)))
        join `tbl_users` ON ((`tbl_stockholders`.`user_id` = `tbl_users`.`user_id`)))
        join `tbl_images` ON ((`tbl_stockholders`.`user_id` = `tbl_images`.`user_id`)))
        join `tbl_fingerprints` ON ((`tbl_stockholders`.`user_id` =         `tbl_fingerprints`.`user_id`)))
    order by `tbl_stockholders`.`user_id`

【问题讨论】:

  • 请阅读此文档页面dev.mysql.com/doc/refman/5.6/en/view-updatability.html,特别注意It is sometimes possible for a multiple-table view to be updatable, assuming that it can be processed with the MERGE algorithm. For this to work, the view must use an inner join (not an outer join or a UNION). Also, only a single table in the view definition can be updated, so the SET clause must name only columns from one of the tables in the view.

标签: mysql workbench


【解决方案1】:

http://dev.mysql.com/doc/refman/5.6/en/create-view.html

要使视图可更新,视图中的行与基础表中的行之间必须存在一对一的关系。还有某些其他构造使视图不可更新。

更多细节在这里:

http://dev.mysql.com/doc/refman/5.6/en/view-updatability.html

是的,我相信您的查询,您对JOINs 和函数的使用使您的视图不可更新。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-03
    • 2011-12-26
    • 1970-01-01
    • 2019-02-19
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多