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

Update all to markdown

parent 1ccf3379
# 实验一
> 本代码使用 MariaDB
```mysql
CREATE DATABASE studentdb;
USE studentdb;
CREATE TABLE employee (
emp_no char(5) NOT NULLCOMMENT "员工编号",
emp_name char(10) NOT NULL COMMENT "员工姓名",
emp_sex char(1) NOT NULL COMMENT "性别",
emp_dept char(5) 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;
```mysql
CREATE TABLE customer (
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 NOT NULL COMMENT "";`
```mysql
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 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(100) NOT NULL COMMENT "产品名称",
PRIMARY KEY (prod_id)
);
```
\ No newline at end of file
# 本代码使用 MariaDB
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(5) 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(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 NOT NULL comment "";
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 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(100) not null comment "产品名称",
PRIMARY KEY (prod_id)
);
\ No newline at end of file
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