Commit 1869bd67 authored by Kiryuu Sakuya's avatar Kiryuu Sakuya
Browse files

Initial commit

parents
# 本代码使用 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(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(10) not null comment "客户电话",
zip char(6) not null comment "邮政编码",
PRIMARY KEY (cust_id)
);
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)
);
create table product (
prod_id char(5) not null comment "产品编号",
prod_name char(20) not null comment "产品名称",
PRIMARY KEY (prod_id)
);
\ No newline at end of file
# 实验二
## 我们预想的表结构
### 员工人事表
| 员工编号 | 员工姓名 | 性别 | 所属部门 | 职称 | 到职日 | 生日 | 薪水 | 住址 |
| : --- | --- | --- | --- | --- | --- | --- | --- | ---: |
Please register or sign in to reply
| 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号 |
#### 示例代码
```mysql
INSERT INTO employee (
emp_no, emp_name, emp_sex, emp_dept, emp_title, emp_date_hired, emp_birthday, emp_salary, emp_addr, emp_mod_date
) VALUE (
"10000", "马化腾", "男", "董事会", "总经理", "2016-10-01 09:00:00", "1998-07-11 12:00:00", "25111", "中华人民共和国北京市西城区西长安街街道", NOW()
), (
"10001", "刘强东", "男", "董事会", "副经理", "2016-10-01 09:00:00", "1974-12-16 15:00:00", "20000", "深圳市龙华区民治街道梅龙路2号星河盛世", NOW()
), (
"10002", "董明珠", "女", "财务部", "会计", "2016-10-01 09:00:00", "1954-08-01 17:00:00", "5251", "广州市越秀区培正路2号", NOW()
);
```
如果更改某一条可以用
```mysql
UPDATE employee SET emp_mod_date=NOW() where emp_no="10000";
```
删除某一条可以用
```mysql
DELETE FROM employee WHERE emp_no="10000";
# delete from deleteRowDemo where StudentName='' OR StudentName IS NULL;
```
\ 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