设计型
假定数据库db_manage中有员工表emp和货物表dept,表结构及表中数据样本如下所示,请按要求写出相应的SQL语句。
create database db_manage;
use db_manage;
create table emp
(
empID varchar(4) primary key,
empName varchar(8) not null,
sex varchar(2) not null default '男',
birthday date not null,
native varchar(20),
wages decimal(8,2) not null,
deptID varchar(4)
);
/*插入数据到emp表*/
INSERT INTO emp
VALUES('E001','向晓伟','男','1982-11-07','北京',4300,'D001'),
('E002','徐燕','女','1985-08-21','上海',3400,'D002'),
('E003','罗刚','男','1984-05-18','四川',3500,NULL),
('E004','张万祥','男','1974-12-14','北京',6700,'D004'),
('E005','胡英','女','1983-04-25',NULL,3600,'D001'),
('E006','程秀华','女','1979-06-02 ','上海',4500,'D003');
create table dept
(
deptID varchar(4) primary key,
deptName varchar(20) not null
);
/*插入数据到dept表*/
INSERT INTO dept
VALUES('D001','销售部'),('D002','人事部'),('D003','财务部'),
('D004','经理办'),('D005','物资部');
1.创建用户sale1,口令为pd01;创建用户sale2,口令为pd02;
创建用户sale3,口令为pd03;创建用户sale4,口令为pd04;创建用户sale5,口令为pd05。
create user sale1@localhost identified by 'pd01',
sale2@localhost identified by 'pd02',
sale3@localhost identified by 'pd03',
sale4@localhost identified by 'pd04',
sale5@localhost identified by 'pd05';
2.删除用户sale5。
drop user sale5@localhost;
3.将用户sal4的名字修改为zhang。
rename user sale4@localhost to zhang@localhost;
4.将用户zhang的口令修改为k168。
set password for zhang@localhost='k168';
5.授予用户sale1在数据库db_manage数据库的emp表上对员工号列和员工姓名列的查询权限。
grant select(empID,empName) on emp
to sale1@localhost;
6.先创建用户wang和li,然后授予它们在数据库db_manage的emp表上添加行、更新表的值和删除行的权限,
并允许它们将自身的权限授予其他用户。
create user wang@localhost identified by 'wang',
li@localhost identified by 'li';
grant insert,update,delete
on db_manage.emp
to wang@localhost,li@localhost
with grant option;
7.授予sale2对数据库db_manage中的所有表的所有操作的权限。
grant all on db_manage.* to sale2@localhost;
8.授予用户zhang在所有数据库中创建新表、修改表和删除表的权限。
grant create,alter,drop on *.*
to zhang@localhost;
select
9.收回用户wang在数据库db_manage的emp表上添加行的权限。
revoke insert on db_manage.emp from wang@localhost;
10.收回用户zhang在所有数据库中删除表的权限。
revoke drop on *.* from zhang@localhost;