SQL Server > Stored Procedure

Delete record stored procedure in SQL Server

How to create stored procedure to delete a record from the SQL Server database?


To create delete stored procedure, replace the UPDATE statement with DELETE statement and change the parameters accordingly.

CREATE PROCEDURE DeletePersonalDetails
       -- Add the parameters for the stored procedure here
       @PersonalDetailsId int
AS
BEGIN
       -- SET NOCOUNT ON added to prevent extra result sets from
       -- interfering with SELECT statements.
       SET NOCOUNT ON;

    -- Insert statements for procedure here
       DELETE PersonalDetails WHERE PersonalDetailsId = @PersonalDetailsId
END

Notice that we have only one parameter in the above stored procedure as we need only that to find out the record having PersonalDetailsId and delete it.

 Views: 1855 | Post Order: 91



Write for us