sql - 卖房的SQL数据模型
问题描述
我为房地产经纪人(房地产经纪人)设计了一个出售房屋的应用程序,其中财产交易指的是“卖方”和“买方”,他们都需要在数据库中注册为客户。
我不知道如何将销售表链接到客户表,其中“销售”需要引用同时都是注册客户的买家和卖家。
任何指导将不胜感激。
谢谢
解决方案
在代理表中注册卖家,在买家表中注册买家。然后使用外键建立关系
create table client
(
id int primary key,
name varchar(255) not null,
state char(4) not null,
city varchar(255) not null
);
create table sales
(
id int primary key,
buyer_id int not null,
saller_id int not null,
amout double(10, 2)
);
alter table sales
add constraint foreign key (buyer_id) references client (id),
add constraint foreign key (saller_id) references client (id);
推荐阅读
- javascript - Using jQuery to auto calculate amount
- python - How to reset a global variable and pass it to Decorator
- mysql - What is wrong with the following trigger before an update?
- vba - Can I select a group of tables to format in microsoft word using VBA?
- python - Unable to downgrade version of Python package by `pip install -I`
- r - r string cleaning , retain everything before the last underscore
- sql - What's the difference between With and View in Oracle?
- linux - How do I tweak my bash script below for searching sub directories
- reactjs - expect(...).toHaveAttribute is not a function - Why?
- css - 即使代码正确,为什么我的图像没有加载?