1、 创建数据库:CreateDATABASEdatabase-name
2、 删除数据库:drop database dbname
3、 创建新表:create table tablename
4、 删除新表:drop table tabname
5、 增加一个列:Alter table tabname add column col type
6、 添加主键: Alter table tabname add primary key(col)
7、 删除主键: Alter table tabname drop primary key(col)
8、 创建索引:create [unique] index idxname on tabname 删除索引:drop index idxname
9、 查询:select * from table1 where 范围查找:select * from table1 where field1 like ’%value1__’
10、 插入:insert into table1(field1,field2) values(value1,value2)
11、 删除:delete from table1 where 范围
12、 更新:update table1 set field1=value1 where 范围
13、 排序:select * from table1 order by field1,field2 [desc]
14、 总数:select count * as totalcount from table1
15、 求和:select sum(field1) as sumvalue from table
16、 平均:select avg(field1) as avgvalue from table1
17、 最大:select max(field1) as maxvalue from table
18、 最小:select min(field1) as minvalue from table1
本文详细介绍了SQL的基本操作,包括创建、删除数据库与表格,修改表结构,增加列,设置主键,创建与删除索引,执行查询、插入、删除、更新操作,以及对数据进行排序、统计、求和、平均、最大、最小等基本操作。
1418

被折叠的 条评论
为什么被折叠?



