交叉制表-验证对象的存在(3)
程序员文章站
2022-04-15 10:23:59
...
交叉制表-验证对象的存在(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 @inytype5 -- if @inytype not between 1 and 5 begin raiserror 51000 ''invalid crosstab type'' return -1 end
推荐阅读