Basically the PARTITION BY creates a table with one or more partitions; in other words, physical tables are created that will be accessed through the specified table.
Exemplifying, when creating the table imovel
and define that it should be supported by the number of rooms pairs and odd, two tables would be created in the BD, "immoveToomsFor" and "immovable", which would be accessible through select * from tabelas
.
This partitioning can be controlled in various ways, only two will be shown to help in understanding, but a list of possibilities and explanations can be found at this link:
PARTITION BY LIST
Can be used when the partition needs to be made based on defined values, for example partitioning the table usuarios
for sex:
CREATE TABLE usuarios
( id NUMBER, nome VARCHAR2(50), idade NUMBER, sexo VARCHAR2(1))
PARTITION BY LIST (sexo) (
PARTITION masculino VALUES ('M'),
PARTITION feminino VALUES ('F')
);
PARTITION BY RANGE
Used when partition needs to be made based on ranges, such as age group:
CREATE TABLE usuarios
( id NUMBER, nome VARCHAR2(50), idade NUMBER, sexo VARCHAR2(1))
PARTITION BY RANGE (idade) (
PARTITION crianca VALUES LESS THAN (18),
PARTITION adulto VALUES LESS THAN (65),
PARTITION idoso VALUES LESS THAN MAXVALUE
);
Understanding the example of the question:
CREATE TABLE employees (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(25) NOT NULL
)
PARTITION BY RANGE(id) (
PARTITION p0 VALUES LESS THAN (5),
PARTITION p1 VALUES LESS THAN (10),
PARTITION p2 VALUES LESS THAN (15),
PARTITION p3 VALUES LESS THAN MAXVALUE
);
Created the table employees
in four other tables:
p0
- records with id
less than 5;
p1
- records with id
greater than or equal to 5 and less than 10;
p1
- records with id
greater than or equal to 10 and less than 15;
p3
- records with id
greater than or equal to 15.
There is some problem the question, it does not make sense, what I can do to improve, I have been being persecuted for some time and taking negative votes every day.
– novic