1、创建数据库
create database 数据库名;
2、删除数据库
drop database 数据库名;
3、创建表
格式:
create table 表名(字段名 字段类型 [约束条件],...) 如下:
create table tablName(col1 type1[not null][primary key],col2 type2[not null],...)
4、删除表
drop table 表名;
5、增加列
alter table 表名 add column 字段名 字段数据类型;
6、添加主键 和 删除主键
添加主键:
alter table 表名 add primary key(字段名);
删除主键:
alter table 表名 drop primary key(字段名);
7、创建索引 和 删除索引
创建索引:
create[unique] index 索引名 no 表名(字段名...);
删除索引:
drop index 索引名;
8、创建视图 和 删除视图
创建视图:
create view 视图名 as select statement;
删除视图:
drop view 视图名;
9、最常用的sql语句
插入:
insert into 表名(字段名,字段名,...) values(字段内容,字段内容,...)
删除:
delete from 表名 where...
更新:
update 表名 set field=value where...
选择:
select * from 表名 where...
查找:
select * from 表名 firld like '%value%';
总数:
select * count(1) as totalcount from 表名 ;
最大:
select max(field) as maxv from 表名
最小:
select min(field) as minv from 表名
求和:
select avg(field) as avgv from 表名