-1
在這裏,您可以在SQL中看到我的表的代碼,存儲過程正在工作,但行中未填充信息。代碼有什麼問題?INSERT的存儲過程不起作用
CREATE TABLE Category_Master(
Category_ID INT IDENTITY(1,1) PRIMARY KEY,
Category_Name VARCHAR(50),
modification_Date DATETIME DEFAULT GETDATE()
)
Select * from Category_Master
Go
create trigger TRIGGER_MODIFDATE_Category_Master
on Category_Master
for insert, update
as begin
UPDATE Category_Master
SET modification_Date = GETDATE()
end
Go
CREATE PROCEDURE usp_InsertCategory_Master
@flag bit output,-- return 0 for fail,1 for success
@Category_ID int,
@Category_Name varchar(50)
AS
BEGIN
BEGIN TRANSACTION
BEGIN TRY
INSERT INTO Category_Master(Category_ID, Category_Name)
VALUES (@Category_ID, @Category_Name)
SET @flag = 1;
IF @@TRANCOUNT > 0
BEGIN
COMMIT TRANSACTION;
END
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
END
SET @flag = 0;
END CATCH
END
Go
Declare @flag bit
EXEC usp_InsertCategory_Master @flag output, 1, 'Short LOAN'
EXEC usp_InsertCategory_Master @flag output, 2, 'Long LOAN'
if @flag=1
print 'Successfully inserted'
else
print 'There is some error'
您的觸發也不好,它會更新所有記錄,而不僅僅是你插入或更新的記錄。 YOu需要加入到插入的表中才能獲取受插入或更新影響的記錄。 – HLGEM