Database MySql create table information

Database MySql: operation of mysqlworkbench

1. Prepare the database design document

insert image description here

2. Start the operation according to the document requirements

1) Open mysqlworkbeach, right-click Local instance MySQL (if the start interface requires a login password, first log in the password, and then check the remember password option below, the following page will appear)

insert image description here

2) Create a database named employee_info

insert image description here

3) Create a table named emp_infor (the table name can be chosen by yourself, here we take emp_infor as an example)

insert image description here

4) Add data constraints to the table according to the document. After the addition is complete, click apply

insert image description here

5) Write check constraints and other data information in SQL language according to the document.

在这里插入代码片
SELECT * FROM employee_info.emp_infor;
-- 对id_card_no与phone_number的检查约束 
alter table emp_infor add constraint check_id check(length(id_card_no=18));
alter table emp_infor add constraint check_phone check(length(phone_number=11));

-- 添加五条数据 
insert into emp_infor(emp_id,emp_name,emp_salary,emp_dept,id_card_no,phone_number)
values(1,'令狐冲',9500,'产品部',612524202006176000,15894493265);

insert into emp_infor(emp_id,emp_name,emp_salary,emp_dept,id_card_no,phone_number)
values(2,'风清扬',10300.78,'产品部',610202195606283000,12725698654);

insert into emp_infor(emp_id,emp_name,emp_salary,emp_dept,id_card_no,phone_number)
values(3,'任盈盈',9870.53,'项目部',703952202020059000,13565467896);

insert into emp_infor(emp_id,emp_name,emp_salary,emp_dept,id_card_no,phone_number)
values(4,'东方不败',11000,'项目部',67957920202005500,15227708123);

insert into emp_infor(emp_id,emp_name,emp_salary,emp_dept,id_card_no,phone_number)
values(5,'张翠山',13000.65,'交付部',612514190008237000,15229907221);

-- 为产品部与项目部员工提薪30%
update emp_infor set emp_salary = emp_salary*1.3 where emp_dept='产品部' or emp_dept='项目部';

-- 修改emp_id为5的员工,将其姓名改为“张无忌",工资改为13500,部门改为"产品交付部"
update emp_infor set emp_name='张无忌',emp_salary=13500,emp_dept='产品交付部' where emp_id=5;

-- 修改所有的“产品部”为“产品研发部”
update emp_infor set emp_dept='产品研发部' where emp_dept='产品部';

-- 修改所有的“项目部”为“产品业务线“
update emp_infor set emp_dept='产品业务线' where emp_dept='项目部';

-- 统计公司的平均薪资、最高薪资、最低薪资、月度薪资合计
select avg(emp_salary) as '平均薪资',
		max(emp_salary) as '最高薪资',
        min(emp_salary) as '最低薪资',
        sum(emp_salary) as '月度薪资合计'
        from emp_infor;
        

6) Display of running results

insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/weixin_51553816/article/details/116711109