I have a task archive some database tables. To simplify everything, I basically have to do the following:
- Retrieve some rows from table 1 based on some condition
- Insert these rows into a table in the backup database
- Delete those rows from table 1
and I have to perform these operations on several tables.
This article is telling me to create separate SP based on the different CRUD operations (one for each of CRUD). As one can see, the steps I need to perform are READ, UPDATE, and DELETE. Then based on the article, I will need 3 SP for each of my tables. So if I have 10 tables I need to back up, then I need to write 30 SPs?
Could someone please tell me if this is the right practice?
Thanks.
Speaking on behalf of my learning curve: When I started with databases, I didn’t care that much about things I do now. The easiest and more “logical” way is to do the CRUD in one SP, since according to your scenario things are small.
But when it comes to scalability you really need them to be separated. It’s a good habit to start building on your programming.
Another thing to point out is the more order you can apply to your DB, the better.
About having to CRUD 10 tables. No, you don’t need 30 SPs (maybe you will do, but that would be a very unlikely scenario). You can use variables, parameters and stuff so you perform READ to several tables using parameters (for table names, etc). Same with other CRUD’s operations.
So, in short: Maybe you end up having a big and complex SP for just READing tables. But that’s how it is, you work hard one time, then you re-use time and time again. (this is a good thing to do; it will definetely help/save you in the future if you don’t know OOP)