Database Reference
In-Depth Information
Solution
Let's say you have a model with the Athlete entity shown in Figure 10-8 . The underlying database has the Athlete table
shown in Figure 10-9 . You want to use stored procedures for the Insert, Update, and Delete actions.
Figure 10-8. The Athlete entity in the model
Figure 10-9. The Athlete table with some basic information about athletes
To map stored procedures to the Insert, Update, and Delete actions for the Athlete entity, do the following:
1.
In your database, create the stored procedures in Listing 10-21.
Listing 10-21. The Stored Procedures for the Insert, Update, and Delete Actions
create procedure [chapter10].[InsertAthlete]
(@Name varchar(50), @Height int, @Weight int)
as
begin
insert into Chapter10.Athlete values (@Name, @Height, @Weight)
select SCOPE_IDENTITY() as AthleteId
end
go
create procedure [chapter10].[UpdateAthlete]
(@AthleteId int, @Name varchar(50), @Height int, @Weight int)
as
begin
update Chapter10.Athlete set Name = @Name, Height = @Height, [Weight] = @Weight
where AthleteId = @AthleteId
 
Search WWH ::




Custom Search