使用触发器

时间:2015-12-03 21:12:14

标签: sql-server

我在竞争表中插入行后尝试使用SQL Server 2014中的触发器更新列。

我需要将竞争表中的judge_Id从NULL更新到judge表中的judge_ID。 judge_ID需要在专业知识表中进行游泳评判(这是游泳比赛)。

然后我需要将competition.judges_ID与来自competition.judges_ID的计数一起插入一个具有最低计数的评判ID。 (即在评委之间平均分配相关的评委工作量)

这是我尝试过的。

我知道这不对,因为我不确定如何加入。

CREATE TRIGGER [dbo].[trg_insertJudge]
   ON [dbo].[competition]
AFTER INSERT
AS
BEGIN
   SET NOCOUNT ON;

   INSERT INTO [dbo].[competition.judges_ID]
   WITH [dbo].[judges.judges_ID]

   SELECT

   FROM [dbo].[judges.judges_ID] 

   WHERE [dbo].[judges.judges_ID] = [judges2expertise.judges_ID]

   AND

   [dbo].[judges2expertise.expertiseType] = 3

   SELECT 

   FROM [dbo].[judges.judges_ID] 

   WHERE 

   COUNT [dbo].[competition.judges_ID] 

   FROM [dbo.competition.judgesID]

   SELECT MIN [dbo.competition.judgesID]

END

0 个答案:

没有答案