修改数据表
1.-- 创建数据库
create database Market_1;
2.-- 链接数据库
use Market_1;
3.-- 创建 customers数据表
create table customers
(
c_num int(11) primary key not null unique auto_increment ,
c_name varchar(50),
c_contact varchar(50),
c_city varchar(50),
c_birth datetime not null
)engine=InnoDB;
4.-- 将c_contact插入到c_brith字段后面
alter table customers MODIFY c_contact varchar(50) after c_birth;
5.-- 将c_name字段数据类型改为varchar类型(70)
alter table customers modify c_name varchar(70);
6.-- 将c_conta字段改为c_phone
alter table customers change c_contact c_phone varchar(70);
7.-- 添加c_gender字段,数据类型为char(1)
alter table customers add c_grnber CHAR(1);
8.-- 将表名修改为customers_info
alter table customers rename to customers_info;
9.-- 删除字段c_city
alter table customers_info drop c_city;
10.-- 修改存储引擎
alter table customers_info engine=MyISAM;
11.-- 创建数据表,在o_num上添加主键约束和自增属性,在c_id字段上添加外键约束,关联customers表中的主键
create table orders
(
o_num int(11) primary key auto_increment,
o_date DATE,
c_id int(11),
constraint fk_orders_customers foreign key(c_id) references customers_info(c_num)
)engine=InnoDB;
12.-- 删除表的外键约束,然后删除表customs
alter table orders drop foreign key fk_orders_customers;
drop table customers_info;