环境:
=========================================================================
命令:
(1)create database Market;
(2)
create table customers(
c_num int(11) primary key auto_increment,
c_name varchar(50),
c_contact varchar(50),
c_city varchar(50),
c_birth datetime not null
);
(3)
alter table customers modify column c_contact varchar(50) after c_birth;
(4)
alter table customers modify column c_name varchar(70);
(5)
alter table customers change c_contact c_phone varchar(50);
(6)
alter table customers add c_gender char(1);
(7)
alter table customers rename to customers_info;
(8)
alter table customers_info drop column c_city;
(9)
alter table customers_info engine=MyISAM;
alter table customers_info engine=InnoDB;
=========================================================================
(1)
create table orders(
o_num int(11) primary key auto_increment,
o_date date,
c_id int(11),
foreign key (c_id) references customers_info (c_num)
);
补充:InnoDB支持外键,MyISAM不支持外键
没有指定外键约束的名称,就会自动生成一个名称,这个名称不是列名字。
(2)
删除表的约束
#查看创建表的过程
show create table orders;
#删除外键约束
alter table orders drop foreign key orders_ibfk_1;
删除表
drop table customers_info;