- 实验目的
1.能够使用简单的系统存储过程。
2.能够创建和执行用户自定义存储过程。
3.能够完成存储过程的修改、删除等管理任务。
- 实验设备
操作系统:Win11
开发软件:SQL Server
- 实验内容
针对第6章设计的电子商务系统,做如下操作。
1.创建存储过程proc_1,显示购买人信息表中性别为“男”的用户信息,并调用此存储过程,显示执行结果。
2.使用sp_helptext查看存储过程proc_1的文本。
3.创建存储过程proc_2,实现为购买人信息表添加一条记录,记录内容自己定义,并调用此存储过程,显示执行结果。
4.创建存储过程proc_3,实现根据商品编号查询某一商品的名称和价格,并调用此存储过程,显示执行结果。
5.修改存储过程proc_1,改为显示购买人信息表中性别为“女”的用户信息。
6.删除存储过程proc_1。
- 实验步骤及实验结果
1.create procedure proc_1 as
2.begin
3.select*from Customer where Gender='M'
4.end
5.exec proc_1
1.create procedure proc_2
2.as
3.begin
4.insert into Customer(CustomerID,CustomerName,Gender,ContactNumber,Email)values(7,'LorraineWen','M','1788','2145@qq.com');
5.end
6.Exec proc_2
1.create procedure proc_3(@id int)
2.as
3.begin
4.select ProductName,Price from Product where ProductID=@id
5.end
6.exec proc_3 1
1.alter procedure proc_1
2.as
3.begin
4.select *from Customer where Gender='F'
5.end
6.exec proc_1
1.drop procedure proc_1