当前位置:Gxlcms > mysql > 交叉制表-验证对象的存在(3)

交叉制表-验证对象的存在(3)

时间:2021-07-01 10:21:17 帮助过:14人阅读

交叉制表-验证对象的存在(3) 交叉表 --通过考察sysobjects 表可以验证源对象的存在性.所有提供的三个列分别被检查以查看---他们对于提供的源对象在syscolumns表中是否存在. --check if source exists if not exists (select * from sysobjects where name=@c

交叉制表-验证对象的存在(3) 交叉表
--通过考察sysobjects 表可以验证源对象的存在性.所有提供的三个列分别被检查以查看---他们对于提供的源对象在syscolumns表中是否存在.
 --check if source exists     
if not exists
        (select * from sysobjects where name=@chrsource and type in(''v'',''u''))
    begin
       raiserror 51001 ''source does not exist.''
       return -1
    end
--check for column existence
  if not exists
  (select sc.name from syscolumns sc join sysobjects so on sc.id=so.id 
   where so.name=@chrsource and sc.name=@chrhead)
 begin
     raiserror 51002 ''invalid @chrcolhead name''
     return -1
 end
  if not exists
   (select sc.name from syscolumns sc join sysobjects so on sc.id=so.id
    where so.name=@chrsource and sc.name=@chrrowhead)
  begin
     raiserror 51002 ''invalid @chrrowhead name''
     return -1
 end
  
  if not exists
  (select sc.name from syscolumns sc join sysobjects so on sc.id=so.id
   where so.name=@chrsource and sc.name=@chrvalue)
 begin
     raiserror 51002 ''invalid @chrvalue name''
     return -1
 end
--verify type  is valid 1(sum) 2(avg) etc...
 if @inytype<1 or @inytype>5
-- if @inytype not between 1 and 5
 begin
    raiserror 51000 ''invalid crosstab type''
    return -1
 end

人气教程排行