mysql第一次作业
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
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!