Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Is STORED PROCEDURE the best way to use in large database or the simple procedure using in application/coding (Queries in Coding)?

Which procedure is the best for inserting, fetching, deleting, updating record(s) (CURD Operations) for a large database, using C# (Desktop Application).

Sorry for silly question, I am a beginner and learning that's why confused.

What I have tried:

I am using Simple procedure (Queries in Coding)
Posted
Updated 9-Jul-17 0:53am
v2

It's not necessarily "just" large databases, stored procedures have advantages in small ones as well.
Have a look here: Advantages and Drawbacks of Using Stored Procedures for Processing Data[^] - it's goign to depened on what the procedure is doing, how often it does it, and a host of other factors!

Personally, I use them when appropriate - which means when I'm doing something complex rather than a simple SELECT or INSERT statement - because they make code more readable and maintainable as well as sometimes giving you the flexibility to change the schema without altering the applications accessing the DB.
 
Share this answer
 
I wouldn't say that the size of the database should be the driving force to use or not to use procedures. After all a database which someone thinks large may be small to another.

The factors that affect the usage of the procedures include:

  • Eliminate round-trips, with procedures you may be able to eliminate the need of transferring data back and forth from the database. This means that a single unit of work may perform better if the whole operation is done on the database side
  • Security, with procedures you can prevent the user (or application) from seeing or modifying the underlying tables allowing only controlled route of access, the procedure
  • Maintainability, think of the procedure like an interface. For example you can change the underlying data structure and still provide the same result to the calling side
  • Dynamic queries, creating and handling dynamic queries is typically more inconvenient and difficult inside procedures
  • User conversation, user conversation isn't allowed inside a transaction so this needs to be taken into account when designing the architecture
  • Multiple callers, if your environment has multiple applications, it may be easier to implement the logic inside a procedure and call it from several places than to implement the logic in multiple places at calling side. This can happen for example in development environments utilizing multiple languages

As you can see, I didn't include the size of the database to the list nor did I include the speed of a single operation. Very often these are not affected whether you use procedure or not.
 
Share this answer
 
That's a good question, and point for heated discussions.
Personally I prefer to keep all code together (C# and database code), but in big databases there might be (perfomance) reasons to opt for stored procedures.
We had problems with SQL Server performance when the database size and number of queries was growing, but we solved this by switching to PostgreSQL and did not use stored procedures.
Here an advantage of our DAL (Data Access Layer) showed up: it was relatively easy to convert the code from SQL Server to PostgreSQL as all code was in one place.
If you are interested in database conversion to PostgreSQL, see: Convert SQL Server Database to PostgreSQL[^]

To the people downvoting this without leaving any comment, my question is: I would really like to know why, is it just because you are convinced SQL Server is the best ?
Have you ever tried PostgreSQL ? if so, what are your arguments against it ?
 
Share this answer
 
v2
Comments
CHill60 9-Jul-17 16:50pm    
I gave you a 4...not just to counter the downers-with-no-comment but because you have repeatedly made the point that there is more to life that MS Sql Server. You make people Think!
Would have been a 5* ...but I'm a sql server junkie; -)
RickZeeland 10-Jul-17 1:41am    
That's the spirit ;) and now the spirit is out of the bottle, I was a SQL Server junkie too in the past, I admit !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900