- 创建表
- 查询所有表
- 查询表信息
- 查询表字段
- 删除表
- 修改表名
- 添加表字段
- 删除表字段
- 修改表字段
- 常见错误
1.创建表
- 格式: create table 名字(字段1名 类型,字段2名 类型,…)charset=utf8/gbk;
create table person(name varchar(50),age int)charset=utf8;
create table student(name varchar(50),chinese int,math int,english int);
2.查询所有表
- 格式: show tables;
show tables;
3.查询表信息
- 格式: show create table 表名;
show create table person;
4.查询表字段
- 格式: desc 表名;
desc student;
5.删除表
- 格式; drop table 表名;
drop table student;
6.修改表名
- 格式: rename table 原名 to 新名;
rename table person to per;
7.添加表字段
- 最后面添加格式: alter table emp add 字段名 类型;
- 最前面添加格式: alter table emp add 字段名 类型 first;
- 某字段后面添加格式: alter table emp add 字段名 类型 after 字段名;
alter table emp add age int;
alter table emp add id int first;
alter table emp add gender varchar(10) after name;
8.删除表字段
- 格式: alter table 表名 drop 字段名;
alter table emp drop gender;
alter table emp drop id;
9.修改表字段
- 格式: alter table 表名 change 原名 新名 新类型;
alter table emp change age gender varchar(10);
常见错误:
ERROR 1046 (3D000): No database selected------没有选择数据库。