Stored procedures enable you to manage your server-based database and display information about that database and its users. For example, you can use a stored procedure to display the title (from the titles
table) and publisher (from the publishers
table) for each author in the authors
table.
Stored procedures can contain program flow, logic, and queries against the database. They can accept parameters, generate parameters, return single or multiple result sets, and return values.
You can use stored procedures for any purpose for which you would use SQL statements, with these advantages:
The SQL editor can be opened from the Data View window. The Data View window can be opened from the View menu or the Standard toolbar.
To create a new stored procedure
A new stored procedure is created using a template containing SQL statements.
StoredProcedure
in the first line with the name of the procedure. For example, you might use "MyProcedure" as the name:Create Procedure MyProcedure
Note Stored procedures must have unique names. If you choose a name that is already assigned to another stored procedure in your project, an error message is displayed.
For more information and examples of stored procedures, see the documentation for your server. If you are using Microsoft® SQL Server™, see CREATE PROCEDURE statement in the SQL Server documentation. The Visual Basic SQL Editor also works with Oracle Stored Procedures, Functions, and Packages.
You can run a stored procedure against your database to execute the SQL statements it contains and display the results in the Immediate window.
To run a stored procedure
You can copy a stored procedure as the first step in creating a new stored procedure for your database. Because stored procedures must have names that are unique, the new stored procedure is automatically assigned a new unique name based on the original name.
To copy a stored procedure
The SQL Editor opens with the stored procedure.
You can edit the SQL statements in the new stored procedure.
You can set execute permissions for a stored procedure that you own to allow access to the stored procedure by specific users or groups. In many databases, such as Microsoft® SQL Server™ and Oracle Database Server, if you are not the database owner, then you must explicitly grant permissions for your stored procedure to other users. Use SQL Server’s ISQL utility, Enterprise Manager, or an Oracle Tool to run the change commands or visually set the permissions.