- 说明:表是建立在数据库中的数据结构,是一类数据的存储集。
1,表的创建
creat tables `表名`(
id int not null auto_increment primary key comment '主键',
price varchar(12) comment `价格`
)charset=utf8;
# 在上面 auto_increment 表示主键默认自增
2,查看所有表
show tables;
3,删除表
drop table `表名`
4,显示建表结构
desc `表名`;
describe `表名`;
5,修改表
-- 修改表的名称
alter table `old_name` rename `new_name`;
-- 移动表 到指定的数据库
alter table `表名` rename to 数据库.表名;
6,修改字段
-- 增加一个新的字段
alter table `表名` add `字段名` 数据类型 [属性];
-- 增加一个新的字段, 并放在首位
alter table `表名` add `字段名` 数据类型 [属性] first;
-- 增加一个新的字段, 并放在某一个字段之后
alter table `表名` add `字段名` 数据类型 [属性] after 指定字段;
-- 修改字段的属性
alter table `表名` modify `字段名` 数据类型 [属性];
-- 修改字段的名称
alter table `表名` change `原字段名` `新的字段名` 数据类型 [属性];
-- 修改字段的位置
alter table `表名` change `原字段名` `新的字段名` 数据类型 after `指定字段`;
-- 删除字段
alter table `表名` drop `字段名`;