题目:
解题过程:
建立数据库mydb6_product:
mysql> create database mydb6_product
-> ;
使用数据库:
mysql> use mydb6_product;
建立employees表:
mysql> create table employees(
id int primary key,
name varchar(50) not null,
age int,
gender varchar(10) not null default'unknown',
salary float);
查看建立的employees表信息:
mysql> desc employees;
查看结果如下:
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id | int | NO | PRI | NULL | |
| name | varchar(50) | NO | | NULL | |
| age | int | YES | | NULL | |
| gender | varchar(10) | NO | | unknown | |
| salary | float | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
建立orders表:
mysql> create table orders(
id int primary key,
name varchar(100) not null,
price float,
quantity int,
category varchar(50));
查看建立的order表信息:
mysql> desc orders;
查看结果如下:
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| id | int | NO | PRI | NULL | |
| name | varchar(100) | NO | | NULL | |
| price | float | YES | | NULL | |
| quantity | int | YES | | NULL | |
| category | varchar(50) | YES | | NULL | |
+----------+--------------+------+-----+---------+-------+
建立invoices表:
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));
查看建立的invoices表信息:
mysql> desc invoices;
查看结果如下:
+--------------+-------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------+------+-----+---------+----------------+
| number | int | NO | PRI | NULL | auto_increment |
| order_id | int | YES | MUL | NULL | |
| in_date | date | YES | | NULL | |
| total_amount | float | YES | | NULL | |
+--------------+-------+------+-----+---------+----------------+
以上便是本次作业的全部过程!