我是初学者,在关系方面遇到麻烦。这里我有两个表1:infinity relation
。如果有人帮助我了解如何为他们创建表格,我将不胜感激。
A has id, name attribute
B has id , email password attribute
A:B = 1:infinity.
如何创建?
如果A本身具有无限关系,那么该怎么办呢?
答案 0 :(得分:1)
你在找这样的东西吗?
CREATE TABLE users
(
id INT NOT NULL PRIMARY KEY,
name VARCHAR(64),
user_id INT,
CONSTRAINT fk_users_user_id FOREIGN KEY (user_id) REFERENCES users (id)
);
CREATE TABLE accounts
(
id INT NOT NULL PRIMARY KEY,
user_id INT NOT NULL,
email VARCHAR(64),
password VARCHAR(32),
CONSTRAINT fk_accounts_user_id FOREIGN KEY (user_id) REFERENCES users (id)
);
这是 SQLFiddle 演示