SQL Server2005学习笔记(1)

来源:互联网 发布:哪个打车软件好 编辑:程序博客网 时间:2024/06/06 20:56

1、sqlServer中的DateAdd(datepart,number,date)----在指定日期加上一段时间的基础上,返回新的datetime值
   例:dateadd(day,-1,getdate())) 表示当前时间减去1天,就是昨天

2、sqlServer中的Convert函数
   1)将日期转换成字符串 SELECT CONVERT(varchar(100), GETDATE(), 1): 12/21/07

3、如果一个where子句中同时出现 and or not 三个操作符,最先评估 not ,然后是 and ,最后是 or  

4、关键字 like
   like   例子:like "xland%"
   %和_是通配符
   %代表零个或多个任意字符
  _表示单个任意字符
  把字符包括在方括号中
  [a-c]表示a c都可行
  [ab]表示a或b
  ^与not表示下一个字符将被排除掉 

5、sql中的in和exist
   两个表,一个大表,一个小表,子查询 大表用exist,子查询 小表用in
   例如:A(小表),B(大表)
         select from where cc in (select cc from B) 效率低
         select from where exists(select cc from where cc=A.cc) 效率高

6、distinct关键字
   select  count(distinct  column) from table 
   检索某一列不重复的记录数

 

 

0 0