ORACLE:限制文章可能存在的问题数量

发布于 2024-12-28 09:39:05 字数 334 浏览 4 评论 0原文

在修订论文中卡住了这个问题。我省略了其他关系,因为它们与问题无关。

考虑以下关系: 文章(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

万劫不复 2025-01-04 09:39:05

编写一个触发器插入时触发。您可以在触发器中编写 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!

相守太难 2025-01-04 09:39:05

一种可能的解决方案是添加 articleNo NUMBER(1) NOT NULL 列和约束:

UNIQUE (issue, articleNo) 

CHECK (articleNo BETWEEN 1 AND 5)

One possible solution is to add an articleNo NUMBER(1) NOT NULL column and the constraints:

UNIQUE (issue, articleNo) 

and

CHECK (articleNo BETWEEN 1 AND 5)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文