-6

SP or Query, which works better?

jarlh
  • 42,561
  • 8
  • 45
  • 63
  • Your question is very broad. Please add a minimum viable example. – Mihail Stancescu Feb 16 '17 at 07:48
  • I am writing queries from very large DBs. The inquiries are coming back in a very long time. If I convert the queries I write to SP, will there be performance difference? Does the SP work faster? – Demirci Mustafa Feb 16 '17 at 07:51
  • http://stackoverflow.com/questions/8559443/why-execute-stored-procedures-is-faster-than-sql-query-from-a-script – Wim Ombelets Feb 16 '17 at 07:55
  • Do some research! This quesiton is answered multiple times... In short: A `VIEW` (=Query) is meant to **read** data, while a `STORED PROCEDURE` is meant **to do** something. Fastest in most cases is single statement *ad-hoc* SQL. But there is no general answer. – Shnugo Feb 16 '17 at 08:55

1 Answers1

1

Stored procedure is group your query; rather also not to only write a adhoc query but write your business logic which will eventually end up executing multiple queries.

Again if it's SP then you end up transmitting very less data over the network when calling from your application code rather than writing up a huge adhoc query.

Again you can have granular privilege by wrapping your query in SP. Along with it .. you can use Transaction / error handling TRY .. CATCH etc..

Rahul
  • 76,197
  • 13
  • 71
  • 125