Verified Commit b73e9600 authored by Kiryuu Sakuya's avatar Kiryuu Sakuya 🎵
Browse files

Finish (nope)

parent 64e6852b
......@@ -4,45 +4,58 @@ create database studentdb;
use studentdb;
create table employee (
emp_no char(5) not null comment "员工编号",
emp_name char(10) not null comment "员工姓名",
emp_sex char(1) not null comment "性别",
emp_dept char(4) not null comment "所属部门",
emp_title char(6) not null comment "职称",
emp_date_hired datetime not null comment "到职日",
emp_birthday datetime not null comment "生日",
emp_salary char(5) not null comment "薪水",
emp_addr varchar(60) not null comment "住址",
emp_mod_date datetime not null DEFAULT CURRENT_TIMESTAMP comment "操作时间",
PRIMARY KEY (emp_no)
emp_no char(5) not null comment "员工编号",
emp_name char(10) not null comment "员工姓名",
emp_sex char(1) not null comment "性别",
emp_dept char(4) not null comment "所属部门",
emp_title char(6) not null comment "职称",
emp_date_hired datetime not null comment "到职日",
emp_birthday datetime not null comment "生日",
emp_salary char(5) not null comment "薪水",
emp_addr varchar(60) not null comment "住址",
emp_mod_date datetime not null DEFAULT CURRENT_TIMESTAMP comment "操作时间",
PRIMARY KEY (emp_no)
);
# 查看所有表可以用 show full columns from employee;
# 或者用 desc employee; 嘛
# 更改表名可以用 ALTER TABLE test RENAME TO test2;
create table customer (
cust_id char(5) not null comment "客户号",
cust_name char(20) not null comment "客户名称",
addr char(40) not null comment "客户住址",
tel_no char(15) not null comment "客户电话",
zip char(8) not null comment "邮政编码",
PRIMARY KEY (cust_id)
cust_id char(6) not null comment "客户号",
cust_name char(20) not null comment "客户名称",
addr char(40) not null comment "客户住址",
tel_no char(15) not null comment "客户电话",
zip char(8) not null comment "邮政编码",
PRIMARY KEY (cust_id)
);
# 更改字段名称及类型可以用
# ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;
create table sales (
order_no varchar(26) not null comment "订单编号",
cust_id char(6) not null comment "客户号",
sale_id char(5) not null comment "业务员编号",
tot_amt numeric(9, 2) not null comment "订单金额",
order_date datetime not null comment "订货日期",
ship_date datetime not null comment "出货日期",
invoice_no char(8) not null comment "发票号码",
PRIMARY KEY (order_no);
)
# numeric(5, 2) 里面的 5 是精度,表示十进制数字的数目,而 2 表示小数点后的数字位数。
create table sale_item (
order_no int not null comment "订单编号",
prod_id char(5) not null comment "产品编号",
qty int not null comment "销售数量",
unit_price numeric(9, 2) not null comment "单价",
order_date datetime not null comment "订单日期",
PRIMARY KEY (order_no, prod_id)
order_no varchar(26) not null comment "订单编号",
prod_id char(5) not null comment "产品编号",
qty int not null comment "销售数量",
unit_price numeric(9, 2) not null comment "单价",
order_date datetime not null comment "订单日期",
PRIMARY KEY (order_no, prod_id)
);
create table product (
prod_id char(5) not null comment "产品编号",
prod_name char(50) not null comment "产品名称",
PRIMARY KEY (prod_id)
prod_id char(5) not null comment "产品编号",
prod_name char(50) not null comment "产品名称",
PRIMARY KEY (prod_id)
);
\ No newline at end of file
......@@ -9,6 +9,8 @@
| 10000 | 马化腾 | 男 | 董事会 | 总经理 | 2016-10-01 09:00:00 | 1998-07-11 12:00:00 | 25111 | 中华人民共和国北京市西城区西长安街街道 |
| 10001 | 刘强东 | 男 | 董事会 | 副经理 | 2016-10-01 09:00:00 | 1974-12-16 15:00:00 | 20000 | 深圳市龙华区民治街道梅龙路2号星河盛世 |
| 10002 | 董明珠 | 女 | 财务部 | 会计 | 2016-10-01 09:00:00 | 1954-08-01 17:00:00 | 5251 | 广州市越秀区培正路2号 |
| 20001 |
| 20002 |
#### 示例代码
......@@ -27,7 +29,7 @@ INSERT INTO employee (
如果更改某一条可以用
```mysql
UPDATE employee SET emp_mod_date=NOW() where emp_no="10000";
UPDATE employee SET emp_mod_date=NOW() WHERE emp_no="10000";
```
删除某一条可以用
......@@ -60,11 +62,21 @@ INSERT INTO customer (
| 订单编号 | 客户号 | 业务员编号 | 订单金额 | 订货日期 | 出货日期 | 发票号码 |
| :--- | --- | --- | --- | --- | --- | ---: |
| 11035462019090116054034524 | 100000 | 10001 | 56.5 | 2019-09-01 16:05:40 | 2019-09-01 18:23:02 | 34600350 |
| 11035462019090211345678134 | 100001 | 10002 | 2510 | 2019-09-02 11:34:56 | 2019-09-04 13:01:22 | 34600352 |
| 11035462019090116054034524 | 100000 | 20001 | 56.5 | 2019-09-01 16:05:40 | 2019-09-01 18:23:02 | 34600350 |
| 11035462019090211345678134 | 100001 | 20002 | 2510 | 2019-09-02 11:34:56 | 2019-09-04 13:01:22 | 34600352 |
#### 示例代码
```mysql
INSERT INTO sales (
order_no, cust_id, sale_id, tot_amt, order_date, ship_date, invoice_no
) VALUE (
"11035462019090116054034524", "100000", "20001", "56.5", "2019-09-01 16:05:40", "2019-09-01 18:23:02", "34600350"
), (
"11035462019090211345678134", "100001", "20002", "2510", "2019-09-02 11:34:56", "2019-09-04 13:01:22", "34600352"
);
```
### 销货明细表
| 订单编号 | 产品编号 | 销售数量 | 单价 | 订单日期 |
......@@ -74,6 +86,16 @@ INSERT INTO customer (
#### 示例代码
```mysql
INSERT INTO sale_item (
order_no, prod_id, qty, unit_price, order_date
) VALUE (
"11035462019090116054034524", "T0001", "1", "56.5", "2019-09-01 16:05:40"
), (
"11035462019090211345678134", "D0002", "5", "502", "2019-09-02 11:34:56"
);
```
### 产品名称表
| 产品编号 | 产品名称 |
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment