我有3個表tblteam
,tblaccount
和tbluser
有以下的列:軟刪除使用SQL Server存儲過程
tblTeam
:
(TeamId int,
TeamName varchar(20),
IsDeleted bit)
tblUser
:
(UserId int,
UserName varchar(20),
TeamId int)
tblAccount
:
(AccountId int,
AccountName varchar(20),
TeamId int,
UserId int
)
我想要做什麼是我想要更新1
刪除列爲此,我曾嘗試
Create procedure sp_isdeleted(
@pteamid int
As
Begin
Update tblTeam
set IsDeleted = 1
Where TeamId = @pteamid
End
但我想,如果團隊與任何用戶相關聯或帳戶和任何用戶仍然在隊Isdeleted
仍然是0.
我該如何檢查這種情況?請幫忙。
備註:您應該**不要**爲存儲過程使用'sp_'前綴。微軟已經保留了這個前綴以供自己使用(參見*命名存儲過程*)](http://msdn.microsoft.com/en-us/library/ms190669%28v=sql.105%29.aspx),以及你將來有可能冒着名字衝突的風險。 [這對你的存儲過程性能也是不利的](http://www.sqlperformance.com/2012/10/t-sql-queries/sp_prefix)。最好只是簡單地避免使用'sp_'並將其他內容用作前綴 - 或者根本沒有前綴! –
@marc_c好吧我會用不同的前綴。非常感謝你回答 – Felixerity