Sandy
Sandy

Reputation: 11697

What should we prefer to use Stored Proc or Prepared statements

I have recently started working on Databases. I know the basic difference between Stored Procedures and Prepared Statements. But can just brief me an idea that when we have to use which one. My trainer told me both are used when you have to execute a command often but then which one we should go for. I have heard that Stored procedures are always preferred. I know Stored procedures are pre-compiled and written in database. I can accept if someone says actually there is no similarity between the two so no question of differences and usage preference, but still I putted this question as I am unaware of these things. I am using SQL Server 2008 Express with C#. Can some one help me out please.

Upvotes: 1

Views: 284

Answers (1)

gbn
gbn

Reputation: 432431

Use both? Stored procedures for writes, prepared statements for reads?

Why?

  • Command-query separation
  • RDBMS deals with transactions, data integrity etc (eg less round trips to check a condition)
  • Clients are not constrained to stored procedures for reads (but would still use a view or UDF: never raw tables)

Oherwise, there is no correct answer because it will be different depending who you ask

Upvotes: 3

Related Questions