使用MySQL 语句在 salary_management_system数据库中创建4个数据表 tbl_departments、tbl_rank_ salary、tbl_employees、tb_salary。
时间: 2024-10-27 07:07:29 浏览: 100
创建 MySQL 数据库中的四个表格,需要使用 SQL 的 `CREATE TABLE` 语句。以下是每个表格的基本结构:
1. tbl_departments 表(部门信息)
```sql
CREATE TABLE tbl_departments (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
manager_id INT,
FOREIGN KEY (manager_id) REFERENCES tbl_employees(id)
);
```
2. tbl_ranks_salary 表(职位和薪资等级)
```sql
CREATE TABLE tbl_ranks_salary (
id INT AUTO_INCREMENT PRIMARY KEY,
rank_name VARCHAR(50),
min_salary DECIMAL(10, 2),
max_salary DECIMAL(10, 2)
);
```
3. tbl_employees 表(员工信息,包含部门关联)
```sql
CREATE TABLE tbl_employees (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
department_id INT,
rank_id INT,
FOREIGN KEY (department_id) REFERENCES tbl_departments(id),
FOREIGN KEY (rank_id) REFERENCES tbl_ranks_salary(id)
);
```
4. tb_salary 表(员工工资记录)
```sql
CREATE TABLE tb_salary (
id INT AUTO_INCREMENT PRIMARY KEY,
employee_id INT,
month DATE,
amount DECIMAL(10, 2),
FOREIGN KEY (employee_id) REFERENCES tbl_employees(id)
);
```
阅读全文