sys.all_object
--all objects
select * from sys.all_object;
--database system datetime format
set Dateformat YMD|MDY|DMY;
--user-defined type
create type SSN from varchar(11) not null;
--drop user-defined type
drop type SSN;
information_schema.columns
--check table struct
select * from information_schema.columns;
distinct
distinct只能放在第一个列名前,且一个查询中只允许有一个distinct关键字。(即一个distinct只允许紧跟select之后)
top n or top n percent
--top n records (contain n)
selec top n * from table_name;
--top n percent
select top n percent * from table_name;
all
默认为all。all、top、distinct语法地位一样。
not like排除查询
包含通配符的模糊查询 like '%[%]%', like '%[_]%'
[^]表示用于匹配没有在方括号中列出的字符
escape转义字符like '%X%%' escape 'X'
按姓氏笔画排序
order by s_name collate Chinese_prc_stroke_cs_as_ks_ws
查询排序规则支持情况
select * from ::fn_helpcollations();
order by:
1.对xml、ntext、text、image类型字段不能使用order by子句
2.空值(null)按最低值处理
3.只影响显示效果,并未改变物理表中的记录位置
having子句:
1.必须与group by搭配使用
2.与where子句的区别
where用于对行记录进行筛选
having用于对组进行筛选