sqlserver中常用的脚本大全


摘要:
下文讲述sqlserver中常用的脚本知识,如下所示:
实验环境:sql server 2008 R2


 ---数据查询
select * from tableName where [检索条件]
---数据插入操作
insert into tableName(field1,field2) values(value1,value2)
---数据删除操作
delete from tableName where [检索条件]
---数据修改操作
update tableName set field1=value1 where [检索条件]
---数据模糊查询
select * from tableName where field1 like ’%value1%’ ---like的语法很精妙,查资料!
---数据排序操作
select * from tableName order by field1,field2 [desc]
---数据行术统计
select count(1) as countAll from tableName

---指定列求和
select sum(field1) as sumField from tableName

---指定列求平均值
select avg(field1) as avgField from tableName

---指定列求最大值
select max(field1) as maxField from tableName

---指定列求最小值
select min(field1) as minField from tableName