一、1.创建数据库 Market,在 Market 中创建数据表customers,customers表结构如表4.6所示,按要求进行操作。

 (1)创建数据库Market。
create database Market;

 (2)创建数据表customers,在c_num字段上添加主键约束和自增约束,在c_birth字段上添加非空约束。
         CREATE TABLE customers (
    ->   `c_num` int(11) NOT NULL AUTO_INCREMENT,
    ->   `c_name` varchar(50) NULL,
    ->   `c_city` varchar(50) NULL,
    ->   `c_birth` datetime NOT NULL,
    ->   PRIMARY KEY (`c_num`)
    -> );

 (3)将c_contact字段插入到c_birth字段后面。
alter table customers ADD c_contact varchar(50);

(4)将c_name字段数据类型改为VARCHAR(70)。
alter table customers modify c_name varchar(70);

(5)将c_contact字段改名为c_phone。
alter table customers change c_contact c_phone varchar(50);

 (6)增加c_gender字段,数据类型为CHAR(1)。
alter table customers add c_gender char(1);

(7)将表名修改为customers_info。
alter table customers rename customers_info;

(8)删除字段c_city。
alter table customers drop c_city;

(9)修改数据表的存储引擎为MyISAM。
alter table customers_info ENGINE = MyISAM;

二、在 Market中创建数据表orders,orders表结构如表4.7所示,按要求进行操作。

 该表中c_id与cusomers表中c_num字段的类型不同,无法创建关联,因此我将c_id类型改为了int类型。
 (1)创建数据表orders,在o_num字段上添加主键约束和自增约束,在c_id字段上添加键约束,关联customers表中的主键c_num.
CREATE TABLE orders  (
    ->   `o_num` int(1) NOT NULL AUTO_INCREMENT,
    ->   `o_data` date NULL,
    ->   `c_id` int(50) NOT NULL,
    ->   PRIMARY KEY (`o_num`),
    ->   CONSTRAINT `co` FOREIGN KEY (`c_id`) REFERENCES `customers` (`c_num`) 
    -> );

 (2)删除orders表的外键约束,然后删除表customers。
alter table orders drop foreign key co;
drop table customers;

三、创建数据库Team,定义数据表player,语句如下:

 (1)创建一个新账户,用户名为accountl,该用户通过本地主机连接数据库,密码为oldpwd1。授权该用户对Team数据库中 player表的SELECT 和INSERT权限,并且授权该用户对player表的 info字段的UPDATE权限。
create user accountl@'localhost' identified by 'oldpwdl';
grant select,insert,update(info) on Team.player to accountl@'localhost';
(2)创建SQL语句,更改account1用户的密码为newpwd2。
set password for accountl@localhost = password('newpwd2');
(3)创建SQL语句,使用FLUSH PRIVILEGES重新加载权限表。
FLUSH PRIVILEGES;
(4)创建SQL语句,查看授权给account1用户的权限。
SHOW GRANTS FOR 'accountl'@'localhost'
(5)创建SQL语句,收回account1用户的权限。
revoke all on Team.player from accountl@'localhost';
(6)创建SQL语句,将account1用户的账号信息从系统中删除。
DROP USER 'accountl'@'localhost';



















