根据图中题目:
(1):create database market default charset utf8;
(2):create table customers( c_num int (11) primary key auto_increment, c_name varchar(50), c_contact varchar(50), c_city varchar(50), c_birth datetime not null);
alter table customers modify c_birth datetime not null;
(3):alter table customers modify c_contact varchar(50) after c_birth;
Query OK, 0 rows affected (0.01 sec)
(4): alter table customers modify c_name varchar(70);
(5):alter table customers change c_contact c_phone varchar(50);
(6):alter table customers add c_gender char(1);
(7):alter table customers rename to customers_info;
注意:这时候表名字就变成了 customers_info。
(8):alter table customers_info drop c_city;
(9):alter table customers_info engine=myisam;
(1):
注意:需要在添加外键时将 customers_info 表的存储引擎再次改回来,不然会报错。
改回存储引擎
alter table customers_info engine=innodb;
根据要求建立数据表 orders
create table orders(
>o_num int(11) primary key not null AUTO_INCREMENT,
>o_date date,
>c_id int(11),
>foreign key(c_id) references customers_info(c_num));
因为上面的创建外键的语句中没有指定外键的外键名,即是外键 c_id 没有设置一个名字,所以会自动生成一个外键,那么这个外键名字用以下查看。
show create table orders;
结果;
| orders | CREATE TABLE `orders` (
`o_num` int(11) NOT NULL AUTO_INCREMENT,
`o_date` date DEFAULT NULL,
`c_id` int(11) DEFAULT NULL,
PRIMARY KEY (`o_num`),
KEY `c_id` (`c_id`),
CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`c_id`) REFERENCES `customers_info` (`c_num`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
发现外键是叫 orders_ibfk_1 ,所以删除外键命令:
alter table orders drop foreign key orders_ibfk_1;
删除表。如果不先删除外键的话就会删不掉 customers_info 表
drop table customers_info;
(1): create database team;
use team
create table player(
-> playid int primary key,
-> playname varchar(30) not null,
-> teanum int not null unique,
-> info varchar(50));
grant select,insert,update(info) on team.player to account1@'localhost' identified by 'oldpwd1';
(2):
alter user account1@'localhost' identified by 'newpwd2';
(3):
改了密码权限后记得更新权限列表
flush privileges;
(4):
show grants for account1@'localhost';
(5):
revoke all on team.player from account1@localhost;
flush privileges;
(6):
drop user account1@localhost;