create database database_name;
创建数据库database_name
drop database database_name;
删除数据库database_name
show databases;
显示数据库列表
use database_name;
进入/使用数据库database_name
show tables;
显示当前数据库所有表
create table table_name(var1 type, var2 type ...);
创建表table_name 有字段var1 var2 ...
drop table table_name;
删除表table_name
desc table_name;
显示所有表结构
alter table table_name add var1 type after var2;
当前数据库 table_name表内增加var1字段 在var2 后面
alter table table_name drop var1;
当前数据库 table_name表内删除var1字段
alter table table_name change var1 var1 type afrer ;
当前数据库 table_name表内更改var1类型/位置/名称
add primary key(var1);
增加var1为主键
alter table table_name1 rename table_name2;
当前数据库表table_name1更名为table_name2
insert into table_name (字段名1, 字段名2, ...) values (字段值1, 字段值2, ...);
在表table_name 插入数据
select 表名.字段名 from 表名 where 表名.字段名=xx
select 表名.字段名 where 表名.字段名 in (select 表名.字段名 from 表名 where 表名.字段名=xx);
p.s. binary 不区分大小写 distinct 仅列出不同值
查询以及二次查询
select 字段名1, 字段名2 from 表名 order by 字段名1, 字段名2;
order by 根据列升序 asc 正序 desc 倒序
update 表名 set 字段名='xxx' where 字段名='xxx';
更新表数据
delete from 表名 where 字段名='xxx';
删除表数据
select * from 表名;
显示表的所有数据
select 字段名 from 表名 limit 数字
select 字段名 from 表名 where rownum < 数字
select top 数字 字段名 from 表名
select top 数字 percent 字段名 from 表名
查询后分段显示
select 字段名 from 表名 like '%'
select 字段名 from 表名 not like '%'
p.s. % 占 _ 1
查询后按like过滤