MySQL常用的修改表命令总结
程序员文章站
2022-07-04 09:40:29
查看列:desc 表名;
查看所有:show databases;
进入数据库:use 数据库名;
查看所有数据表名:show tables;
查看用户权限情况:select * from mysq...
查看列:desc 表名;
查看所有:show databases;
进入数据库:use 数据库名;
查看所有数据表名:show tables;
查看用户权限情况:select * from mysql.user\g;
修改表名:alter table t_book rename to bbb;?
添加列:alter table 表名 add column 列名 varchar(30);?
删除列:alter table 表名 drop column 列名;
修改列名mysql: alter table bbb change nnnnn hh int;?
修改列属性:alter table t_book modify name varchar(22);?
查看表的所有信息:show create table 表名;
添加主键约束:alter table 表名 add constraint 主键 (形如:pk_表名) primary key 表名(主键字段);
添加外键约束:alter table 从表 add constraint 外键(形如:fk_从表_主表) foreign key 从表(外键字段) references 主表(主键字段);
删除主键约束:alter table 表名 drop primary key;
删除外键约束:alter table 表名 drop foreign key 外键(区分大小写);