将主键添加到 sql 视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2041308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 05:01:48  来源:igfitidea点击:

adding primary key to sql view

sqloracleviewprimary-key

提问by Hoax

Reading that

读那

how to do hibernate mapping for table or view without a primary key

如何在没有主键的情况下对表或视图进行休眠映射

I am wondering how to add a primary key to my viewas it is basically just a stored query...?

我想知道如何将主键添加到我的视图中,因为它基本上只是一个存储查询......?

PS: oracle 10g

PS:甲骨文10g

thx

谢谢

回答by APC

We can add a disabledprimary key constraint to a view. That is, the constraint does not fire if an insert or update is run against the view. The database expects integrity to be maintained through constraints on the underlying tables. So the constraint exists solely for the purposes of documentation.

我们可以向视图添加禁用的主键约束。也就是说,如果对视图运行插入或更新,则约束不会触发。数据库希望通过对底层表的约束来维护完整性。因此,该约束仅出于文档目的而存在。

SQL> create view emp_view as select * from emp
  2  /


View created.

SQL> alter view emp_view add constraint vemp_pk primary key (empno) disable
  2  /

View altered.

SQL> 

Caveat: I have never tried this with Hibernate, so I don't know whether it would work in your scenario. However, I do know sites which use Hibernate exclusively against a layer of views, so I presume it does. Please experiment with the syntax and report back.

警告:我从未在 Hibernate 中尝试过这个,所以我不知道它是否适用于您的场景。但是,我确实知道专门针对视图层使用 Hibernate 的站点,所以我认为它确实如此。请尝试语法并报告。