【MySQL作业】DDL 和 DML——美和易思使用 DDL 维护数据库表结构应用习题

点击打开所使用到的数据库>>>


1、使用 DDL 语句修改 easyShopping 商品表 goods 表结构,要求如下:

  1. 新增字段生产厂商 manufacturer,它的类型为 varchar(50)。
  2. 将字段 unitPrice 更名为 price,字段类型维持不变,仍为 decimal(8,2) 类型。
  3. 将字段 category 的类型修改为 varchar(50)。
  4. 删除字段 saleCount。
  5. 删除定义在 goodsName 字段的唯一约束,约束名为 unique_gName。
use easyShopping;
alter table goods 
    add manufacturer varchar(50), 
    change unitPrice price decimal(8,2), 
    modify category varchar(50), 
    drop column saleCount, 
    drop unique unique_gName

2、使用 DDL 语句创建订单表,然后在订单表的客户编号上创建一个参照客户表的外键约束。

alter table orders 
    add constraint fk_orders_customer
    foreign key(customerID) references 
    customer(customerID)

3、删除定义在订单表客户编号上的外键约束。

alter table orders drop foreign key fk_orders_customer

>>知识点【第3章 DDL 和 DML】

原创文章 120 获赞 215 访问量 35万+

猜你喜欢

转载自blog.csdn.net/weixin_44893902/article/details/105751700