1、创建数据库使用create database语句创建“工资管理系统”数据库wage_management代码如下:Create database wage_management charset utf8;
2、创建表根据设计的表结构,使用create table语句创建表。代码如下:#创建员工档案钱砀渝测(file)表create table file(id bigint primary key not null,name varchar(20) not null,sex enum('男','女') not null,age tinyint,education varchar(20) not null,identify varchar(10) not null,school varchar(40) not null,major varchar(40) not null,birth datetime not null,department varchar(15) not null);
3、insert into file (id,name,sex,age,education,identify,school,major,birth,department) values(1,'张三','男','23','本科','党员','云南民族大学','计算机专业','1996-11-11','技术部');insert into file (id,name,sex,age,education,identify,school,major,birth,department) values(2,'李四','女','23','本科','党员','云南民族大学','市场营销专业','1996-05-19','市场部');insert into file (id,name,sex,age,education,identify,school,major,birth,department) values(3,'王五','男','23','本科','团员','云南民族大学','财务管理专业','1996-02-19','财务部');insert into file (id,name,sex,age,education,identify,school,major,birth,department) values(4,'陆六','女','23','本科','群众','云南民族大学','人事管理专业','1996-06-25','人事部');
4、#创建员工工资(wage)表create table wage(id bigint primary key not null,name varchar(20) not null,base_pay float(5) not null,merit_pay float(5) not null,add_pay float(5) not null,sj_salary float(5) not null,date datetime not null,card char(19) not null);
5、insert into wage (id,name,base_pay,merit_pay,add_pay,sj_salary,d锾攒揉敫ate,card) values(1,'张三','2500','160','200','2860',now(),'6217003850011428958');insert into wage (id,name,base_pay,merit_pay,add_pay,sj_salary,date,card) values(2,'李四','2500','150','200','2850',now(),'6217003850011428960');insert into wage (id,name,base_pay,merit_pay,add_pay,sj_salary,date,card) values(3,'王五','2500','180','200','2880',now(),'6217003850011428962');insert into wage (id,name,base_pay,merit_pay,add_pay,sj_salary,date,card) values(4,'陆六','2500','170','200','2870',now(),'6217003850011428964');
6、#创建员工考勤(attendance)表create table attendance(department varchar(15) primary key not null,id bigint not null,name varchar(20) not null,overtime float(5) not null,vacate float(5) not null,work_time float(5) not null);
7、insert into attendance (department,id,name,overtime,vacate,work_time) values('技术部','1','张三','1','3','18');insert into attendance (department,id,name,overtime,vacate,work_time) values('市场部','2','李四','2','1','21');insert into attendance (department,id,name,overtime,vacate,work_time) values('财务部','3','王五','4','0','24');insert into attendance (department,id,name,overtime,vacate,work_time) values('人事部','4','陆六','3','1','22');
8、#创建员工部门(dept)表create table dept(id bigint(20) primary key not null,name char(20) not null,remark char(20),manager char(20),number bigint(20),tel varchar(20) default '0871-');
9、insert into dept (id,name,remark,manager,number,tel) values('1','技术部','技术支撑部门','张三','18468253855','0871-65091818');
10、#创建员工保险(insurance)表create table insu筠续师诈rance(id bigint(20) primary key default '5',old bigint(20) default '501',unemployment bigint(20) default '502',injury bigint(20) default '503',bear bigint(20) default '504',medical bigint(20) default '505',house bigint(20) default '506');
11、insert into insurance (id,old,unemployment,injury,bear,medical,house) values('5','501','502','503','504','505','506');
12、添加约束(1)员工档案表:添加主键约束、非空约束、外键约束
13、员工档案表中department所属部门,为员工考勤表的外键
14、(2)员工工资表:添加主键约束、非空约束和外键约束
15、员工工资表中id员工工号,为员工档案表的外键
16、(3)员工考勤表:添加主键约束和非空约束
17、(4)员工部门表:添加主键约束、非空约束和默认约束
18、(5)员工保险表:添加主键约束、非空约束和默认约束
19、(1)创建索引index,便于信息的查询,创建语句如下:create table temp(id bigint primary key not null,name varchar(20) not null,card char(19) not null,t1 datetime);create index index1 on wage(id);explain select * from wage where id='1';