错误 - 无法绑定多部分标识符

时间:2014-08-14 00:37:21

标签: sql-server sql-server-2008 stored-procedures

我正在尝试创建一个存储过程,如下所示:

as  
  if(@ItemRefID = 47011 and @Operation = 16)
  begin 
     declare @TotalSP int 
     declare @TotalSPMastery int 

     SELECT 
         @TotalSP = SUM(_RefSkill.ReqLearn_SP) 
     FROM 
         SRO_VT_SHARD.dbo._RefSkill, SRO_VT_SHARD.dbo._CharSkill 
     WHERE 
         _RefSkill.ID = _CharSkill.SkillID 
         AND _CharSkill.CharID = @CharID 
         AND _RefSkill.ReqCommon_MasteryLevel1 <= '110' 

     SELECT 
         @TotalSPMastery = SUM(_RefLevel.Exp_M) 
     FROM 
         SRO_VT_SHARD.dbo._CharSkillMastery, SRO_VT_SHARD.dbo._RefLevel 
     WHERE 
         _RefLevel.Lvl = _CharSkillMastery.Level 
         AND _CharSkillMastery.CharID = @CharID 
         AND _CharSkillMastery.Level <= '110' 

     UPDATE SRO_VT_SHARD.dbo._Char 
     SET RemainSkillPoint = RemainSkillPoint + @TotalSP + @TotalSPMastery + 200000 
     WHERE CharID = @CharID 

     DELETE _CharSkill 
     FROM SRO_VT_SHARD.dbo._RefSkill, SRO_VT_SHARD.dbo._CharSkill 
     WHERE _RefSkill.ID = _CharSkill.SkillID 
      AND _CharSkill.CharID = @CharID 
      AND _RefSkill.ReqCommon_MasteryLevel1 <= '110' 
      AND _RefSkill.ID NOT IN (1, 70, 40, 2, 8421, 9354, 9355, 11162, 9944, 8419, 8420, 11526, 10625) 

    UPDATE SRO_VT_SHARD.dbo._CharSkillMastery 
    SET Level = '0' 
    WHERE CharID = @CharID AND Level <= '110'

但我收到这些错误消息:

  

Msg 4104,Level 16,State 1,Procedure _AddLogItem,Line 23
  多部分标识符&#34; _RefSkill.ID&#34;无法受约束。

     

Msg 4104,Level 16,State 1,Procedure _AddLogItem,Line 23
  多部分标识符&#34; _CharSkill.SkillID&#34;无法受约束。

     

Msg 4104,Level 16,State 1,Procedure _AddLogItem,Line 23
  多部分标识符&#34; _CharSkill.CharID&#34;无法受约束。

     

Msg 4104,Level 16,State 1,Procedure _AddLogItem,Line 23
  多部分标识符&#34; _RefSkill.ReqCommon_MasteryLevel1&#34;无法受约束。

     

Msg 4104,Level 16,State 1,Procedure _AddLogItem,Line 23
  多部分标识符&#34; _RefSkill.ReqLearn_SP&#34;无法受约束。

     

Msg 4104,Level 16,State 1,Procedure _AddLogItem,Line 24
  多部分标识符&#34; _RefLevel.Lvl&#34;无法受约束。

     

Msg 4104,Level 16,State 1,Procedure _AddLogItem,Line 24
  多部分标识符&#34; _CharSkillMastery.Level&#34;无法受约束。

     

Msg 4104,Level 16,State 1,Procedure _AddLogItem,Line 24
  多部分标识符&#34; _CharSkillMastery.CharID&#34;无法受约束。

     

Msg 4104,Level 16,State 1,Procedure _AddLogItem,Line 24
  多部分标识符&#34; _CharSkillMastery.Level&#34;无法受约束。

     

Msg 4104,Level 16,State 1,Procedure _AddLogItem,Line 24
  多部分标识符&#34; _RefLevel.Exp_M&#34;无法受约束。

为什么?

1 个答案:

答案 0 :(得分:1)

嗯,有一件事:你不能一次从两个表中删除:

DELETE _CharSkill 
FROM SRO_VT_SHARD.dbo._RefSkill, SRO_VT_SHARD.dbo._CharSkill 

这是无效的T-SQL语法 - 您必须分别从每个表中删除。

而且,你还在使用旧的SQL-89&#34;加入&#34;语法:

SELECT 
     @TotalSP = SUM(_RefSkill.ReqLearn_SP) 
FROM 
     SRO_VT_SHARD.dbo._RefSkill, SRO_VT_SHARD.dbo._CharSkill 
WHERE 
     _RefSkill.ID = _CharSkill.SkillID 

已被适当的ANSI JOIN语法替换为SQL-92标准(超过20年前!) - 这是首选加入方式 - 你应养成使用这个&#34; new&#34;语法!

SELECT 
     @TotalSP = SUM(_RefSkill.ReqLearn_SP) 
FROM 
     SRO_VT_SHARD.dbo._RefSkill
INNER JOIN  
     SRO_VT_SHARD.dbo._CharSkill ON _RefSkill.ID = _CharSkill.SkillID 

这使得你加入的更加清晰,以及 JOIN条件的(它并未隐藏在所有其他条件中{ {1}}条件某处 - 它清晰而明显)