ORACLE:限制文章可能存在的问题数量
在修订论文中卡住了这个问题。我省略了其他关系,因为它们与问题无关。
考虑以下关系: 文章(arID、标题、期刊、问题、年份、起始页、结束页)
我如何制定限制以确保在某一特定问题上发表的文章不得超过 5 篇?
我会做类似的事情吗:
CREATE ASSERTION ArticlesInIssue
CHECK(
(SELECT COUNT(Issue) FROM Article) <= 5);
我认为这不会完全起作用,因为它不会计入特定问题,对吧?那么我是否需要一个 where 子句,或者我在这里走向完全错误的方向? 谢谢, 莫。
Stuck on this question in a revision paper. I've left the other relations out as they're not relevant to the question.
Consider the following relation:
Article(arID, title, journal, issue, year, startpage, endpage)
How would I go about making a constraint that makes sure no more than 5 articles may be published in one particular issue?
Would I do something like:
CREATE ASSERTION ArticlesInIssue
CHECK(
(SELECT COUNT(Issue) FROM Article) <= 5);
I think this wouldn't work fully as it wouldn't be counting for the specific issue, right? So would I need a where clause, or am I going in the totally wrong direction here?
Thanks,
Mo.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编写一个触发器插入时触发。您可以在触发器中编写 SQL 来查询要插入的表并进行检查。您的代码将需要显式回滚插入。
我希望你在问题栏上有一个索引!
write a trigger that fires upon insert. You can write SQL in the trigger to query the table about-to-be-inserted and do that check. Your code will need to explicitly rollback the insert.
I hope you have an index on the issue column!
一种可能的解决方案是添加
articleNo NUMBER(1) NOT NULL
列和约束:和
One possible solution is to add an
articleNo NUMBER(1) NOT NULL
column and the constraints:and