Senior
Määratle primaar- ja välishalud tabelites accounts ja payments
sobes.tech AI
Vastus AI-lt
For the accounts and payments tables, primary and foreign keys are usually defined as follows:
-
accounts:
- Primary Key — a unique identifier for the account, e.g.,
account_id. - Foreign keys in this table are usually absent unless the account is linked to other entities.
- Primary Key — a unique identifier for the account, e.g.,
-
payments:
- Primary Key — a unique identifier for the payment, e.g.,
payment_id. - Foreign Key — a reference to the account from which or to which the payment is made, e.g.,
account_id, referencingaccounts.account_id.
- Primary Key — a unique identifier for the payment, e.g.,
Example SQL definition:
CREATE TABLE accounts (
account_id INT PRIMARY KEY,
account_name VARCHAR(100)
);
CREATE TABLE payments (
payment_id INT PRIMARY KEY,
account_id INT,
amount DECIMAL(10,2),
payment_date DATE,
FOREIGN KEY (account_id) REFERENCES accounts(account_id)
);
This way, account_id in the payments table links the payment to a specific account.