Automating the Creation of the Code
One great thing about stored procedures is that they can save time. One stored procedure that I needed would write the code that, when executed, would be a stored procedure that would insert rows into a table. This stored procedure can be seen in Listing 7.6.
Code Listing 7.6. Automatic Creation of Stored Procedure Code
CREATE PROCEDURE usp_create_insert_proc @vchTableName VARCHAR(64) AS SET NOCOUNT ON -- Declare the variables DECLARE @vchCurrentLine VARCHAR(128) DECLARE @vchColumnName VARCHAR(32) DECLARE @vchColumnType VARCHAR(16) DECLARE @intColumnLength INT DECLARE @bitNullable BIT DECLARE @intColNameLength INT DECLARE @intColCounter INT DECLARE @vchVariableName VARCHAR(32) -- Creates and prints the ... |
Get Writing Stored Procedures for Microsoft SQL Server now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.