alter Procedure InsertAdmin
@AdminType varchar(10),@Adminname varchar(10),@AdminPassword varchar(8)
as
begin
insert into Admin(AdminType,Adminname,Adminpassword) values('@AdminType','@Adminname','@AdminPassword')
end
表中有一个自增为I的标识符
alter Procedure InsertAdmin
@AdminType varchar(10),@Adminname varchar(10),@AdminPassword varchar(8)
as
begin
insert into Admin(AdminType,Adminname,Adminpassword) values('@AdminType','@Adminname','@AdminPassword')
end
表中有一个自增为I的标识符
alter Procedure InsertAdmin
@AdminType varchar(10),
@Adminname varchar(10),
@AdminPassword varchar(8)
as
begin
insert into Admin(AdminType,Adminname,Adminpassword) values('@AdminType','@Adminname','@AdminPassword')
end
你这段代码中有不对的地方。在添加数据的时候,变量不能用单引号引起来。
应该是
alter Procedure InsertAdmin
@AdminType varchar(10),
@Adminname varchar(10),
@AdminPassword varchar(8)
as
begin
insert into Admin(AdminType,Adminname,Adminpassword) values(@AdminType,@Adminname,@AdminPassword)
end
alter Procedure InsertAdmin declare @AdminType varchar(10)
declare @Adminname varchar(10)
declare @AdminPassword varchar(8) as begin insert into Admin(AdminType,Adminname,Adminpassword) values('@AdminType','@Adminname','@AdminPassword') end
go
声明变量的时候要用declare 创建存储过程时候要记得go
-------------------建立测试数据------------------------ if object_id('[Admin]') is not null drop table [Admin] go create table [Admin](id int identity(1,1) primary key, AdminType varchar(10), Adminname varchar(10), AdminPassword varchar(10)) go --------------------存储过程开始-------------------------- if object_id('InsertAdmin','P') is not null drop proc InsertAdmin go
create proc InsertAdmin @AdminType varchar(10), @Adminname varchar(10), @AdminPassword varchar(10) as begin --declare @sql varchar(1000) insert into [Admin](AdminType,Adminname,Adminpassword) values (''+@AdminType+'',''+@Adminname+'',''+@AdminPassword+'') end
go
exec InsertAdmin '管理员','admin','admin'
select * from [Admin] --------------------结果----------------------------