格式:show tables;
格式: create table 表名 (属性名1 类型(长度) 约束,...属性名n 类型(长度) 约束) engine=引擎 default charset=utf8;
eg>>: create table test (id int primary key auto_increment, name varchar(20));
注:1) 表字符编码跟数据库编码走
? 2) 长度和约束在某些情况下是可以省略的
格式:show create table 表名;
eg>>: show create table test;
格式:desc 表名;
eg>>: desc test;
格式:alter table 表名 charset="字符编码";
eg>>:alter table test charset=‘utf‘;
格式:alter table 旧表名 rename 新表名;
eg>>: alter table test rename new_test;
格式:drop table 表名
eg>>: drop table new_test;
格式:alter table 表名 modify 字段名 字段类型[长度] 约束条件;
eg>>: alter table test modify name varchar(16) unique;
格式:alter table 表名 change 旧字段名 新字段名 字段类型[长度] 约束条件;
eg>>: alter table test change name new_name varchar(18) unique;
格式:alter table 表名 add 新字段名 字段类型[长度] 约束条件 first | [after 字段名] ;
eg>>: alter table test add sex enum(‘男‘, ‘女‘) default ‘男‘; # 默认在字段末尾
eg>>: alter table test add height float(7, 2) default 0 first; # 首位
eg>>: alter table test add weight float(7, 2) default 0 after height; # 某字段之后
格式:alter table 表名 drop 字段名;
eg>>: alter table test drop height;
引擎作用
驱动数据的方式 -进行 数据库优化
引擎是建表时规定, 提供给表使用的, 不是数据库
查看数据库库所有引擎
格式:show engines;
格式:create table 表名(字段...)engine=引擎名称;
eg>>: create table test (id int, name char(10)) engine=innodb;
原文:https://www.cnblogs.com/randysun/p/11629796.html