This article describes how to set and use the Create CRUD procedures feature.
This feature allows to automatically create select, insert, update and delete stored procedures using customizable templates.
To create procedures, right click on a table or database in Object Explorer and from the context menu chose the Create CRUD procedures command:
This will generate code in a new query tab. The generated code will look like this:
When the above code is executed the four procedures will be created under the Stored Procedure folder:
The CRUD feature is located under the CRUD tab of the Options dialog with four sub-tabs for each of CRUD procedure templates (Select, Insert, Update, Delete):
Note, that the stored procedure script template is customizable and is designed by using named variables, e.g. %ColumnList% that will be replaced with exact object names (schemas, table names, column names…) in the process of generating a specific stored procedure.
All available variables can be manually entered by typing the name of the variable (e.g. %InputParameter%) or from the context menu, by clicking desired variable:
Clicking the Default template button will reset any changes and return the script to the default (aka factory settings) template for the particular CRUD procedure.
By default, the procedure name is created like this: crud_%TableName%%ProcedureType%
%TableName% stands for the name of the table over which the CRUD procedure is created (e.g. Employee).
By default, %ProcedureType% will be the name of the CRUD sub-tab which the user is currently using, for example (e.g. Select):
The auto-generated name for the CRUD procedure will be like this (crud_EmployeeSelect)
Let’s set some custom name in the Procedure name text boxes and see how will look like when the code is generated.
In the Procedure name box under the Select tab of the Options dialog put in “prc_%TableName%_Select_all_data”:
The procedure name for the select statement will look like this:
If the Insert Select CRUD procedure check box is unchecked:
A procedure for the select statement will be excluded from the procedures generation:
Here the list of all available variables:
The name of the schema (e.g. dbo)
The name of a table (e.g. Employee)
Generates a list of parameters. The name of the parametars will be made up of the names of columns for the selected table. The column name “ColumnName_ID” the generated parameter name will be @ColumnName_ID.
Set condition for the particular CRUD procedure.
For example, for the delete CRUD procedure:
User enters the value (e.g. 1) for the identity column, which row will be deleted:
EXECUTE Person.crud_AddressTypeDelete @AddressTypeID = 1;
List all the columns from a chosen table (e.g. ColumnName_ID, ColumnName_1, ColumnName_…n)
List all columns from the chosen table in the insert CRUD procedure:
Generate parameters for the values which will be passed to an insert statement for the insert CRUD procedure:
Listed all columns for the chosen table in the update CRUD procedures:
Q: Will the new installation or upgrade of ApexSQL Complete delete the custom created CRUD templates?
A: No, installation, or upgrade to a newer version won’t affect custom changes.
Q: Where is information about the CRUD procedures saved?
A: By default, the CRUD procedures are saved in the following location:
Q: Can settings for CRUD procedures be used on a different machine?
A: Yes, you can use the settings for the CRUD procedures on different machines. By copying the Options.xml file to the appropriate location on another machine where ApexSQL Complete is already installed.
Note: When copy the Options.xml file to another machine, all ApexSQL Complete settings will be copied too.