MySQL数据库管理之如何创建分区表
短信预约 -IT技能 免费直播动态提醒
下面一起来了解下MySQL数据库管理之如何创建分区表,相信大家看完肯定会受益匪浅,文字在精不在多,希望MySQL数据库管理之如何创建分区表这篇短内容是你想要的。
创建分区表
mysql> CREATE TABLE `LINEITEM` (
L_SHIPDATE DATE NULL,
L_ORDERKEY INT NOT NULL,
L_DISCOUNT DECIMAL(10,2) NOT NULL,
L_EXTENDEDPRICE DECIMAL(10,2) NOT NULL,
L_SUPPKEY INT NOT NULL,
L_QUANTITY INT NOT NULL,
L_RETURNFLAG CHAR(1) BINARY NULL,
L_PARTKEY INT NOT NULL,
L_LINESTATUS CHAR(1) BINARY NULL,
L_TAX DECIMAL(10,2) NOT NULL,
L_COMMITDATE DATE NULL,
L_RECEIPTDATE DATE NULL,
L_SHIPMODE CHAR(10) BINARY NULL,
L_LINENUMBER INT NOT NULL,
L_SHIPINSTRUCT CHAR(25) BINARY NULL,
L_COMMENT VARCHAR(44) BINARY NULL,
PRIMARY KEY (`L_ORDERKEY`, `L_LINENUMBER`,`L_SHIPDATE`)
) PARTITION BY RANGE COLUMNS (L_SHIPDATE) (
PARTITION p0 VALUES LESS THAN ('1993-01-01'),
PARTITION p1 VALUES LESS THAN ('1994-01-01'),
PARTITION p2 VALUES LESS THAN ('1995-01-01'),
PARTITION p3 VALUES LESS THAN ('1996-01-01'),
PARTITION p4 VALUES LESS THAN ('1997-01-01'),
PARTITION p5 VALUES LESS THAN ('1998-01-01'),
PARTITION p6 VALUES LESS THAN ('1999-01-01'),
PARTITION p7 VALUES LESS THAN (MAXVALUE)
)
删除
mysql> ALTER TABLE lineitem DROP PARTITION p7;
增加
mysql> ALTER TABLE lineitem ADD PARTITION (PARTITION p7 VALUES LESS THAN ('2000-01-01'));
拆分
mysql> ALTER TABLE lineitem
REORGANIZE PARTITION p0 INTO (
PARTITION p199206 VALUES LESS THAN ('1992-07-01'),
PARTITION p199212 VALUES LESS THAN ('1993-01-01')
);
合并
mysql> ALTER TABLE lineitem REORGANIZE PARTITION p199206,p199212 INTO (
PARTITION p0 VALUES LESS THAN ('1993-01-01')
);
交换分区
mysql> CREATE TABLE `temp1992` (
`L_SHIPDATE` date NOT NULL DEFAULT '0000-00-00',
`L_ORDERKEY` int(11) NOT NULL,
`L_DISCOUNT` decimal(10,2) NOT NULL,
`L_EXTENDEDPRICE` decimal(10,2) NOT NULL,
`L_SUPPKEY` int(11) NOT NULL,
`L_QUANTITY` int(11) NOT NULL,
`L_RETURNFLAG` char(1) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`L_PARTKEY` int(11) NOT NULL,
`L_LINESTATUS` char(1) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`L_TAX` decimal(10,2) NOT NULL,
`L_COMMITDATE` date DEFAULT NULL,
`L_RECEIPTDATE` date DEFAULT NULL,
`L_SHIPMODE` char(10) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`L_LINENUMBER` int(11) NOT NULL,
`L_SHIPINSTRUCT` char(25) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`L_COMMENT` varchar(44) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (`L_ORDERKEY`,`L_LINENUMBER`,`L_SHIPDATE`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
mysql> ALTER TABLE lineitem EXCHANGE PARTITION p0 WITH TABLE temp1992;
Query OK, 0 rows affected (0.24 sec)
看完MySQL数据库管理之如何创建分区表这篇文章后,很多读者朋友肯定会想要了解更多的相关内容,如需获取更多的行业信息,可以关注我们的数据库栏目。
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341