1、创建表
>help create table;
>create database student;
>use student;
>create table student(id int, name varchar(10))
2、查看某数据库中的表
>show tables;
3、查看表的结构
>describe student;
>desc student;
4、查看数据表的详细信息
>show create table student;
>show table status like ‘student’;
5、查看表的具体内容
>select * from student;
6、清空表的数据
>truncate table student;
>select * from student;
7、删除表
>drop table student;
>show tables;
8、修改表
(1)修改表名
>alter table student rename to student1;
>show tables;
(2)在表的最后一个位置增加字段
>alter table student add city varchar(10);
>desc student;
(3)在表的指定字段之后增加字段
>alter table student add nation varchar(10) after name;
>desc student;
>alter table student add(sex char(1), age int);
(4)删除字段
>alter table student drop nation;
(5)修改字段的数据类型
>alter table student modify city char(10);
(6)修改字段的名字和属性
>alter table student change city country varchar(20);
注意:后面的数据类型varchar(20)必不可少
(7)修改字段的顺序
>alter table student modify country varchar(20) first/after id;
Comments