MySQL第一次作业
要求:
新建产品库mydb6_product,新建4张表如下:
employees表
列1:id,整型,主健
列2:name,字符串,最大长度50,不能为空
列3:age, 整型
列4:gender,字符串,最大长度10,不能为空,默认值"unknown"
:列5:salary, 浮点型
orders表
列1:id,整型,主键
列2:name,字符串,最大长度100,不能为空
列3:price,浮点型
列4:quantity,整型
列5:category, 字符串,最大长度50
invoices表
列1:number,整型,主键自增长
列2:order_id,整型,外键关联到orders表的id列
列3:in_date:日期型
列4:total_amount:浮点型,要求数据大于0
创建数据库mydb6_product:
mysql
[root@localhost ~]# mysql -u root -p
mysql> create database mydb6_product;
Query OK, 1 row affected (0.00 sec)

创建表

创建employees表
mysql
mysql> use mydb6_product;
Database changed
mysql> create table employees (
-> id int primary key,
-> name varchar(50) not null,
-> age int,
-> gender varchar(10) not null default 'unknown',
-> salary float);
表结构:
创建orders表
mysql
mysql> create table orders (
-> id int primary key,
-> name varchar(100) not null,
-> price float,
-> quantity int,
-> category varchar(50));
Query OK, 0 rows affected (0.01 sec);
表结构:

创建invoices表
mysql
mysql> create table invoices(
-> number int auto_increment primary key,
-> order_id int,
-> in_date date,
-> total_amount float check(total_amount > 0),
-> foreign key (order_id) references orders(id));
表结构:
