473,383 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

CRUD in SP or Dynamic SQL

Hi,

I'm implementing a new Business Layer in one of our applications. I'm
toying with the idea of placing all the Create, Read, Update and Delete SQL
in the object in question and build a dynamic SQL string using a class
builder.

The pros I can see are:
It reduces the number of stored procs to admin.
Changes to the underlying table schema does not require massive changes to
large numbers of storeprocs

The cons are probably I can se are:
the potential for malicious code to be generated would be higher.
The slight loss in performance do to no execution plan being available to
cache.

I would appreciate any ideas, opinions URL links etc

TIA

MattC
Nov 19 '05 #1
6 2652
"MattC" <m@m.com> wrote in message
news:eW**************@TK2MSFTNGP15.phx.gbl...
Hi,

I'm implementing a new Business Layer in one of our applications. I'm
toying with the idea of placing all the Create, Read, Update and Delete
SQL
in the object in question and build a dynamic SQL string using a class
builder.

The pros I can see are:
It reduces the number of stored procs to admin.
Changes to the underlying table schema does not require massive changes to
large numbers of storeprocs


Wouldnt database schema change affect the way you build dynamic sql in ur
code? and it requires compilation.
Nov 19 '05 #2
Yeah that's gonna happen regardless, but I wouldn't have to change the
update/insert/read stored procs as well as the code.
MattC
"The Crow" <q> wrote in message
news:#U**************@TK2MSFTNGP09.phx.gbl...
"MattC" <m@m.com> wrote in message
news:eW**************@TK2MSFTNGP15.phx.gbl...
Hi,

I'm implementing a new Business Layer in one of our applications. I'm
toying with the idea of placing all the Create, Read, Update and Delete
SQL
in the object in question and build a dynamic SQL string using a class
builder.

The pros I can see are:
It reduces the number of stored procs to admin.
Changes to the underlying table schema does not require massive changes to large numbers of storeprocs


Wouldnt database schema change affect the way you build dynamic sql in ur
code? and it requires compilation.

Nov 19 '05 #3
PB
Stored procedures perform better than dynamic SQL. A stored procedure is
parsed and complied once (the first time it is executed). Every time you
subsequently execute the sp, the parsed/compiled version gets executed.
Dynamic SQL requires parsing and compiling on *every* execution. This is a
bit more runtime overhead - which negatively impacts your application's
scalability.

Also from a maintenance perspective - when you use stored procedures - you
have one place to make an update (in your SQL Server); whereas dynamic SQL
requires a recompile of your application and redistribution and
reinstallation. That's a whole lot of work - especially if the change is
small - and most changes are typically small.

It's a push regarding radical database schema changes (because app logic and
supporting sql will likely both change) - but such changes are typically far
less frequent in occurance compared to small changes.

Personally I'd opt for stored procedures over dynamic SQL for (1) improved
runtime performance; (2) simplified maintenance; and (3) protection against
SQL injection attacks.

-HTH

"MattC" <m@m.com> wrote in message
news:eW**************@TK2MSFTNGP15.phx.gbl...
Hi,

I'm implementing a new Business Layer in one of our applications. I'm
toying with the idea of placing all the Create, Read, Update and Delete
SQL
in the object in question and build a dynamic SQL string using a class
builder.

The pros I can see are:
It reduces the number of stored procs to admin.
Changes to the underlying table schema does not require massive changes to
large numbers of storeprocs

The cons are probably I can se are:
the potential for malicious code to be generated would be higher.
The slight loss in performance do to no execution plan being available to
cache.

I would appreciate any ideas, opinions URL links etc

TIA

MattC

Nov 19 '05 #4
Think about CRUD in SP if your object is quite complex, but in most of
the time dynamic SQL will save lot of time.

http://www.nethoa.com

"MattC" <m@m.com> wrote in message news:<eW**************@TK2MSFTNGP15.phx.gbl>...
Hi,

I'm implementing a new Business Layer in one of our applications. I'm
toying with the idea of placing all the Create, Read, Update and Delete SQL
in the object in question and build a dynamic SQL string using a class
builder.

The pros I can see are:
It reduces the number of stored procs to admin.
Changes to the underlying table schema does not require massive changes to
large numbers of storeprocs

The cons are probably I can se are:
the potential for malicious code to be generated would be higher.
The slight loss in performance do to no execution plan being available to
cache.

I would appreciate any ideas, opinions URL links etc

TIA

MattC

Nov 19 '05 #5
Well paramaterised queries and stored procs both have their execution plans
stored in the cache. From what I've read stored procs, by virtue of their
stronger signature, might be found quicker from the cache.

A change to a stored proc (and I'm talking changes that mean datatype, field
addition or removals) will require recompilation anyway, so that point is
moot.

From the perspective of saving a single set of information to a database the
performance cost versus maintainability. If I want to know how my OM is
transformed into a format acceptable to my RM I would simply look at my
class. With stored procs it's an extra level.

I think Yukon will do a lot to simplify this or provide an inbetween step
but I'm still undecided on whether to use SP's for my CRUD stuff.

