SQL Server编程:从T-SQL到CLR的选择与实践
1. SQL操作代码示例与分析
首先来看一段SQL代码:
UPDATE contact
SET contactNotes = inserted.contactNotes
FROM sales.contact as contact
JOIN inserted
ON inserted.contactId = contact.contactId
--this correlated subquery checks for rows that have changed
WHERE EXISTS (SELECT *
FROM deleted
WHERE deleted.contactId = inserted.contactId
AND deleted.contactNotes <> inserted.contactNotes
or (deleted.contactNotes is null and
inserted.contactNotes is not null)
or (deleted.contactNotes is not null and
inserted.contactNotes is null))
END TRY
BEGIN CATCH
IF @@trancount > 0
ROLLBACK TRANSACTION
EXECUTE dbo.errorLog$insert
DECLARE @ERROR_MESSAGE varchar(8000)
SET @ERROR_MESSAGE = ERROR_MESSAGE()
RAISERROR (@ERR