我希望能够编写一个单元测试脚本,它将显示代码中每个语句的结果。当我使用inserted表运行脚本时,消息显示“插入了无效的对象名称'”。我现在发现测试逻辑的唯一方法是使用源表来测试代码,然后在创建触发器时从源表更改为插入。这将用作控制以促进代码到qa和生产。为插入表格的触发器编写单元测试脚本的最佳方法是什么? sql server 2008r
--insert test
INSERT INTO SIS.dbo.People (First_Name,Middle_Name,Last_Name)
SELECT
T.ForeName
,T.Middle_Name
,T.Surname
FROM CRM.dbo.Contact1 C
INNER JOIN SIS.dbo.People P
ON P.People_ID = C.Key4
CROSS APPLY dbo.NameParser(C.Contact) T
WHERE C.Key1 = '76'
--insert reference inserted table
INSERT INTO SIS.dbo.People (First_Name,Middle_Name,Last_Name)
SELECT
T.ForeName
,T.Middle_Name
,T.Surname
FROM inserted i --change to inserted
INNER JOIN SIS.dbo.People P
ON P.People_ID = i.Key4
CROSS APPLY dbo.NameParser(i.Contact) T
WHERE i.Key1 = '76'