• sql 创建多表删除的存储过程


    CREATE PROCEDURE [dbo].[存储哦过程的名称]

    @userID varchar(50) --声明变量
    AS
    BEGIN
    IF(@userID='' OR @userID IS NULL) --判断是否输入
    BEGIN
       SELECT '0' as 'message','请输入要删除的用户ID!' AS 'ErrorInfo' --提示信息
       RETURN
    END

    BEGIN TRANSACTION --开启事务

    DELETE FROM 表1 WHERE ID = @userID; --删除表中数据
    IF(@@ERROR<>0)
    BEGIN
       ROLLBACK TRANSACTION;
       SELECT '0' as 'message','删除失败!' AS 'ErrorInfo'
       RETURN
    END

    DELETE FROM 表2 WHERE ID = @userID; --删除表中数据
    IF(@@ERROR<>0)
    BEGIN
       ROLLBACK TRANSACTION;
       SELECT '0' as 'message','删除失败!' AS 'ErrorInfo'
       RETURN
    END

    DELETE FROM 表3 WHERE ID = @userID; --删除表中信息
    IF(@@ERROR<>0)
    BEGIN
       ROLLBACK TRANSACTION;
       SELECT '0' as 'message','删除失败!' AS 'ErrorInfo'
       RETURN
    END COMMIT TRANSACTION;
    SELECT '0' as 'message','删除成功!' AS 'ErrorInfo'
    END;

  • 相关阅读:
    F
    D
    J
    M
    H
    L
    Android线程之间的通讯
    Java4Android基础学习之异常
    Java4Android基础学习之接口
    Java4Android基础学习之包与访问权限
  • 原文地址:https://www.cnblogs.com/yuanye0918/p/6923334.html
Copyright © 2020-2023  润新知