要给一张表A新增历史记录,历史表B比A多几个字段记录操作人、时间等,使用存储过程可简单完成
_ueditor_page_break_tag_
USE [M2Financial] GO /****** Object: StoredProcedure [dbo].[SPD_InsertVehicle] Script Date: 12/04/2013 11:22:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[SPD_AddHisVehicle]( @VehicleCode char(10), @OperAccount varchar(50), @OperName varchar(100), @OperContent varchar(200) ) AS BEGIN SET NOCOUNT ON; --新增历史记录 Begin Tran insert into His_Vehicle select @OperAccount,@OperName,@OperContent,* from inf_Vehicle where VehicleCode=@VehicleCode If @@error <> 0 Begin ROLLBACK Select '数据库错误原因' ErrMessage, @@Error ErrCode Return End COMMIT TRAN Select '插入成功' ErrMessage, 0 ErrCode END GO