Mysql笔记【2】-数据表的基本操作

1、创建数据库表

create table <表名>
(
字段名1 类型 <列级别限制> ,
字段名2 类型 <列级别限制> ,
字段名3 类型 <列级别限制> ,
...
表级别限制
)

2、查看表结构

desc <表名>
show create table <表名>

3、修改表

  a、修改表名

alter table <表1> rename <新表名>  

  b、修改字段的数据类型

#例如 alter table test modify name varchar(100)
alter table <表名1> modify <列名> <字段类型>

  c、修改字段名

#例如 alter table test change sex age varchar(5)
alter table <表名> change <旧列> <新列> <新列字段类型>

  d、添加字段

#例如 alter table test add sex varchar(100)
alter table <表名> add <列名> <字段类型> #在表的第一列添加字段
alter table <表名> add <列名> <字段类型> first #在列名 name之前插入
alter table <表名> add <列名> <字段类型> after name

  e、删除字段

#例如 alter table test drop sex
alter table <表名> drop <列名>

  f、修改字段的排列顺序

#放在第一列
alter table <表名> modify <列名> <类型> first #放在指定列之后
alter table <表名> modify <列名> [<类型>] after <指定列>

4、删除表

drop table <表名>

  

  

上一篇:面试题之 query转为obj


下一篇:ssh 登陆进去后, .bashrc 也没有被执行