我想刪除用戶(更新)我還有8個處理表,匹配表和futured表與用戶表相關。 我想如果我刪除(InActive)用戶然後必須從其他8表中刪除所有activitry我也寫了sp但我知道這是不正確的方式來做到這一點....我想使用連接(或其他方式)我怎麼能這樣做...請幫助我..謝謝加入多個表在sql server中刪除/更新
CREATE PROC [dbo].[bb_DeleteUser]
@userId int
AS
SET NOCOUNT ON
SET XACT_ABORT ON
BEGIN TRAN
UPDATE bb_user SET IsActive =0 WHERE user_id = @userId
IF EXISTS (SELECT * FROM DealA WHERE [user_id]= @userId)
BEGIN
update DealA
set [acq_veripro]= 'Del',[acq_status] = 'Closed',[acq_isclose] = 0,[acq_modifieddate]= Getdate()
where [user_id]= @userId
END
IF EXISTS (SELECT * FROM DealB WHERE [user_id]= @userId)
BEGIN
update DealB
set [fundfundraise_veripro]= 'Del',[fundfundraise_status] = 'Closed',[fundfundraise_isclose] = 0,[fundfundraise_modifieddate] = Getdate()
where [user_id]= @userId
END
IF EXISTS (SELECT * FROM DealC WHERE [user_id]= @userId)
BEGIN
update DealC
set [provider_veripro]= 'Del',[provider_status] = 'Closed',[provider_isclose] = 0,[provider_modifieddate] = Getdate()
where [user_id]= @userId
END
IF EXISTS (SELECT * FROM DealD WHERE [user_id]= @userId)
BEGIN
update DealD
set [seek_veripro]= 'Del',[seek_status] = 'Closed' ,[seek_isclose] = 0,[seek_modifieddate] = Getdate()
where [user_id]= @userId
END
IF EXISTS (SELECT * FROM DealE WHERE [user_id]= @userId)
BEGIN
update DealE
set [lpinvestor_veripro]= 'Del',[lpinvestor_status] = 'Closed',[lpinvestor_isclose] = 0,[lpinvestor_modifieddate]= Getdate()
where [user_id]= @userId
END
IF EXISTS (SELECT * FROM DealF WHERE [user_id]= @userId)
BEGIN
update DealF
set [sellseek_veripro]= 'Del',[sellseek_status] = 'Closed',[sellseek_isclose] = 0,[sellseek_modifieddate] = Getdate()
where [user_id]= @userId
END
IF EXISTS (SELECT * FROM Match WHERE Seeker_id [email protected] or [email protected] )
BEGIN
update Match
set [IsActive]=0 ,[Match_ModifiedDate]=GETDATE()
where Seeker_id [email protected] or [email protected]
END
IF EXISTS (SELECT * FROM Featured_Deal WHERE Deal_User_Id= @userId )
BEGIN
UPDATE Featured_Deal
set [Active_Status]= 0,[Modified_Date]= Getdate()
WHERE Deal_User_Id= @userId
END
COMMIT
一旦停用用戶,我不明白爲什麼有必要更新任何其他表。但是再次,我不明白爲什麼每筆交易都需要單獨的表格。 –
請不要這樣 - 爲什麼我們有很多交易表...只是想知道如何加入所有表刪除/更新? –
你的問題很混亂。 – Rahul