简体   繁体   English

如何在 SQL 模式中正确设计 2 个表?

[英]How to correctly design 2 tables in a SQL schema?

I'm new to working with relational databases, my question may sound very simple but bare with me ...我是关系数据库的新手,我的问题听起来很简单,但对我来说很简单......

So I'm trying to design a database based on the following information:所以我试图根据以下信息设计一个数据库:

The landlord records the following data about each property:房东记录每个房产的以下数据:

-Eircode
-Capacity of property i.e. number of tenants it can hold
-Number of tenants currently renting this property
-Cost of rental per tenant per calendar month

The landlord stores the following information about each tenant:房东存储每个租户的以下信息:

-Name
-Email
-Phone number

What am I confused about is the "Cost Of Rental Per tenant" row, in which table to place and how to make the connection.我感到困惑的是“每个租户的租金成本”行,在哪个表中放置以及如何建立连接。 Any help would be greatly appreciate it.任何帮助将不胜感激。

The following is what I got so far:以下是我到目前为止所得到的:

CREATE TABLE property (
    Eircode int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    MaxCapacity int(10) NOT NULL
    NumberOfTenants int(10) NOT NULL
    CostOfRental int(10) NOT NULL
);

CREATE TABLE tenant (
    tenantID int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    tenantName varchar(30) NOT NULL
    tenantEmail varchar(30) NOT NULL
    tenantPhone varchar(30) NOT NULL
);

As I understand your structure you have a table called tennant, wich holds information about tenants.据我了解您的结构,您有一个名为 Tennant 的表,其中包含有关租户的信息。 If the payment is a property of the tenant (the amount this indivual tenant has to pay) you should add that property to that table.如果付款是租户的财产(该个人租户必须支付的金额),您应该将该财产添加到该表中。

Alternatively you could say the rent is for the whole property, and these costs are shared equally by each tenant.或者,您可以说租金是针对整个物业的,这些费用由每个租户平均分摊。 That way you would compute that outside the database.这样你就可以在数据库之外计算它。

Also I would not set the attribute NOT NULL to each value.此外,我不会将属性 NOT NULL 设置为每个值。 Maybe you do not have an email address, therefor you may want to add a value there.也许您没有电子邮件地址,因此您可能想在那里添加一个值。

To connect the information you should set a table to make the connection.要连接信息,您应该设置一个表来进行连接。 This contains of two columns (ID_property , ID_tenant)这包含两列(ID_property,ID_tenant)

Hope this will help you at least a bit.希望这至少会帮助你一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM