我必须优化有 212 个表的数据库。一个表主键充当 94 个表的外键。例如我有这张表:
create table CUSTOMER (
CUSTOMER_ID BIGINT NOT NULL,
CUSTOMER_NAME VARCHAR(255) NOT NULL UNIQUE,
CONTACT_PERSON VARCHAR(255) NOT NULL,
CUSTOMER_EMAIL VARCHAR(255) NOT NULL,
ADDRESS VARCHAR(255),
CITY VARCHAR(255),
PHONE VARCHAR(255),
FAX VARCHAR(255),
constraint CUSTOMER_PK PRIMARY KEY (CUSTOMER_ID)
);
这CUSTOMER_ID
是作为 94 个表的外键的引用。下面以一张表为例:
create table CUSTOMER_STATUS (
CUSTOMER_DETAILS_ID BIGINT NOT NULL,
CUSTOMER_ID BIGINT NOT NULL,
USER_ID BIGINT NOT NULL,
TRIAL_PERIOD BIGINT NOT NULL,
TRIAL_PERIOD_TYPE BIGINT NOT NULL,
EXPIRY_DATE BIGINT NOT NULL,
MAXIMUM_CLIENTS BIGINT NOT NULL,
STATUS BIGINT NOT NULL,
AUTO_AUTHORIZATION BIGINT NOT NULL,
constraint CUSTOMER_STATUS_PK PRIMARY KEY (CUSTOMER_ID,CUSTOMER_DETAILS_ID),
constraint CUSTOMER_STATUS_FK1 FOREIGN KEY (CUSTOMER_ID) references CUSTOMER(CUSTOMER_ID)
);
我需要将所有表的CUSTOMER_ID
数据类型从BIGINT
更改TINYINT
为,但由于外键约束而出现错误。
错误:
mysql> alter table CUSTOMER MODIFY CUSTOMER_ID TINYINT;
ERROR 1025 (HY000): Error on rename of '.\uds7\#sql-670_cdd' to '.\uds7\customer' (errno: 150)
我应该怎么做才能在不影响我的表数据的情况下进行更改?