MattC
"PB" <A@B.com> wrote in message
news:eu**************@TK2MSFTNGP10.phx.gbl...
Stored procedures perform better than dynamic SQL. A stored procedure is
parsed and complied once (the first time it is executed). Every time you
subsequently execute the sp, the parsed/compiled version gets executed.
Dynamic SQL requires parsing and compiling on *every* execution. This is a
bit more runtime overhead - which negatively impacts your application's
scalability.

Also from a maintenance perspective - when you use stored procedures - you
have one place to make an update (in your SQL Server); whereas dynamic SQL
requires a recompile of your application and redistribution and
reinstallation. That's a whole lot of work - especially if the change is
small - and most changes are typically small.

It's a push regarding radical database schema changes (because app logic and supporting sql will likely both change) - but such changes are typically far less frequent in occurance compared to small changes.

Personally I'd opt for stored procedures over dynamic SQL for (1) improved
runtime performance; (2) simplified maintenance; and (3) protection against SQL injection attacks.

-HTH

"MattC" <m@m.com> wrote in message
news:eW**************@TK2MSFTNGP15.phx.gbl...
Hi,

I'm implementing a new Business Layer in one of our applications. I'm
toying with the idea of placing all the Create, Read, Update and Delete
SQL
in the object in question and build a dynamic SQL string using a class
builder.

The pros I can see are:
It reduces the number of stored procs to admin.
Changes to the underlying table schema does not require massive changes to large numbers of storeprocs

The cons are probably I can se are:
the potential for malicious code to be generated would be higher.
The slight loss in performance do to no execution plan being available to cache.

I would appreciate any ideas, opinions URL links etc

TIA

MattC


Nov 19 '05 #6
I use storedprocs exclusively. I write them in sql scripts and precede
each declaration with a matching (if this_storedproc exists, delete
this_storedproc) statement.

Storing them in sql scripts lets me keep them under version control
alongside the code that references them so they are always in sync.

Preceding each with a conditional removal statement allows me to run
the entire script w/o conflicts if i need to make a change, and has the
added benefit of serving as an install script as it describes the
entirety of my stored procs.

Obviously i don't store table definitions with remove statements in
these storedproc script files, or my table data would be cleared out
each time i ran these scripts.

By keeping each table definitions separate, however, i can group my
stored procedure by table or list them all in a single script. In
either case, storedprocs do not maintain any data, so removing them and
recreating them only incurs a (relatively) small cost at update time.

Even changes to the table schema can generally be handled by a few
search/replace queries on my script file when all my storedproc defn's
are laid out linearly in a flat text file. Either that or i use the
find feature of VIM to zip around my script definitions and make the
updates.

Using this method, i find that administration and update time is
minimal.

This seems to address (eliminate?) the pros that you list below and
suggest that storedprocs are, indeed, the way to go.
From the reading that i've done, the more calculation you can move into the database, the more the server can optimize your query for speed,
and the fewer high-cost database accesses you need to incur in your
application.

cheers,

David.

MattC wrote: Hi,

I'm implementing a new Business Layer in one of our applications. I'm
toying with the idea of placing all the Create, Read, Update and Delete SQL
in the object in question and build a dynamic SQL string using a class
builder.

The pros I can see are:
It reduces the number of stored procs to admin.
Changes to the underlying table schema does not require massive changes to
large numbers of storeprocs


Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: amber | last post by:
Hello, I'm looking for some guidance . I'm new to VB.NET and SQL server, and have been working on a project for a while. I have been reading up on implementing CRUD operations using stored...
3
by: Torben Madsen | last post by:
Hello, I have a C# problem that I hope you could help me with. I'm making a program where I need data from a database using ADO.NET. The problem is that I can't figure out how to retrieve...
4
by: lkamal | last post by:
What is CRUD? Read at http://lkamal.blogspot.com/
0
by: RickmanCR750 | last post by:
People, I have an old (php3?) script which does CRUD over a mySQL db. I've upgraded to php5 and PostgreSQL (on Linux), and the script bombs (multiple errors). I'm working through it at the moment,...
3
by: =?Utf-8?B?dGhlamFja29mYWxs?= | last post by:
Hi. Is there a way to generate the CRUD stored procedures for a table using the Visual Studio 2005? I tried to do it in a new database project, but I can't find a way to do it. Can VS 2005...
13
by: John Kraft | last post by:
Friends, I'm working on some crud stuff, and I was looking for opinions on the subject. Below, I have pasted some VERY simple sample code. Class2 is a "traditional" crud type object. In a...
11
by: walterbyrd | last post by:
With PHP, libraries, apps, etc. to do basic CRUD are everywhere. Ajax and non-Ajax solutions abound. With Python, finding such library, or apps. seems to be much more difficult to find. I...
0
by: CBFalconer | last post by:
For the past week I have been collecting data on the relative incidence of crud in the 18 newsgroups I monitor. Here crud is defined as anything that gets caught by my filters, and good is...
1
by: nospam | last post by:
Hello all, Using Net 2 0 and VS 2005 and MSSQL 2000... I am a newbie to ASP. I am trying to created a screen to manipulate a table - CRUD commands. The problem is the checkbox to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.