SQL Server Information and Resources Bookmark this page

SQLINFO.net is a Community Service from DataExpressions makers of dbOrchestra©

Google
 

 

 

 


SQL Server Examples

SQL DML

String Functions

Stored Procedures

SQL Views

SQL Table Basics


SQL Server Stored Procedure - DELETE - Example

Source code to create and add sql delete stored procedure to catalog

The following example is for creating a simple delete stored procedure. You can run it through an explicit call from a host language program or directly from a DBMS query execution shell like SQL Server Management Studio or dbOrchestra.

IF ( OBJECT_ID('dbo.sp_Students_DEL_byPK') IS NOT NULL ) 
   DROP PROCEDURE dbo.sp_Students_DEL_byPK
GO

CREATE PROCEDURE dbo.sp_Students_DEL_byPK
       @student_id    INT        
AS 
BEGIN 
     SET NOCOUNT ON 

     DELETE dbo.Students
     FROM   dbo.Students
     WHERE  
            student_id = @student_id

END

GO

Executing the sql delete stored procedure

Execute sql delete stored procedure

To run the stored procedure you need to supply a values to the applicable variables.

-- @student_id  IN  INT

EXEC dbo.sp_Students_DEL_byPK
     @student_id  =  25    

GO 

 

Link to schema for Students table



Copyright 2006-2007 by DataExpressions --- All Rights Reserved            dbOrchestra - SQL Server home page