Stephanie Chatagner's Blog

• T-Sql

Well.

If you have an SQL query which you often need, Stored Prodecure is what you are looking for. It’s a piece of code that we can save, then reused over and over again.
Stored procedures can also be cached. The main purpose of SP’s to hide direct SQL queries from the code and improve performance of database operations such as select, update, and delete data. It can be easily modified!
It’s stored as a named object in the SQL Server Database.
Just call it to execute it! SP accept parameters in input too, and can return output parameters.

-- create
CREATE PROCEDURE procedure_name
AS
    sql_statement
GO;

-- Execute
EXEC procedure_name;

With ALTER PROCEDURE, it’s possible to change the query. Copy the query, add the modifications and done! You can execute the new SP.

To rename a stored procedure using T-SQL, use system stored procedure sp_rename.

sp_rename 'SelectAllCustomers','SelectAllCustomers_new'

To delete a procedure, very easy to DROP PROCEDURE SelectAllCustomers

So, step by step and keep learning!