employees表:
mysql> create database mydb6_product;
Query OK, 1 row affected (0.01 sec)
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);
Query OK, 0 rows affected (0.03 sec)
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 | |
+--------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
orders表:
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.03 sec)
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 | |
+----------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
invoices表:
mysql> create table invoices(
-> number int primary key auto_increment,
-> order_id int,
-> in_date date,
-> total_amount float,
-> check(total_amount>0),
-> foreign key (order_id) references orders(id));
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 | |
+--------------+-------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
本文转载自: https://blog.csdn.net/m0_73819250/article/details/140500298
版权归原作者 予安不会写博客 所有, 如有侵权,请联系我们删除。
版权归原作者 予安不会写博客 所有, 如有侵权,请联系我们删除。