A stored procedure is a sql query which could be executed at demand. A stored procedure could be used to delete, update, insert or select a record or set of records from database using any language. These procedures are stored in database. This a great way to save time and efforts because a single stored procedure could be called multiple times in an application which is opposite to writing inline select,delete,update or insert statements which may cause difficulty in maintaining the code as application grows.
The syntax for writing the stored procedure may vary from database to database but the main idea is the same.
Stored procedure don't require compilation each they are executed because the are compiled only once upon creation.The following is the syntax to create the stored procedure which deletes a record from table in sql server
CREATE PROCEDURE [Delete]
@ID int
AS
delete
FROM TableName where ID = @ID
Explanation
CREATE PROCEDURE is the key word which actually creates the stored procedure.
[Delete] This is the name of the stored procedure, It could be any string of characters or combination of characters and digits.
@ID is a parameter passed to stored procedure, this parameter is used to locate a record in table based on this ID, for example if the the user wishes to delete a record where ID = 10 then @ID parameter must contain a value which should be 10.
int defines that the parameter is of type int.
From defines the table name which contains the record to be deleted.
TableName The name of the table.
Sometimes we need to modify our stored procedure, to do so syntax is the same as for creating the stored procedure but we use the keyword alter procedure instead of create procedure.
The following is the syntax to alter the stored procedure which deletes a record from table in sql server
ALTER PROCEDURE [Delete]
@Name varchar(150)
AS
delete
FROM TableName where Name = @Name
Explanation
ALTER PROCEDURE is the key word which alters or modifies the stored procedure.
[Delete] This is the name of the stored procedure, It could be any string of characters or combination of characters and digits.
@Name is a parameter passed to stored procedure, this parameter is used to locate a record in table based on this Name, for example if the the user wishes to delete a record where Name = John then @Name parameter must contain a value which should be John.
varchar(150) defines that the parameter is of type string.
From defines the table name which contains the record to be deleted.
TableName The name of the table.
Insert Stored Procedure SQL
For further question please mail: brainstormiert@gmail.com