SQLserver学习(二)——基本SQL语句整理

几个简单的基本的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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值