-- 创建 Market 数据库
create database Market;
-- 选择 Market
use Market;
create table customers (
c_num int(11) primary key auto_increment not null,
c_name varchar(50) ,
c_contact varchar(50),
c_city varchar(50),
c_birth datetime not null
)
drop table customers -- 删除 customers 表
desc customers -- customers 表的组织架构
-- 将c_contact 移动到c_city后面
alter table customers modify c_contact varchar(50) after c_city
-- 修改 c_name 长度
alter table customers modify c_name varchar(70)
-- 将c_contact 改成 c_phone
alter table customers change c_contact c_phone varchar(50)
-- 添加 c_gender 列
alter table customers add c_gender char(1)
-- 将表名 修改成 customer_info
alter table customers rename customer_info
-- 删除 c_city 字段
alter table customer_info drop c_city
-- 修改数据库的存储引擎为 MyISAM
show create table customer_info -- 先查看当前的存储引擎 innoDB
alter table customer_info engine=MyISAM
-- 选择 Market 数据库
use Market
-- 创建Order表
create table order1(
o_num int(11) auto_increment primary key not null,
o_date date,
c_id int(11),
constraint c_id foreign key(c_id) references customer_info(c_num)
)
-- 选择订单表
SELECT * from Order1
-- 删除外键
alter table Order1 drop foreign key c_id
-- 删除customer_info 表
drop table customer_info