create datebase test1; 创建数据库test1
drop datebase test1; 创建数据库test1
数据库表结构的操作
create table 表名(
列名1 数据类型[列级别约束条件] [默认值],
列名2 ......,
列名n ......,
[表级别约束条件]
);
查看数据表列表(就是看看这里有那些表) show tables [from db_name]; 注释:[ ] 内可以不填
查看数据表基本结构(比如 姓名,性别等)三种方法 1 show columns from 表名;
2 describe 表名;
3 desc 表名;
添加列
alter table 表名 add 新列名 数据类型 [约束条件];
修改列名
alter table 表名 change 旧表名 新表名 数据类型;
修改列的数据类型
alter table 表名 modify 列名 数据类型;
修改列的排列位置
alter table 表名 modify 列1 数据类型 first/after 列2;
删除列
alter table 表名 drop 列名;
修改表名
alter table 旧表名 rename 新表名;
删除数据库表
drop table [if exists] 表1,表2,表3,......表n;
创建表分区
首先判断数据库是否支持表分区 show plngins 倒数第二行出现 partition active 说明支持
举列:
create table bookinfo(
book_id int,
book_name varchar(20),
)
partition by range (book_id)(
partition p1 values less than (20109999),
partition p2 values less than (20159999),
partition p3 values less than MAXVALUE
);