-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstoradbtabeller.txt
47 lines (30 loc) · 1.09 KB
/
storadbtabeller.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Dela stora db tabeller i små db tabeller, till exempel tre små tabeller
Relevant::::::Säkerhetskopiera först!!!::::::::::
CREATE TABLE tabell_del1 LIKE demotable;
CREATE TABLE tabell_del2 LIKE demotable;
CREATE TABLE tabell_del3 LIKE demotable;
Insert, Infoga den första tredjedelen av data i tabell_del1
INSERT INTO tabell_del1
SELECT * FROM demotable WHERE id <= (SELECT MAX(id) FROM demotable) / 3;
INSERT INTO tabell_del2
SELECT * FROM demotable
WHERE id > (SELECT MAX(id) FROM demotable) / 3
AND id <= (SELECT MAX(id) FROM demotable) * 2 / 3;
INSERT INTO tabell_del3
SELECT * FROM demotable
WHERE id > (SELECT MAX(id) FROM demotable) * 2 / 3;
Dela upp tabellen baserat på antalet rader
*** LIMIT och OFFSET *****'
SELECT COUNT(*) FROM demotable;
CREATE TABLE tabell_del1 LIKE demotable;
CREATE TABLE tabell_del2 LIKE demotable;
CREATE TABLE tabell_del3 LIKE demotable;
INSERT INTO tabell_del1
SELECT * FROM demotable
LIMIT 30000 OFFSET 0;
INSERT INTO tabell_del2
SELECT * FROM demotable
LIMIT 30000 OFFSET 30000;
INSERT INTO tabell_del3
SELECT * FROM demotable
LIMIT 30000 OFFSET 60000;