Important difficulty: five-star
Difficulty: Invisible
The database is designed to reflect your understanding of the business logic.
Database design is good or bad, sometimes determines the success or failure of the project
Points:
Table-to-table relationship (one-to-one, one-to-many, many-to-many)
The data type of each field (numeric, String, datetime) does not have a Boolean type, use tinyint instead, 1 is true, 0 is False
Design database, take commodity as an example
Find the core (center), then step-by-step deployment
Core Products
First of all, to design the field of the commodity table:
Name, price, picture, color, shelf time, various specification parameters, detailed description, inventory, brand, classification.
Brands and commodities are two different things, a concept of the design table: A table represents a kind of information.
If everything is in the same table, then it's easy to get data redundancy-- update exception, delete exception. High coupling resistance.
A concept of software development: low coupling, high cohesion.
Such as:
Brand: apple->1984 Year was born
Item: Iphone6 plus->2014 years ago
Goods and prices are stored in the same table, with this product there is no need to have a price, the brand should be independent of a table to save.
The relationship between brand and commodity can be judged from the following two aspects
A brand has multiple products,
Such as:
Apple has->iphone4->iphone4s->ipad and so on.
One product corresponds to a brand
Such as:
IPhone6 Plus and iphone6s their corresponding brands are apple
From the above analysis, we can analyze the relationship between them is: one-to-many.
The relationship between them can be reflected in the following ways:
1 is called the parent table, and many of the parties call it a child table. You need to add a field to the child table that is associated with the primary key in the primary table, which is the foreign key in the child table.
The Product classification information is also saved to a single table. Commodity classification table.
The main purpose of commodity classification is to die in order to improve the user experience.
Different types of products have different extended attributes, but common classifications are generally inseparable from the following two kinds:
Such as:
Basic information: Attributes of all goods, such as product name, compression chart, and price
Extended information: Different products His extended information is different, such as clothing, materials, colors, workmanship, mobile phone with screen size, operating system, memory size, camera, books with publishers, authors and so on.
Different types of goods, he has different extended attributes.
The first thing you need to do to save these extensions is that there are two types of tables, such as Goods_type and attribute tables, that attribute to the property itself, not a property of a commodity.
The relationship between goods and attributes is like the table structure of our common student management system, as shown in:
The above elective table is for the sake of Jiedo to many problems, need to introduce a third association table.
The table design of the commodity module of this project is as follows:
The----of the thinkphp project of Lei Gung Dog 2 database design