Escolar Documentos
Profissional Documentos
Cultura Documentos
In This Presentation..
Introduction to Variables Stored Procedures Types of Stored Procedures System Stored Procedures Extended Stored Procedures User-defined Stored Procedures Creating Stored Procedures Executing Stored Procedures System Stored Procedures Managing Stored Procedures
Introduction to Variables
Variables are defined memory locations that are given a specific name and contain some value. Variables are mainly used for calculations or to store some value for stored procedures. The name of the local variable must be prefixed with @ sign. declare keyword is used to declare a variable. set keyword is used to assign a vale to a variable. SQL Server uses several system global variables that hold information useful to the database user.
Stored Procedures
Stored Procedures are the database objects that encapsulate data manipulation and retrieval statements. Stored Procedures contain a collection of precomplied T-SQL statements . Stored Procedures are processed as a single unit. Stored Procedures are mainly used for reducing the network traffic in a Client - Server environment. Stored Procedures are also referred to as SPROCS
Stored Procedures are classified into THREE Types. System Stored Procedures: Supplied by SQL Server and are precompiled version of T-SQL statements. Used to report and manage information in the system. They begin with sp_. User-defined Stored Procedures: We can create our own Stored Procedures, compile them execute them as per our need. Extended Stored Procedures: These SPs work outside SQL Server and are stored as DLLs and are executed dynamically. They begin with xp_
We can execute a complied stored procedure with the use of EXEC or EXECUTE command
EXEC <procedure-name> or EXECUTE <procedure-name>
However, if the execution is the first statement of the batch, then there is no need to include the EXEC or EXECUTE command.
Stored Procedures can be modified using the ALTER statement similar to other DB Objects.
ALTER PROC[EDURE] <procedure-name> <new schema>
Stored Procedures can be dropped using DROP statement similar to other DB Objects.
DROP PROC[EDURE] <procedure-name>
Sp_databases
Sp_columns sp_depends
Sp_pkeys
Sp_indexes,
etc
Procedures can be recompiled whenever required using sp_recompile system Stored Procedure. Definition can be extracted using sp_helptext We can encrypt the definition of the Stored Procedure as well and secure it from unauthorized users.