Where/When to Define Stored Procedures?

Let’s say you have a stored procedure you want to execute at some point. Great. Where do i put this thing? Do i have to define the procedure in the application code and then send the SQL every time it is used, assuming it did not previously exist? (CREATE OR REPLACE …) Or do i have to create it directly in the database and then only call it from the application? What happens when it needs to be updated or changed?

I’m not confused about what stored procedures are for. I just need to know where and when to define them.

Any help is appreciated.


it can be done either way, but considering that it’ll only be done once, i don’t see the advantage of putting it inside the app

That is a helpful document, but it does not answer the original question. My question is not a “how do i …” question, but rather a “what is the best way to …” question.

I need to know if the SQL for the procedure needs to be typed into the database directly or if it can live in the application code.

Again, any help is appreciated. Thanks!

I need the answer too and your question prompted me to check a search engine.



seems to be what we’re looking for