代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
MSSQL
】
SQL 框架
作者:
Dezai.CN
/ 发布于
2011/6/15
/
644
<div>--Start Customer_Set CREATE PROCEDURE [dbo].[Customer_Set] @Name as varchar(50), @Address as varchar(250), @Mobile as varchar(50) AS BEGIN</div> <div>SET NOCOUNT ON</div> <div>--Validation IF @Name IS NULL BEGIN RAISERROR ('Name cannot be empty.',16,1) END</div> <div>IF LEN(@Name)<3 BEGIN RAISERROR ('Name cannot be less than 3 characters.',16,1) END</div> <div>--Data Insertion BEGIN TRY INSERT INTO [dbo].[Customer] ([Name] ,[Address] ,[Mobile]) VALUES (@Name ,@Address ,@Mobile) END TRY BEGIN CATCH RETURN (0) END CATCH</div> <div>RETURN (1) END --End Customer_Set</div> <div> --Start Supplier_Set CREATE PROCEDURE [dbo].[Supplier_Set] @Name as varchar(50), @Address as varchar(250), @Mobile as varchar(50) AS BEGIN</div> <div>SET NOCOUNT ON</div> <div>--Validation IF @Name IS NULL BEGIN RAISERROR ('Please enter suppiler name.',16,1) END</div> <div>IF LEN(@Name)<3 BEGIN RAISERROR ('Supplier name cannot be less than 3 characters.',16,1) END</div> <div>--Data Insertion BEGIN TRY INSERT INTO [dbo].[Supplier] ([Name] ,[Address] ,[Mobile]) VALUES (@Name ,@Address ,@Mobile) END TRY BEGIN CATCH RETURN (-1) END CATCH</div> <div>RETURN (1) END --End Supplier_Set</div> <div>--Start GetValidationConstraint CRAETE PROCEDURE [dbo].[GetValidationConstraint] --Output values @EmptyCheck int OUTPUT, @LenCheck int =NULL OUTPUT, @NoDataExist int =NULL OUTPUT, @True bit =NULL OUTPUT, @False bit =NULL OUTPUT AS BEGIN SELECT @EmptyCheck=1 SELECT @LenCheck =2 SELECT @NoDataExist =3</div> SELECT @True=1 SELECT @False=0 END --End GetValidationConstraint</div> <div> --Start ReturnMessage CREATE PROCEDURE [dbo].[ReturnMessage] --Success, Fail is the order of output parameter @Success int OUTPUT, @Fail int OUTPUT AS SET NOCOUNT ON</div> <div>BEGIN SELECT @Fail=0 SELECT @Success=1 END --End ReturnMessage</div> <div>--Start MessageHelper CREATE PROCEDURE [dbo].[MessageHelper] --Input values @Field varchar(200) =NULL, @MinLenght int =NULL, @ValidationConstraint int, --Output values @ValidationMessage varchar(200) OUTPUT AS BEGIN --Variables DECLARE @EMPTY_MESSAGE varchar(50), @MINIMUM_LENGHT_MESSAGE varchar(50), @NO_DATA_EXIST_MESSAGE varchar(50)</div> <div> DECLARE @EMPTY int, @LEN int, @NO_DATA_EXIST int</div> <div>DECLARE @SUCCESSED int, @FAILED int</div> <div>--Message Constraint SET @EMPTY_MESSAGE = 'cannot be empty.' SET @MINIMUM_LENGHT_MESSAGE ='cannot be less than' SET @NO_DATA_EXIST_MESSAGE = 'No record found.' --Get global values EXEC ReturnMessage @SUCCESSED output, @FAILED output EXEC GetValidationConstraint @EMPTY OUTPUT, @LEN OUTPUT, @NO_DATA_EXIST OUTPUT</div> <div>--Set message IF @ValidationConstraint = @EMPTY BEGIN IF LEN(@Field)<=0 BEGIN RAISERROR('Field name cannot be empty. StoreProcedure/MessageHelper',16,1) RETURN @FAILED END SELECT @ValidationMessage = @Field + ' ' + @EMPTY_MESSAGE END</div> <div>IF @ValidationConstraint = @LEN BEGIN IF @MinLenght IS NULL OR @MinLenght <=0 BEGIN RAISERROR('Minimum length cannot be empty. StoreProcedure/MessageHelper',16,1) RETURN @FAILED END ELSE BEGIN SELECT @ValidationMessage = @Field + ' ' + @MINIMUM_LENGHT_MESSAGE + ' ' + CONVERT(varchar, @MinLenght) END END</div> <div>IF @ValidationConstraint = @NO_DATA_EXIST BEGIN SELECT @ValidationMessage = @NO_DATA_EXIST_MESSAGE END END --End MessageHelper</div> <div>--Start Customer_Set CREATE PROCEDURE [dbo].[Customer_Set] --Input values @Name as varchar(50), @Address as varchar(250), @Mobile as varchar(50), --Output values @LASTID bigint OUTPUT, @MESSAGE varchar(200) =NULL OUTPUT AS SET NOCOUNT ON BEGIN --Constraint Variables For Readable Return Value DECLARE @SUCCESSED int, @FAILED int</div> <div>--Constraint Variables For Readable Validation Operation DECLARE @EMPTY int, @LEN int BEGIN TRY --Get constraint value for successed and failed EXEC ReturnMessage @SUCCESSED output, @FAILED output --Get constraint value for validation. @EMPTY is for empty check and @LEN is for length check common messaging system. EXEC GetValidationConstraint @EMPTY output, @LEN output --Validation IF LEN(@Name)=0 BEGIN EXEC MessageHelper 'Name', @EMPTY,@MESSAGE OUTPUT --It will generate a common empty message. RETURN @FAILED-- Readable Failed Return END</div> <div>IF LEN(@Name)<3 BEGIN EXEC MessageHelper 'Name',3, @LEN,@MESSAGE OUTPUT --It will generate a common length check message. RETURN @FAILED-- Readable Failed Return END --Data insertion INSERT INTO [dbo].[Customer] ([Name] ,[Address] ,[Mobile]) VALUES (@Name ,@Address ,@Mobile) SELECT @LASTID=SCOPE_IDENTITY() END TRY BEGIN CATCH -- Error Traping Section DECLARE @ErrorMessage nvarchar(4000); DECLARE @ErrorSeverity int; DECLARE @ErrorState int; SELECT @ErrorMessage = ERROR_MESSAGE(), @ErrorSeverity = ERROR_SEVERITY(), @ErrorState = ERROR_STATE(); RAISERROR (@ErrorMessage,@ErrorSeverity,@ErrorState); RETURN @FAILED -- Readable Failed Return END CATCH</div> <div>RETURN @SUCCESSED -- Readable Successed Return END --End Customer_Set</div> <div>--Start Customer_Get CREATE PROCEDURE [dbo].[Customer_Get] --Output values @TOTAL_ROWS bigint OUTPUT, @MESSAGE varchar(200) =NULL OUTPUT AS BEGIN SET NOCOUNT ON --Variables DECLARE @SUCCESSED int, @FAILED int</div> <div>DECLARE @EMPTY int, @LEN int, @NO_DATA_EXIST int BEGIN TRY --Get constraint value EXEC ReturnMessage @SUCCESSED OUTPUT, @FAILED OUTPUT EXEC GetValidationConstraint @EMPTY OUTPUT, @LEN OUTPUT,@NO_DATA_EXIST OUTPUT --Validation IF (SELECT COUNT(CustomerId) FROM Customer )<= 0 BEGIN EXEC MessageHelper '', @NO_DATA_EXIST,@MESSAGE OUTPUT --It will generate common no data exist message. SELECT @TOTAL_ROWS=0 RETURN @SUCCESSED END --Data retrival SELECT [CustomerId] ,[Name] ,[Address] ,[Mobile] FROM [dbo].[Customer]</div> <div>--Get total rows SELECT @TOTAL_ROWS=@@ROWCOUNT END TRY BEGIN CATCH DECLARE @ErrorMessage nvarchar(4000); DECLARE @ErrorSeverity int; DECLARE @ErrorState int; SELECT @ErrorMessage = ERROR_MESSAGE(), @ErrorSeverity = ERROR_SEVERITY(), @ErrorState = ERROR_STATE(); RAISERROR (@ErrorMessage,@ErrorSeverity,@ErrorState); RETURN @FAILED END CATCH</div> <div>RETURN @SUCCESSED END --End Customer_Get</div> <div>--Start Customer_DeleteById CREATE PROCEDURE [dbo].[Customer_DeleteById] --Input values @CustomerId bigint, @MESSAGE varchar(200) =NULL OUTPUT AS BEGIN --Variables DECLARE @SUCCESSED int, @FAILED int</div> <div>DECLARE @EMPTY int, @LEN int</div> <div>BEGIN TRY --Get constraint value EXEC ReturnMessage @SUCCESSED OUTPUT, @FAILED OUTPUT EXEC GetValidationConstraint @EMPTY OUTPUT, @LEN OUTPUT --Validation IF @@CustomerId <=0 BEGIN EXEC MessageHelper 'Customer Id', @EMPTY,@MESSAGE OUTPUT RETURN @FAILED END --Data deletion DELETE FROM [dbo].[Customer] WHERE (CustomerId = @CustomerId)</div> <div>END TRY BEGIN CATCH DECLARE @ErrorMessage nvarchar(4000); DECLARE @ErrorSeverity int; DECLARE @ErrorState int; SELECT @ErrorMessage = ERROR_MESSAGE(), @ErrorSeverity = ERROR_SEVERITY(), @ErrorState = ERROR_STATE(); RAISERROR (@ErrorMessage,@ErrorSeverity,@ErrorState); RETURN @FAILED END CATCH</div> <div>RETURN @SUCCESSED END</div> <div>--End Customer_DeleteById</div>
试试其它关键字
SQL
框架
同语言下
.
SQL查询 多列合并成一行用逗号隔开
.
查看存储过程修改时间,最近执行时间
.
设置手动批量删除数据库相关进程
.
获取某个表中特定字段的所有字符串形式
.
SQL 如何去除重复的字符串
.
怎么去掉一个字段中的重复数据
.
String 去除空格 回车 换行 水平制表符
.
SQL查询和替换含有回车,空格,TAB
.
SQL SERVER 查询每日新增用户数量、次留数量
.
判断两个字符串是否存在相同的内容
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3