存储过程 Stored Procedure 创建、执行、修改、删除

--先建设测试表 +造数据
create table Studentl
(

id int primary key,
name varchar(20),
age int

);

insert into Studentl
values
(1,'张三',18),
(2,'李四',19),
(3,'王五',18);

GO

--创建存储过程
create proc p_GetStudent18
as
begin
select * from Studentl where age = 18;
end
GO

--执行存储过程
exec p_GetStudent18;

go

--修改存储过程
alter proc p_GetStudent18
as
begin
select * from Studentl where age >= 18;
end
go

--删除存储过程
drop proc p_GetStudent18
go

--带参数的存储过程
--根据传入年龄 查询对应学生
create proc p_GetStudentByAge
@age int --输入参数
as
begin
select * from studentl where age = @age;
end
GO
--执行调用传参
exec p_GetStudentByAge @age = 18;

——————————————————————————————————————————————————

存储过程在哪里找?
SSMS 左侧对象资源管理器:
你的数据库 → 可编程性 → 存储过程

posted @ 2026-05-03 21:41  菜鸟的奋斗军  阅读(3)  评论(0)    收藏  举报