基于SQL Server 的Exception Handling - PART II
2008-12-06 10:15:28 来源:WEB开发网· Create Role:T_ROLES_I
CREATE Procedure T_ROLES_I
(
@role_id varchar(50),
@role_name nvarchar(256)
)
AS
DECLARE @error_number INT
DECLARE @error_serverity INT
DECLARE @error_state INT
BEGIN TRY
IF(EXISTS(SELECT * FROM dbo.T_ROLES WHERE LOWERED_ROLE_NAME = LOWER(@ROLE_name) OR [ROLE_ID] = @role_id))
BEGIN
RAISERROR (50002,16,1)
END
INSERT INTO dbo.T_ROLES
([ROLE_ID]
,[ROLE_NAME]
,LOWERED_ROLE_NAME)
VALUES(@ROLE_id, @ROLE_name, LOWER(@ROLE_name))
END TRY
BEGIN CATCH
SET @error_number = ERROR_NUMBER()
SET @error_serverity =ERROR_SEVERITY()
SET @error_state = ERROR_STATE()
RAISERROR(@error_number,@error_serverity,@error_state)
END CATCH
· Add User in Role:P_USERS_IN_ROLES_I
CREATE Procedure P_USERS_IN_ROLES_I
(
@user_name NVARCHAR(256),
@role_name NVARCHAR(256)
)
AS
DECLARE @user_id VARCHAR(50)
DECLARE @role_id VARCHAR(50)
DECLARE @error_number INT
DECLARE @error_serverity INT
DECLARE @error_state INT
BEGIN TRY
SELECT @user_id = [USER_ID] FROM dbo.T_USERS WHERE LOWERED_USER_NAME = LOWER(@user_name)
IF(@user_id IS NULL)
BEGIN
RAISERROR (50003,16,1)
END
SELECT @role_id = [ROLE_ID] FROM dbo.T_ROLES WHERE LOWERED_ROLE_NAME = LOWER(@role_name)
IF(@role_id IS NULL)
BEGIN
RAISERROR (50004,16,1)
END
IF(EXISTS(SELECT * FROM T_USERS_IN_ROLES WHERE [USER_ID] = @user_id AND ROLE_ID = @role_id))
BEGIN
RAISERROR (50005,16,1)
END
INSERT INTO dbo.T_USERS_IN_ROLES([USER_ID],ROLE_ID) VALUES(@user_id,@role_id)
END TRY
BEGIN CATCH
SET @error_number = ERROR_NUMBER()
SET @error_serverity =ERROR_SEVERITY()
SET @error_state = ERROR_STATE()
RAISERROR(@error_number,@error_serverity,@error_state)
END CATCH
- ››sql server自动生成批量执行SQL脚本的批处理
- ››sql server 2008亿万数据性能优化
- ››SQL Server 2008清空数据库日志方法
- ››sqlserver安装和简单的使用
- ››SQL Sever 2008 R2 数据库管理
- ››SQL SERVER无法安装成功,sqlstp.log文件提示[未发...
- ››Sql Server中通过父记录查找出所有关联的子记录
- ››基于IP地址的vsftp服务器
- ››SqlServer触发器、存储过程和函数
- ››SQL Server 中的事务(含义,属性,管理)
- ››Sqlite数据库插入和读取图片数据
- ››Sql server 2005拒绝了对对象 'xx表' (数...
更多精彩
赞助商链接