Auto commit

This commit is contained in:
smallkun 2025-03-14 09:32:00 +08:00
parent 4958a07e62
commit 88350396ba

View File

@ -84,3 +84,35 @@ WHERE death IS NOT NULL;
TRUNCATE pet;
```
### 练习三
```sql
#1.创建数据库
CREATE DATABASE test_compay DEFAULT CHARACTER SET utf8;
#2.创建表
CREATE TABLE department(
depid INT PRIMARY KEY AUTO_INCREMENT,
depname VARCHAR(20) NOT NULL,
deinfo VARCHAR(50)
);
CREATE TABLE employee(
empid INT PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(20) NOT NULL,
sex CHAR(1) NOT NULL DEFAULT '男',
title VARCHAR(20) NOT NULL,
birthday DATE NOT NULL,
depid INT,
CONSTRAINT fk_eid_did FOREIGN KEY(depid) REFERENCES department(depid)
);
CREATE TABLE salary(
empid INT,
basesalary DECIMAL(10, 2),
titleSalary DECIMAL(10, 2),
decuction DECIMAL(10, 2)
);
#3添加外键并设置级联更新、级联删除
ALTER TABLE salary ADD CONSTRAINT fk_sal_eid FOREIGN KEY(empid)
REFERENCES employee(empid) ON UPDATE CASCADE ON DELETE CASCADE;
```