我创建了两个名为enquiry_master
和enquiry_master_hist
..
我正在使用SQL Server Trigger更新表refference_no
上的列enquiry_master
。
现在我想插入enquiry_master_hist
,其中包含插入enquiry_master
的相同数据。所有精细数据都在插入,但更新的列只插入旧数据......
有什么方法可以在SQL Server触发器中获取更新数据???这是代码
UPDATE enquiry_master
SET enquiry_master.reference_no = pass.RandomPassword
FROM #Users tmp
CROSS APPLY dbo.GeneratePassword_Real(CRYPT_GEN_RANDOM(@RefferenceNOLength)) pass
WHERE enquiry_master.enquiry_id = @EnquiryId;
DECLARE @InsertedID AS INT;
select @EnquiryId = i.enquiry_id from inserted i;
select @UpdatedRefference = i.reference_no from inserted i;
SET IDENTITY_INSERT enquiry_master_hist ON
INSERT INTO enquiry_master_hist([enquiry_id],
[enquiry_source_id],
[reference_no],
[assigned_staff_no],
[emp_id],
[status_id],
[remarks],
[enquiry_date_time],
[departing_from],
[travelling_to],
[departing_date],
[returning_date],
[hotel_name],
[airline],
[flight_class],
[no_of_adult_passangers],
[no_of_child_passangers],
[no_of_infant_passangers],
[taxes],
[from_price],
[total_price],
[name],
[home_office_no],
[mobile_no],
[prefered_callback_time],
[email],
[additional_comments],
[from_website],
[from_campaign],
[enquiry_type_id],
[type_of_group],
[budget],
[supplier],
[trip_code],
[trip_name],
[no_of_countries],
[no_of_days],
[countries],
[deal_reference_no],
[how_did_know],
[no_of_rooms],
[bedding],
[room_views],
[board_basis],
[system_date],
[system_time]
)
VALUES(
@EnquiryId,
@EnquirySourceId,
@UpdatedRefference,
@AssignedStaffNo,
@EmpId,@StatusId,
@Remarks,
@EnquiryDatetime,
@DepartingFrom,
@TravellingTo,
@DepartingDate,
@ReturningDate,
@HotelName,
@Airline,
@FlightClass,
@NoOfAdults,
@NoOfChild,
@NoOfInfant,
@Taxes,
@FromPrice,
@TotalPrice,
@Name,
@HomeofficeNo,
@MobileNo,
@PreferedCallbackTime,
@Email,
@AdditionalComments,
@FromWebsite,
@FromCompaign,
@EnquiryTypeId,
@TypeOfGroup,
@Budget,
@Supplier,
@TripCode,
@TripName,
@NoOfCountries,
@NoOfDays,
@Countries,
@DealRefferenceNo,
@HowDidknow,
@NoOfRooms,
@Bedding,
@RoomViews,
@BoardBasis,
@SystemDate,
@SystemTime)
SET IDENTITY_INSERT enquiry_master_hist OFF
END
强文
答案 0 :(得分:0)
您无法获得任何更新的动态表格。 SQL只允许插入和删除。在更新命令的情况下,先前的数据存储在已删除的动态表中,新值存储在插入的动态表中。