问题描述
限时送ChatGPT账号..我正在创建此表,但在第一个程序 (sp_joseview) 中遇到问题
I'm creating this table but I'm running into a problem with the first procedure (sp_joseview)
create table josecustomer(
name varchar(50),
address varchar(300),
ssnid int,
balance bigint,
accountnumber bigint
)
insert into josecustomer values('Aman','Canada',10000,5000,100000000)
insert into josecustomer values('Shubham','USA',10001,6000,200000000)
insert into josecustomer values('Himanshu','Australia',10002,2000,300000000)
insert into josecustomer values('Jose','India',10003,3000,400000000)
insert into josecustomer values('Albert','Brazil',10004,4000,500000000)
insert into josecustomer values('Peterson','Germany',10005,7000,600000000)
insert into josecustomer values('Adam','Honkong',10006,8000,700000000)
insert into josecustomer values('William','Paris',10007,9000,800000000)
select * from josecustomer
create proc sp_joseview
as begin
select * from josecustomer
end
go
create proc sp_updatejose
(@accountno bigint,@newbalance bigint)
as begin
update josecustomer
set balance=@newbalance
where accountnumber=@accountno
end
go
第一个过程显示语法错误,但我无法弄清楚该错误可能是什么.
There is a syntax error showing for the first procedure but I can't figure out what that error might be.
推荐答案
该错误是不言自明的 - 您不能发出 CREATE PROCEDURE
语句,除非它是批处理中的唯一语句.
The error is self-explanatory - you cannot issue a CREATE PROCEDURE
statement unless it's the only statement in the batch.
在 SSMS 中,GO
关键字将语句拆分为单独的批次,因此您需要在 CREATE PROCEDURE
之前的语句后添加一个:
In SSMS the GO
keyword splits the statement into separate batches, so you need to add one after the statement before the CREATE PROCEDURE
:
create table josecustomer(
name varchar(50),
address varchar(300),
ssnid int,
balance bigint,
accountnumber bigint
)
insert into josecustomer values('Aman','Canada',10000,5000,100000000)
insert into josecustomer values('Shubham','USA',10001,6000,200000000)
insert into josecustomer values('Himanshu','Australia',10002,2000,300000000)
insert into josecustomer values('Jose','India',10003,3000,400000000)
insert into josecustomer values('Albert','Brazil',10004,4000,500000000)
insert into josecustomer values('Peterson','Germany',10005,7000,600000000)
insert into josecustomer values('Adam','Honkong',10006,8000,700000000)
insert into josecustomer values('William','Paris',10007,9000,800000000)
select * from josecustomer
Go --Add a Go here
create proc sp_joseview
as begin
select * from josecustomer
end
go
create proc sp_updatejose
(@accountno bigint,@newbalance bigint)
as begin
update josecustomer
set balance=@newbalance
where accountnumber=@accountno
end
go
这篇关于'CREATE PROCEDURE' 必须是批处理中的唯一语句(错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!