table structure in server1:
CREATE TABLE t1 (
a int NOT NULL,
b char(10) NOT NULL,
c varchar(100) DEFAULT '',
PRIMARY KEY (a,b),
KEY idx_a_b (a,b)
)
table structure in server2:
CREATE TABLE t1 (
a int(11) NOT NULL AUTO_INCREMENT,
b char(10) DEFAULT NULL COMMENT '保证金',
c varchar(100) NOT NULL DEFAULT '',
d datetime DEFAULT NULL,
e datetime DEFAULT NULL,
PRIMARY KEY (a),
KEY idx_b_c (b,c)
)
--changes-for=server1 result :
ALTER TABLE test.t1
DROP PRIMARY KEY,
DROP PRIMARY KEY,
DROP INDEX idx_a_b,
ADD PRIMARY KEY(a),
ADD INDEX idx_b_c (b,c),
CHANGE COLUMN a a int(11) NOT NULL AUTO_INCREMENT,
ADD COLUMN e datetime NULL,
ADD COLUMN d datetime NULL AFTER c,
CHANGE COLUMN c c varchar(100) NOT NULL DEFAULT '',
CHANGE COLUMN b b char(10) NULL COMMENT '保证金',
AUTO_INCREMENT=3, COLLATE=utf8_general_ci;
If it is a federated primary key, "drop primary key" will generate multiple primary keys
table structure in server1: CREATE TABLE
t1
(a
int NOT NULL,b
char(10) NOT NULL,c
varchar(100) DEFAULT '', PRIMARY KEY (a
,b
), KEYidx_a_b
(a
,b
) )table structure in server2: CREATE TABLE
t1
(a
int(11) NOT NULL AUTO_INCREMENT,b
char(10) DEFAULT NULL COMMENT '保证金',c
varchar(100) NOT NULL DEFAULT '',d
datetime DEFAULT NULL,e
datetime DEFAULT NULL, PRIMARY KEY (a
), KEYidx_b_c
(b
,c
) )--changes-for=server1 result : ALTER TABLE
test
.t1
DROP PRIMARY KEY, DROP PRIMARY KEY, DROP INDEX idx_a_b, ADD PRIMARY KEY(a
), ADD INDEX idx_b_c (b,c), CHANGE COLUMN a a int(11) NOT NULL AUTO_INCREMENT, ADD COLUMN e datetime NULL, ADD COLUMN d datetime NULL AFTER c, CHANGE COLUMN c c varchar(100) NOT NULL DEFAULT '', CHANGE COLUMN b b char(10) NULL COMMENT '保证金', AUTO_INCREMENT=3, COLLATE=utf8_general_ci;If it is a federated primary key, "drop primary key" will generate multiple primary keys