我想创建一个函数,在每个表中加入一id列,如下:
use test
go
create function alterID()   
returns
as   
begin   
     alter table cdd_CELL add idcdd_CELL int identity(1,1)
     alter table RLDEP add idRLDEP int identity(1,1) 
     alter table RLCFP add idRLCFP int identity(1,1)
end 
go提示“ 关键字 'as' 附近有语法错误。 ”
大侠们看看

解决方案 »

  1.   

    我在存储过程中这样写:
    alter table cdd_CELL add idcdd_CELL int identity(1,1)
    alter table RLDEP add idRLDEP int identity(1,1) 
    alter table RLCFP add idRLCFP int identity(1,1)提示“ 列名 'idRLDEP' 无效。”我加完这列后,最后要把它删除,只是作为一个中介
      

  2.   

    在 UDF 定义中的 T-SQL 语句不能用于修改函数外的对象,包括创建/删除数据库对象、修改对象的架构,插入/删除/更新表,开始/提交/回滚事务,操作全局游标。
      

  3.   

    用存储过程create procedure usp_name
    as
     ... ...
    go
      

  4.   

    我这样写的:
    create procedure newTable
    as
    alter table cdd_CELL add idcdd_CELL int identity(1,1)
    alter table RLDEP add idRLDEP int identity(1,1) 
    alter table RLCFP add idRLCFP int identity(1,1)
    .....
    .....
    go提示“ 列名 'idRLDEP' 无效。”