SQL SERVER 2005 存储过程
USE AdventureWorks
GO
CREATE PROC spEmployee
AS
SELECT * from Humanresources.Employee
EXEC spEmployee
ALTER PROC spEmployee
AS SELECT EmployeeID from Humanresources.Employee
drop proc spEmployee
ALTER PROC spEmployee
@LastName nvarchar(50) = NULL
AS
IF @LastName IS NULL
SELECT * from HumanResources.Employee
ELSE
SELECT c.LastName,c.FirstName,e.*
from Person.Contact c
INNER JOIN HumanResources.Employee e
ON c.ContactID = e.ContactID
WHERE c.LastName LIKE @LastName + '%'
EXEC spEmployee
BEGIN TRY
CREATE TABLE OurIFTest
(
COL INT PRIMARY KEY
)
END TRY
BEGIN CATCH
DECLARE @MyOutParameter int
IF ERROR_NUMBER() = 2714
BEGIN
PRINT 'WARNING SHIPPING CREATE AS TABLE ALREADY EXISTS'
EXEC dbo.uspLogError @ErrorLogID = @MyOutParameter OUTPUT
PRINT 'A ERROR WAS LOGGED.THE ERROR ID WAS ' + CAST(@MyOutParameter AS VARCHAR)
END
ELSE
RAISERROR('SOMETHINGS NOT GOOD HAPPENED THIS AROUND',16,1)
END CATCH
DROP TABLE OurIFTest
CREATE TABLE OurIFTest
(
COL INT PRIMARY KEY
)
IF @@ERROR != 0
PRINT 'PROBLEM'
ELSE
PRINT 'EVERYTHING ID OK !'
CREATE PROC spTestRETURN
AS
DECLARE @MyMessage varchar(50)
DECLARE @MyOtherMessage varchar(50)
SELECT @MyMessage = 'HI,IT''S THAT LINE BEFOR THE RETURN'
PRINT @MyMessage
RETURN
SELECT @MyOtherMessage = 'SORRY,BUT WE WON''T GET THIS FAR'
RETURN @MyOtherMessage
RETURN
ALTER PROC spTestRETURN
AS
DECLARE @MyMessage varchar(50)
DECLARE @MyOtherMessage varchar(50)
SELECT @MyMessage = 'HI,IT''S THAT LINE BEFOR THE RETURN'
PRINT @MyMessage
RETURN 100
SELECT @MyOtherMessage = 'SORRY,BUT WE WON''T GET THIS FAR'
PRINT @MyOtherMessage
RETURN
DECLARE @ReturnVal int
EXEC @ReturnVal = spTestRETURN
SELECT @ReturnVal
DECLARE @Error int
INSERT INTO Sales.Individual
(CustomerID,ContactID)
VALUES
(0,0)
SELECT @Error = @@ERROR
PRINT ''
PRINT 'THE VALUE OF ERROR IS ' + CONVERT(VARCHAR,@Error)
PRINT 'THE VALUE OF @@ERROR IS ' + CONVERT(VARCHAR
相关文档:
摘要
对于SQL Server中的约束,想必大家并不是很陌生。但是约束中真正的内涵是什么,并不是很多人都很清楚的。本文以详细的文字来介绍了什么是约束,以及如何在数据库编程中应用和使用这些约束,来达到更好的编程效果。(本文部分内容参考了SQL Server联机手册)
内容
数据完整性分类
实体完整性
&nb ......
//取出源数据
select groupname,totalnum,inputdate,groupid into #temp from
(select count(*)as totalnum,p.groupid,g.groupname,convert(nvarchar(10),inputdate,120) as 'inputdate'
from person p left join admin_group g on p.groupid = g.groupid and deleteflag = '0'
where p.inactive=' ......
. SQL 命令
这部分包含那些 PostgreSQL 支持的 SQL 命令的信息.这里的 "SQL" 就是该语言通常的含义; 每条命令的与标准有关的兼容性的信息可以在相关的参考页中找到.
Table of Contents
ABORT -- 退出当前事务
ALTER GROUP -- 向组中增加用户或从组中删除用户
ALTER USER -- 改变数据库 ......
通配符 说明
_ 与任意单字符匹配
% 与包含一个或多个字符的字符串匹配
[ ] 与特定范围(例如,[a-f])或特定集(例如,[abcdef])中的任意单字符匹配。
[^] 与特定范围(例如,[^a-f])或特定集(例如,[^abcdef])之外的任意单字符匹配。 ......
摘自http://hi.baidu.com/dusongw/blog/item/4090493d6ec0cdee3d6d97a6.html
我将以“办公自动化”系统为例,探讨如何在有着1000万条数据的MS SQL SERVER数据库中实现快速的数据提取和数据分页。以下代码说明了我们实例中数据库的“红头文件”一表的部分数据结构:
CREATE TABL ......