创建数据库
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;
文章来源地址https://www.toymoban.com/news/detail-538854.html
创建外键
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;
文章来源:https://www.toymoban.com/news/detail-538854.html
创建表
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库表操作作业的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!