与表的关系

发布于 2025-01-27 16:50:57 字数 982 浏览 2 评论 0原文

目前,我正在为“竞争管理”的作业项目工作,但我对SQL和PHP的了解不多。阿法克(Afaik),我的问题应该是在PHP中进行的锻炼,但我对这些SQL感到好奇。您可以忽略空的varchar。

2个问题

  1. 玩家表与竞争与关联表有关。我必须做某事还是让它成为?

  2. 在比赛表中,您可以看到Config_competition Field ...但是,该领域应包含其中的数据...在运动比赛中,可以说我们有足球运动,游戏电子运动,运动员运动等...在这种情况下,我应该创建一个新表吗?如果是,我该如何与比赛表相关联?

这是组织表(创建竞赛)

CREATE TABLE organisation (
    id_organisation varchar() PRIMARY KEY,
    name_organisation varchar(),
    password varchar()
);

这是竞争表(由组织者创建)

CREATE TABLE competition (
    id_competition varchar() PRIMARY KEY,
    name_competition varchar(),
    config_competition varchar()
);

这是协会表(参与竞赛)

CREATE TABLE association (
    id_association varchar() PRIMARY KEY,
    name_association varchar(),
    password varchar()
);

这是玩家表(由协会注册以参与竞争的参与者)

CREATE TABLE player (
    id_player varchar() PRIMARY KEY,
    name_player varchar()
);

Currently, I'm working for my assignment project called 'Competition Management' and I don't know much about SQL and PHP. Afaik, my questions should be workout in PHP to do this or that but I'm just curious with these SQL. You can ignore the empty varchar.

2 Questions

  1. Player Table is related to Competition and Association Table. Do I have to do something with it or just let it be?

  2. In Competition Table, you can see config_competition field... but, the field should contain data inside it... in term of sport competition, lets say we have football sport, gaming e-sport, athlete sport, and etc... In this case, should I create a new table? If yes, how do I make it related with the Competition Table?

This is Organisation Table (who creates a competition)

CREATE TABLE organisation (
    id_organisation varchar() PRIMARY KEY,
    name_organisation varchar(),
    password varchar()
);

This is Competition Table (Created by Organiser)

CREATE TABLE competition (
    id_competition varchar() PRIMARY KEY,
    name_competition varchar(),
    config_competition varchar()
);

This is Association Table (participate a competition)

CREATE TABLE association (
    id_association varchar() PRIMARY KEY,
    name_association varchar(),
    password varchar()
);

This is Player Table (registered by Association to participate player in a competition)

CREATE TABLE player (
    id_player varchar() PRIMARY KEY,
    name_player varchar()
);

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

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

发布评论

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

评论(1

吹泡泡o 2025-02-03 16:50:58

您需要使用外国键来参考另一个表的主要键。这样,您可以在表之间建立关系。换句话说,您可以连接与彼此之间关系的表。

我建议您使用 mysql workbench 并在第一阶段绘制您的项目图您的项目。之后,您可以创建一个数据库。

另外,在所有这些工作之前,您可能需要查看关系数据模型,一对一,一对一,多一对。然后,您可以选择表之间的适当关系。

对于下面的第二个问题,是答案

CREATE TABLE category (
    category_id int PRIMARY KEY,
    category_name varchar(),
);

CREATE TABLE competition (
id_competition varchar() PRIMARY KEY,
name_competition varchar(),
category_id int FOREIGN KEY REFERENCES category(category_id)

:);

You need to use foreign keys to refer to another table's primary keys. In that way, you can build a relationship between tables. In other words, you can connect the tables that have relationships with each other.

I can suggest you use MySQL workbench and draw an ER diagram of your project in the first phase of your project. After that, you can create a database.

Also, before all these work, you may need to look at the relational data models, one-to-many, one-to-one, and many-to-many. Then you can select the appropriate relations between tables.

For your second question below is an answer:

CREATE TABLE category (
    category_id int PRIMARY KEY,
    category_name varchar(),
);

CREATE TABLE competition (
id_competition varchar() PRIMARY KEY,
name_competition varchar(),
category_id int FOREIGN KEY REFERENCES category(category_id)

);

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