首先在这申明,sqlserver是不区分大小写的。
SqlServer插入语句
insert into <表名> [<属性1><属性2><属性3>] values(<常量1><常量1><常量1>)
SqlServer修改数据语句
update <表名> set <列名>=<表达式>,<列名>=<表达式> [where <条件>]
SqlServer删除数据语句
delete from <表名> [where<条件>]
查询中消除重复的行
select distinct Sno from sc;
where子句后面常跟的查询条件
- 比较—(=、<、>、>=、<=、!=、!>、!<(不小于)、)
- 确定范围—-(between and、not between and)
- 确定集合—–(in、not in)
- 字符匹配——(like、not like)
- 空值——(is null,is not null)
- 多重条件—–(and、or、not)
下面是上述的例子
select Sname from student where sdept='cs';
select Sname from student where sage between 20 and 30;(如果用not between and 就是不在这个范围的)
//使用谓词来查找属性是否属于指定集合元祖
select sname from student where sdept in('cs','ma','is');
select sname from student where sname like '刘%';
select sname from student where sname like '_勇';
// %用来代表任意长度的字符串
// _下划线代表是任意字符
select sno from sc where grade is not null;
select sname from student where sdept='cs' and sage<20;
order by子句
用户可以用order by子句对查询结果按照一个或多个属性列进行排序,默认是升序。
select sno ,grade from sc where cno='3' order by grade desc;//升序是asc
聚集函数
- count(*) ——-统计元祖的个数
- count(distinct 列名)——统计某个列值的个数
- sum&#x