이렇게 테이블을 분할해서는 안됩니다. 대신은, 월, 인덱스 컬럼과, 통합 테이블에 모두 넣어 고려 OR 월, 인덱스 열이있는 테이블을 생성하고, 다른 테이블의 행 ID를 참조 :
옵션 1 : 통합 테이블 :
을
CREATE TABLE Unified (
month CHAR(3) NOT NULL,
ix INT NOT NULL DEFAULT 1,
[...],
PRIMARY (month, ix, somethingMore),
CHECK month IN (
'jan', 'feb', 'mar', 'apr', 'may', 'jun',
'jul', 'aug', 'sep', 'oct', 'nov', 'dec')
);
SELECT * FROM Unified where month = 'jan' AND ix = 1;
// select only tables with a "jan" prefix... or "1" suffix.
SELECT * FROM Unified where month = 'jan' OR ix = 1
옵션 2 :이 구조를 수정할 수
CREATE TABLE Partitions (
id INT AUTO_INCREMENT PRIMARY,
month CHAR(3) NOT NULL,
ix INT NOT NULL DEFAULT 1,
CHECK month IN (
'jan', 'feb', 'mar', 'apr', 'may', 'jun',
'jul', 'aug', 'sep', 'oct', 'nov', 'dec'),
INDEX (month, ix)
)
CREATE TABLE Stuff (
partition INT NOT NULL,
[...],
PRIMARY KEY (partition, somethingMore),
FOREIGN KEY fk_Stuff_Partitions (partition) REFERENCES Partitions (id)
)
SELECT * FROM Stuff
INNER JOIN Partitions ON Stuff.partition = Partitions.id
WHERE Partition.month = 'jan' AND Partition.ix = 2;
// select only tables with a "jan" prefix... or "1" suffix.
SELECT DISTINCT * FROM Stuff
INNER JOIN Partitions ON Stuff.partition = Partitions.id
WHERE Partition.month = 'jan' OR Partition.ix = 1;
위치 : 외래 키를 사용? 정규화되지 않았습니다. 매월 테이블을 가져서는 안됩니다. – Leslie