几个简单的基本的sql语句
选择:select * from table1 where 。。。
插入:insert into table1(field1,field2) values(value1,value2)
删除:delete from table1 where 。。。
更新:update table1 set field1=value1 where 。。。
查找:select * from table1 where field1 like ’%value1%’ (在ACCESS中通配符有所不同,这也是arcgis中针对mdb或其他形式的数据所用的sql语句略有不同的原因)
排序:select * from table1 order by field1,field2 [desc]
总数:select count as totalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1
创建数据库 CREATE DATABASE database-name
删除数据库 drop database dbname
创建新表 create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
根据已有的表创建新表:
create table A like B(使用旧表创建新表)
create table A as select col1,col2… from B definition only
将已有的表中部分行拿出来生成一个新表
SELECT * into A FROM B where...
把一个表中部分行插入到另一个表
INSERT into A(col1,col2,...) select col1,col2,... from B
删除表drop table tabname
增加一列 Alter table tabname add column col type
添加主键: Alter table tabname add primary key(col)
删除主键: Alter table tabname drop primary key(col)
创建索引:create [unique] index idxname on tabname(col….)
删除索引:drop index idxname
注:索引是不可更改的,想更改必须删除重新建。
创建视图:create view viewname as select statement
删除视图:drop view viewname