易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL存储过程基础语法

一.注释
-- 单行注释,从这到本行结束为注释sql 语法,类似C++,c#中//
/* … */ 多行注释,类似C++,C#中/* … */
二.变量(int, smallint, tinyint, decimal,float,real, money ,smallmoneysql 语法, text ,image, char, varchar。。。。。。)
语法:
DECLARE
{
{@local_variable data_type}
} [,...n]
例如:
declare @ID int --申明一个名为@ID的变量,类型为int型
三.在SQL Server窗口中打印出变量的值
语法:
PRINT 'any ASCII text' | @local_variable | @@FUNCTION | string_expr
四.变量赋值
例如:
--从数据表中取出第一行数据的ID,赋值给变量@id,然后打印出来
Declare @ID int
Set @ID = (select top(1) categoryID from categories)
Print @ID
在SQL中,我们不能像代码那样直接给变量赋值,例如@id = 1,如果要达到这样的功能,可以这样写:
Declare @ID int
Set @ID = (select 1) -- 类似 @ID=1
Select @id=1 -- 类似 @ID=1
Print @ID
五.变量运算(+,-,*sql 语法,/,……)
以下必要时候省略变量申明
Set @ID = (select 1+5) --类似 @ID=1+5
Set @ID=(select 1-@ID) --类似 @ID=1-@ID
六.比较操作符
? >(greater than).
? <(less than).
? = (equals).
? <= (less than or equal to).
? >= (greater than or equal to).
? != (not equal to).
? <>(not equal to).
? !< (not less than).
? !> (not greater than).
没什么说的
七.语句块:Begin … end
将多条语句作为一个块,类似与C++,C#中的{ }
例如:
Begin
Set @ID1 = (select 1)
Set @ID2 = (select 2)
End
八.If, if…else…
语法:
IF Boolean_expression
{sql_statement | statement_block}
[ELSE
{sql_statement | statement_block}]
例如:
If @id is not null
Print ‘@id is not null
if @ID = 1
begin
Set @ID = (select 1 + 1)
end
else
begin
set @ID=(select 1+2)
end
上面的例子用到了比较操作符,语句块,和IF的语法。
九.执行其他存储过程 EXEC
例如
EXEC dbo.[Sales by Year] @Beginning_Date=’1/01/90’, @Ending_Date=’1/01/08’
十.事务
语法:
BEGIN TRAN[SACTION] [transaction_name | @tran_name_variable]
例如
BEGIN TRAN
-- 做某些操作,例如In


相关文档:

pl/sql 语句的几点优化

1.
     SQL> desc gjh_a05 ;
Name  Type          Nullable Default Comments
----- ------------- -------- ------- --------
A0500 VARCHAR2(2)   Y           &nbs ......

获取SQL Server所有数据库名,表名,字段名


/*
 * Source URL: http://jonsion.javaeye.com/blog/511584
 */
1. 获取所有数据库名
1> SELECT name from master..sysdatabases;
2> go
2. 获取所有表名
1> USE master
2> go
1> SELECT name from sysobjects WHERE type='U';
2> go
3. 获取所有字段名
1> SELECT name ......

基于SQL的分页

select top PageSize * from 表
where 条件 and id not in
(select top PageSize*(CurrentPageIndex-1)  id from 表 where 条件 order by 排序条件)
order by 排序条件
《PageSize 是GridView中每页显示的信息条数,PageSize*(CurrentPageIndex-1) 在SQL中不识别,需定义变量来替换》 ......

Microsoft SQL Server 2008安装图解(Windows 7)

Microsoft SQL Server 2008
安装图解(Windows 7)
FoxDie
2010年04月17日
简介
本文详细记录了一次完整的Microsoft SQL Server 2008在Windows 7操作系统上的安装过程。注意:Microsoft SQL Server 2008与Windows 7操作系统存在一定的兼容性问题,在完成安装之后需要为Microsoft SQL Server 2008安装SP1补丁。下面将详细 ......

SQL面试题小结

 
我想面试过软件开发的朋友都会碰到sql方面的面试题,这个可以说是面试必考的。这里拿几个例子开拓一下思路。
1.      
有这样一张表
教师号
星期
是否有课
1
1

2
3

1
2

1
2

要得出这样的数据:
姓名
星期一
星期二
星期三
星期四
星期五
1
1 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号