链接数据库中的 2 个属性

发布于 2024-10-01 01:25:05 字数 492 浏览 0 评论 0原文

我们正在寻求建议以找到解决此问题的方法:

我们认为我们有以下数据库表

Article (id, title, content)

我们在此表上存储 2 篇文章

article1(1, title1, content1)
article2(2, title2, content2)

主键是 id,我们想知道是否有一种方法可以“链接” Article2.title 与article1.title。例如,如果文章具有相同的标题,我们只想使用一个条目,因此article2.title应该是一种指向article1.title的指针。系统将在将数据存储到数据库之前检查数据,如果 title2 = title1,则应创建一个链接而不插入 title2。

有没有办法用 Python 和任何数据库管理系统来做到这一点?

这是一个学校项目,因此我们将不胜感激任何帮助,

提前谢谢您:-)

We are looking for advice to find a solution to this problem :

We consider that we have the following database table

Article (id, title, content)

We store 2 articles on this table

article1(1, title1, content1)
article2(2, title2, content2)

The primary key is the id and we want to know if there is a way to "link" the article2.title with the article1.title. For example, if the articles have the same title, we want to use only one entry so article2.title should be a kind of pointer to article1.title. The system will check the data before storing it in the database and if title2 = title1, a link should be created without inserting the title2.

There is a way to do that with Python and any database management system ?

It's for a school project, so any help will be really appreciated

Thank you in advance :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

梦回梦里 2024-10-08 01:25:05

这是 RDBS 101,但我还是会回答。设置一些像这样的模式:

article
    id
    title_id
    content

title
    id
    title

然后您可以使用 INNER JOIN 获取文章和标题。

SELECT
    article.id,
    title.title,
    article.content
FROM article 
INNER JOIN title ON
    title.id = article.title_id

我将把插入内容留给你,但此时它应该非常明显。

至于 CMS 和数据库 ORM,我推荐 FlaskSqlAlchemy 分别。然而,Flask 并不是一个 CMS,而是一个易于学习和使用的轻量级 Web 框架。

This is RDBS 101 but I'll answer anyway. Setup some schema like this:

article
    id
    title_id
    content

title
    id
    title

Then you can get the articles and titles using an INNER JOIN.

SELECT
    article.id,
    title.title,
    article.content
FROM article 
INNER JOIN title ON
    title.id = article.title_id

I'll leave the inserts up to you, but it should be pretty obvious at this point.

As for a CMS and database ORM, I'd recommend Flask and SqlAlchemy respectively. However, Flask isn't a CMS, but rather a lightweight web framework that's easy to learn and use.

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