sql server学习笔记(1)基础语法

1、–select语句的基本查询使用语法

select   列名表
from     表名
[ where    条件 ]

2、数据汇总查询的语法格式
用聚合函数、group  by子句、compute…by子句

select    列名表
from      表名[,……n]
[ where    条件 ]
[ group   by  列名  ]
[ having       逻辑表达式 ]
[ order   by  列名  ]
[ compute   聚集函数   [ by 列名]  ]

3、连接查询SQL  Server语法形式:

select  列名表
from     表1, 表2
where    表1.列名1 = 表2.列名2 

4.插入单行数据命令格式

insert    [ into ]  表名
[ (字段名列表) ]
values (字段值列表) 

5.命令格式

update  表名
set  {列名 = 表达式 | null | default }  [ , … n ] )
[ where   逻辑表达式 ] 

6.命令格式

delete    表名
[ where   逻辑表达式 ]

7.视图最基本的语句格式:

create   view   视图
[ (列名表) ]
[ with  encryption ]
as
select查询语句
[ with   check  option ]

8、索引命令格式

create [ unique ] [ clustered | nonclustered ]
index   索引名
on { 表名 | 视图名 } ( 列名 [ asc | desc ] [ , ...n ] )

9.创建存储过程格式:

create   proc[edure]   存储过程名
@形参   数据类型 [=默认值] ,…n
as    SQL语句

相应的执行格式:

[execute]  存储过程名  [ @实参= ] 值 ,…n

输入参数的传递方式有两种:
按位置传递:直接给出参数的值,实参与形参一一对应
通过参数名传递:使用“参数名=参数值“的形式,参数可以任意顺序给出。

10、创建格式:

create   trigger    触发器名     on   表名| 视图名
for   |  after   |  instead   of      [ insert ,  update,  delete ]
as       SQL语句

说明:
1个表上可有多个触发器。
每个触发器只能作用在一个表上。

点赞