1

我希望能够使用 PHP 代码创建分区表,而不是在 phpMyAdmin 中手动运行查询,可以这样做吗?

我尽可能使用 MySQLi,因为它比 MySQL 更安全。

目前,我的一张典型表是这样创建的......

$sql = "CREATE TABLE `fred` (
`id` INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`data1` VARCHAR(256),
`data2` VARCHAR(256),
`data3` VARCHAR(256),
`data4` VARCHAR(256)
) CHARACTER SET utf8 COLLATE utf8_general_ci"; 

// Performs the $sql query on the server to create the table
if ($mysqli->query($sql) === TRUE) {
  echo 'Table Fred created successfully';
}
else {
  echo 'Error: '. $mysqli->error;
}

我如何写这个所以它是分区的?

4

1 回答 1

0
CREATE TABLE `invoice_detail2` (
  `id` int(11) NOT NULL,
  `office_code` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
  `order_type` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'purchase order, sale order, transfer in, transfer out, debit note, credit note',
  `in_out_flag` int(1) NOT NULL COMMENT '1=in, 2=out',
  `order_no` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
  `order_date` date NOT NULL,
  `item_no` int(10) NOT NULL,
  `item_qty` int(10) NOT NULL,
  `item_unit` varchar(5) COLLATE utf8mb4_unicode_ci NOT NULL,
  `unit_price_loc` int(12) NOT NULL,
  `unit_price_fc` int(12) NOT NULL,
  `curr_code` int(5) NOT NULL,
  `exch_rate` int(7) NOT NULL,
  `total_price_loc` decimal(15,2) NOT NULL,
  `total_price_fc` decimal(15,2) NOT NULL,
  `include` int(11) NOT NULL,
  `includ_vat_tax` varchar(1) COLLATE utf8mb4_unicode_ci NOT NULL,
  `bar_code` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `item_origin` varchar(4) COLLATE utf8mb4_unicode_ci NOT NULL,
  `item_waranty` int(4) NOT NULL,
  `warranty_type` varchar(1) COLLATE utf8mb4_unicode_ci NOT NULL,
  `agaunest_indent_no` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
  `order_statud` varchar(1) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status_date` date NOT NULL,
  `status_ref` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `ss_creator` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `ss_created_on` datetime NOT NULL,
  `ss_modifier` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `ss_modofier_on` date NOT NULL
)PARTITION BY RANGE (month(order_date)) (
    PARTITION p0 VALUES LESS THAN (1),
    PARTITION p1 VALUES LESS THAN (2),
    PARTITION p2 VALUES LESS THAN (3),
    PARTITION p3 VALUES LESS THAN (4),
    PARTITION p4 VALUES LESS THAN (5),
     PARTITION p5 VALUES LESS THAN (6),
    PARTITION p6 VALUES LESS THAN (7),
    PARTITION p7 VALUES LESS THAN (8),
    PARTITION p8 VALUES LESS THAN (9),
    PARTITION p9 VALUES LESS THAN (10),
     PARTITION p10 VALUES LESS THAN (11),
    PARTITION p11 VALUES LESS THAN (12)
);
于 2020-02-06T10:12:51.813 回答