SQL2005——求高人写个存储过程看下

来源:百度知道 编辑:UC知道 时间:2024/06/24 15:32:36
create table stuInfo
(
stuName varchar(20) not null,
stuNo int not null primary key,
stuAge int not null check(stuAge between 8 and 30),
stuSex varchar(2) not null check(stuSex in('男','女')),
stuSeet int identity(1,1),
stuAdress text default('地址不详')
)

这个是表格

select * from stuInfo where stuNo=@stuNo ----这句求存储过程

update stuInfo set stuName=@stuName,stuAge=@stuAge,stuSex=@stuSex,stuAdress=@stuAdress
where stuNo=@stuNo--------还有这句求存储过程

希望能写的规范,通俗易懂,我是个新手,写的好的话我可以再加分!

第一个:
if exists(select * from sysobjects where name='proc_stuNo')
drop proc proc_stuNo
go
create proc proc_stuNo
@stuNo int
as
select * from stuInfo where stuNo = @stuNo
go
第二个:
if exists(select * from sysobjects where name='proc_stuInfo')
drop proc proc_stuInfo
go
create proc proc_stuInfo
@stuName varchar(10),
@stuAge int,
@stuSex nvarchar(1),
@stuAddress varchar(50),
@stuNo int
as
update stuInfo set stuName=@stuName,stuAge=@stuAge,stuSex=@stuSex,stuAddress=@stuAddress where stuNo = @stuNo
go

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

create proc abc --存储过程的名字 修改存储过程时把create换成alter
(
@stuNo nvarchar(100)='' --从外面传的参数
)
as
begin
select * from stuInfo where stuNo=@stuNo
end

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON