MySQL库表操作作业

MySQL库表操作作业_第1张图片

 创建数据库

mysql> create database Market;  

mysql> use Market;

创建表和约束

mysql> create table customers(c_num int(11) primary key not null UNIQUE Key auto_increment ,

    -> c_name varchar(50),

    -> c_city varchar(50),

    -> c_birth datetime not null);

添加字段

mysql> alter table customers add c_contact varchar(50);

更改字段  

mysql> alter table customers change c_contact c_phone varchar(50);

更改字段类型

mysql> alter table customers modify  c_name varchar(70);

添加字段

mysql> alter table customers add c_gender char(1);

更改表名

mysql> alter table customers rename customers_info;

删除字段

mysql> alter table customers_info drop c_city;

修改存储引擎

mysql> alter table customers_info engine = MyISAM;

MySQL库表操作作业_第2张图片

 

创建外键

mysql> create table orders( o_num int(11) primary key auto_increment, o_data date, c_id int(11), constraint `links` foreign key(c_id) references customers_info(c_num));

删除外键连接

mysql> alter table orders drop foreign key links;

 删除表

mysql> drop table customers_info;

MySQL库表操作作业_第3张图片

 

创建表

mysql> create table player( playid int primary key, playname varchar(30) not null, teamnum int not null unique, info varchar(50));

创建用户

mysql>create user accountl@localhost identified by 'oldpwdl';

用户权限设置

mysql> grant select on Team.player to accountl@localhost;

mysql> grant insert on Team.player to accountl@localhost;

mysql> grant update(info) on Team.player to accountl@localhost;

更改用户密码

mysql> alter user accountl@localhost identified by 'newpwd2';

刷新权限表

mysql> flush privileges;

查看用户权限

mysql> show grants for accountl@localhost;

移除用户权限

mysql> use mysql

mysql> revoke select on Team.player from accountl@'localhost';

mysql> revoke insert on Team.player from accountl@'localhost';

mysql> revoke update(info) on Team.player from accountl@'localhost';

删除用户

mysql> drop user accountl@'localhost';

 

 

 

 

你可能感兴趣的:(mysql,数据库)