职工(员工号,姓名,性别,年龄,电话,邮箱,部门号,家庭住址) 部门(部门号,部门名) 工资 (工资号,基本工资,奖金,罚金,净工资,员工号) 考勤(考勤号,考勤类型) 登记(考勤号,员工号,考勤日期)数据库的创建和数据的录入
时间: 2023-08-24 21:05:21 浏览: 252
好的,我可以为您提供创建数据库和数据录入的步骤。
1. 创建数据库
首先,我们需要在MySQL中创建一个新的数据库,命名为"personnel_management",可以使用以下SQL语句:
```
CREATE DATABASE personnel_management;
```
2. 创建表
接下来,我们可以在创建好的数据库中创建表,可以使用以下SQL语句分别创建职工表、部门表、工资表、考勤类型表和登记表:
- 职工表(Employee):
```
CREATE TABLE Employee (
EmployeeID INT PRIMARY KEY,
Name VARCHAR(50),
Gender VARCHAR(10),
Age INT,
Phone VARCHAR(20),
Email VARCHAR(50),
DepartmentID INT,
Address VARCHAR(100),
FOREIGN KEY (DepartmentID) REFERENCES Department (DepartmentID)
);
```
- 部门表(Department):
```
CREATE TABLE Department (
DepartmentID INT PRIMARY KEY,
DepartmentName VARCHAR(50)
);
```
- 工资表(Salary):
```
CREATE TABLE Salary (
SalaryID INT PRIMARY KEY,
BasicSalary FLOAT,
Bonus FLOAT,
Fine FLOAT,
NetSalary FLOAT,
EmployeeID INT,
FOREIGN KEY (EmployeeID) REFERENCES Employee (EmployeeID)
);
```
- 考勤类型表(AttendanceType):
```
CREATE TABLE AttendanceType (
AttendanceID INT PRIMARY KEY,
AttendanceType VARCHAR(50)
);
```
- 登记表(CheckIn):
```
CREATE TABLE CheckIn (
AttendanceID INT,
EmployeeID INT,
CheckInDate DATE,
PRIMARY KEY (AttendanceID, EmployeeID),
FOREIGN KEY (AttendanceID) REFERENCES AttendanceType (AttendanceID),
FOREIGN KEY (EmployeeID) REFERENCES Employee (EmployeeID)
);
```
3. 数据录入
创建完表之后,我们可以向表中录入数据。可以使用以下SQL语句向职工表、部门表、工资表、考勤类型表和登记表中录入部分数据:
- 职工表(Employee):
```
INSERT INTO Employee (EmployeeID, Name, Gender, Age, Phone, Email, DepartmentID, Address)
VALUES (1, '张三', '男', 25, '13811112222', 'zhangsan@abc.com', 1, '北京市海淀区');
INSERT INTO Employee (EmployeeID, Name, Gender, Age, Phone, Email, DepartmentID, Address)
VALUES (2, '李四', '女', 30, '13911113333', 'lisi@abc.com', 2, '北京市朝阳区');
INSERT INTO Employee (EmployeeID, Name, Gender, Age, Phone, Email, DepartmentID, Address)
VALUES (3, '王五', '男', 28, '13611114444', 'wangwu@abc.com', 1, '北京市昌平区');
```
- 部门表(Department):
```
INSERT INTO Department (DepartmentID, DepartmentName)
VALUES (1, '人力资源部');
INSERT INTO Department (DepartmentID, DepartmentName)
VALUES (2, '财务部');
```
- 工资表(Salary):
```
INSERT INTO Salary (SalaryID, BasicSalary, Bonus, Fine, NetSalary, EmployeeID)
VALUES (1, 5000.00, 1000.00, 500.00, 5500.00, 1);
INSERT INTO Salary (SalaryID, BasicSalary, Bonus, Fine, NetSalary, EmployeeID)
VALUES (2, 6000.00, 1200.00, 600.00, 6600.00, 2);
INSERT INTO Salary (SalaryID, BasicSalary, Bonus, Fine, NetSalary, EmployeeID)
VALUES (3, 5500.00, 1100.00, 550.00, 6050.00, 3);
```
- 考勤类型表(AttendanceType):
```
INSERT INTO AttendanceType (AttendanceID, AttendanceType)
VALUES (1, '出勤');
INSERT INTO AttendanceType (AttendanceID, AttendanceType)
VALUES (2, '请假');
INSERT INTO AttendanceType (AttendanceID, AttendanceType)
VALUES (3, '加班');
```
- 登记表(CheckIn):
```
INSERT INTO CheckIn (AttendanceID, EmployeeID, CheckInDate)
VALUES (1, 1, '2022-01-01');
INSERT INTO CheckIn (AttendanceID, EmployeeID, CheckInDate)
VALUES (2, 2, '2022-01-02');
INSERT INTO CheckIn (AttendanceID, EmployeeID, CheckInDate)
VALUES (3, 3, '2022-01-03');
```
通过以上步骤,我们就成功地创建了人事工资管理系统所需的数据库和表,并录入了一些测试数据。
阅读全文