[dba-SQLServer] Dynamic SQL

jwcolby jwcolby at colbyconsulting.com
Mon Oct 1 07:03:09 CDT 2007


Folks,

There has been much discussion re using dynamic SQL to perform operations on
SQL Server, vs. using stored procedures.  Let me give you a rundown on my
situation and I would then like opinions on strategy.

This is the "big database" operations I am discussing.  I get DVDs full of
raw data, typically many different text (flat or CSV) files, which I
assemble into a directory.  I am using VB.Net to iterate through the
directory and import all of the files into SQL Server.  My code:

1) Creates a new database if none exists for this import.
2) Creates a new "master" raw data table if none exists
3) Creates a temp table for each data file
4) Imports the data into the temp table.
5) If the complete data file imports without errors, I append the temp to
the master table
6) If the append succeeds I delete the temp table
7) If all of the above succeeds I move the data file to an archive directory
8) I log each step of the above, both errors if any and a general memo of
steps, how long they took etc and when done I write that log file to disk.
Someday I will write that log data to disk.

Steps 1 through 6 is all "dynamic sql" that I build up based on the SQL
Server name, the database name, the table names, and even the field names.
Doing things this way allows me to have a class that knows how to build
databases, tables and indexes, and also perform action queries to perform
all of these actions.

My question is simply whether this really needs to be moved to the SP
paradigm?  My database runs on a server here at my office behind a hardware
and a software firewall, although of course I am not a notwork guy so in the
end how secure it all is is questionable.  To this point there is no one
accessing the database from outside of my office and in fact to this point I
am the only one accessing the database at all.

If I were to move to the SP paradigm I guess I would need to design and
store all of these SPs into a master database and run them from there,
passing in the various part names?  I really do not want to go there "today"
as I have work to do and this would be another learning curve and a lot of
development effort.

So, opinions on the necessity in my case?

John W. Colby
Colby Consulting
www.ColbyConsulting.com 




More information about the dba-SQLServer mailing list