create database test;
CREATE DATABASE IF NOT EXISTS test;
CREATE DATABASE IF NOT EXISTS test DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
RENAME DATABASE test TO project;
DROP DATABASE test;
ALTER DATABASE test DEFAULT CHARACTER utf8, DEFAULT COLLATE utf8_general_ci;
CREATE TABLE users (
`id` INT(11),
`username` VARCHAR(20),
`status` TINYINT(1) DEFAULT 1,
`create_time` INT(11) DEFAULT 0
) DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
CREATE TABLE IF NOT EXISTS users (
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR(20) NOT NULL UNIQUE DEFAULT '',
`status` TINYINT(1) NOT NULL DEFAULT 1 COMMENT "1 有效用户 2 禁用用户",
`create_time` INT(11) NOT NULL DEFAULT 0
) DEFAULT CHARSET utf8 COLLATE utf8_general_ci COMMENT "用户表";
CREATE TABLE IF NOT EXISTS users2 (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`username` VARCHAR(20) NOT NULL DEFAULT '',
`status` TINYINT(1) NOT NULL DEFAULT 1 COMMENT "1 有效用户 2 禁用用户",
`create_time` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY(id, username),
INDEX uus(username, status),
UNIQUE username(username)
) DEFAULT CHARSET utf8 COLLATE utf8_general_ci COMMENT "用户表";
SET @@auto_increment_increment = 3;
SET @@auto_increment_offset = 2;
ALTER TABLE users RENAME TO test_users;
ALTER TABLE test_users RENAME TO users;
ALTER TABLE users ADD COLUMN update_time int(11) NOT NULL DEFAULT 0 COMMENT "修改时间" AFTER create_time;
ALTER TABLE users MODIFY username VARCHAR(30) DEFAULT '' COMMENT "用户名";
ALTER TABLE users MODIFY update_time int(11) DEFAULT 0 NOT NULL;
ALTER TABLE users MODIFY username char(20) DEFAULT '';
ALTER TABLE users CHANGE username user_name varchar(20) DEFAULT '';
ALTER TABLE users DROP COLUMN update_time;
ALTER TABLE users ADD INDEX status(`status`);
ALTER TABLE users ADD UNIQUE username(user_name);
ALTER TABLE users ADD UNIQUE(user_name);
ALTER TABLE users ADD INDEX uus(user_name, status);
CREATE INDEX ts ON users(`status`);
CREATE UNIQUE INDEX tss ON users(`status`);
DROP INDEX tss ON users;
ALTER TABLE users DROP INDEX ts;
ALTER TABLE users ADD CONSTRAINT fk_user_type_id FOREIGN KEY(type_id) REFERENCES user_types(id);
ALTER TABLE users DROP FOREIGN KEY fk_user_type_id;
TRUNCATE TABLE users;
CREATE TABLE IF NOT EXISTS orders2 (
`id` BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT "订单主键",
`user_id` INT(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT "用户主键ID",
`goods_id` INT(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT "商品主键ID",
`amount` INT(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT "订单价格[单位:分]",
`pay_amount` INT(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT "订单实际支付金额[单位:分]",
`status` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1 COMMENT "订单状态:1 未支付 2 已支付 3 已退款 4 已评价 5 已取消",
`pay_time` INT(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT "订单支付时间",
`create_time` INT(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT "订单创建时间",
INDEX user_id(`user_id`),
INDEX `status`(`status`),
CONSTRAINT fk_order_users_id FOREIGN KEY(user_id) REFERENCES users(id)
ON DELETE CASCADE
) DEFAULT CHARSET utf8 COLLATE utf8_general_ci COMMENT "用户订单表";