Is the concept of abstraction relevant for tables in MySQL? If so, how can I do this?

I want to store data on different machines in a MySQL database, which includes both piston and rotary engines.


In OO languages, I can create and extend a superclass of a class Engineto get subclasses of PistonEngineand RotaryEngine.

The subclass PistonEnginewill contain properties such as CylinderNo, PistonBore, and PistonStroke.

The subclass RotaryEnginewill contain properties such as RotorThickness and RotorDiameter.


In MySQL, although I can create two separate tables for reciprocating and rotary engines, respectively, I would prefer to maintain the EngineType field as part of the engine data and store all the data common to both types of engines in a single table.

How can I create my database to avoid data redundancy as much as possible?

+3
source share
2 answers

In this situation, I would create four tables.

One is called EngineTypes, which will have id / value pairs for your engine types 1 rotary 2 pistons

One is called an engine, which contains information that is relevant to both reciprocating and rotating engines. It will have a column containing the engine type identifier.

One table called RotaryEngineDetails that contains all of your data, depending on a rotating motor. He will have a foreign key for the table of your engines.

PistonEngineDetails, .

+2

, , . "" , . , , , , .

, .

, SELECT. , , . , . , ; . (http://www.mysqltutorial.org/introduction-sql-views.aspx)

. .

+1

Source: https://habr.com/ru/post/1718563/


All Articles