Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Auto generated SQL code

$
0
0
My company has adopted a new way of stored proc creation. Because the developers are mostly responsible for creating their stored procs, it was decided they have to use a generator to generate stored procs based on the table structure and columns.This auto generator will create a proc parameter for each column, as well as an OR clause for each column. If it is a SELECT proc, it will automatically SELECT all columns, similar for INSERT and UPDATE statements.For example:TableA has columns: Col1 INT, Col2 VARCHAR (10), Col3 BIT DEFAULT 0The proc will then be generated as follows:CREATE PROC procName @Col1 INT = NULL, @Col2 VARCHAR (10) = NULL, @Col3 BIT = NULLAS SELECT Col1, Col2, Col3FROM TableAWHERE (@Col1 IS NULL OR @Col1 = Col1)AND (@Col2 IS NULL OR @Col2 = Col3)AND (@Col3 IS NULL OR @Col2 = Col3)The above may not seem too bad but what about tables with numerous columns (up to 50 or more). The procs will then have 50 parameters and 50 OR statements, and with this I have a big problem.Yes the developers were told to remove unnecessary columns from the auto generated code, but they don’t do that.What are your thoughts on this? I don’t like these generic-like procs but I am having a hard time convincing them of this. They need to know Why, and I just know from experience on large amounts of data that multiple OR Statements like this makes execution really slow….

Viewing all articles
Browse latest Browse all 3145

Trending Articles