insert into dbo.Student values(cast(rand()*100 as int))   是正确的if exists(select * from sys.procedures where name ='pro_test')
drop procedure pro_test
go
create procedure pro_test
as
(
    insert into dbo.Student values(cast(rand()*100 as int))
)
为什么会报错呢??错误信息:
消息 156,级别 15,状态 1,过程 pro_test,第 5 行
关键字 'insert' 附近有语法错误。
消息 102,级别 15,状态 1,过程 pro_test,第 6 行
')' 附近有语法错误。

解决方案 »

  1.   

    if exists(select * from sys.procedures where name ='pro_test')
    drop procedure pro_test
    go
    create procedure pro_test
    as  insert into dbo.Student values(cast(rand()*100 as int))
      

  2.   

    要么把括号去掉,要么把括号换成begin\ end
      

  3.   

    if exists(select * from sys.procedures where name ='pro_test')
    drop procedure pro_test
    go
    create procedure pro_test
    as
     insert into dbo.Student values(cast(rand()*100 as int))
      

  4.   


    if exists(select * from sys.procedures where name ='pro_test')
    drop procedure pro_test
    go
    create procedure pro_test(-- 如果有参数的这里可以加括号~)
    as  insert into dbo.Student values(cast(rand()*100 as int))