创建一名为“MP1”的存储过程,其功能是在STUDENT表中添加一列AGE(表示学生年龄),再修改该列的值。
提示:添加列后用UPDATE命令进行修改,修改时必须利用CSRQ列值

解决方案 »

  1.   

    --在同一个存储过程给某个表添加列,还要使用这一列,需要用动态SQL语句,如:create proc test 
    asexec ('alter table Student add age int')update student set age=datediff(yy,birthday,getdate())
    go
      

  2.   

    create proc test 
    as--先判断一下列是否存在,如果不存在,才添加列
    exec ('if not exists (select * from syscolumns where id=object_id(''Student'') and name=''age'')
     alter table Student add age int')update student set age=datediff(yy,birthday,getdate())
    go