简体   繁体   中英

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. 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. 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)

Hope this will help you at least a bit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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