Contents
Is it safe to reuse SQL Server code?
However, of course, due care must be taken when reusing SQL code. Careless reuse of code can lead to maintenance and performance issues, especially when this reuse takes the form of scalar UDFs. We cannot reuse code without first verifying that it runs fast enough.
Is it better to reuse parameterized queries in SQL?
If we want to reuse parameterized queries, it is usually preferable to wrap them in user-defined functions. It is typically less convenient to reuse parameterized queries that are wrapped in stored procedures, as the following examples will demonstrate.
Why are the stored procedures produce different results?
Listing 5: The stored procedures produce different results. Clearly the average sales size for the state of California (4,630,000) is many times greater than the total sales for the same state (10,000), which makes no sense at all. In this example, I have deliberately used test data that makes the discrepancy obvious.
Is it OK to reuse a sqlconnection?
As VMAtm has said, .net Pools the connections on it’s own, so it is perfectly ok to recreate them. As such I generally write a wrapper for the whole process like this one. To answer your specific question, you can reuse a SqlConnection for each query.
What happens if you reuse SQL in Scala?
However, of course, due care must be taken when reusing SQL code. Careless reuse of code can lead to maintenance and performance issues, especially when this reuse takes the form of scalar UDFs.
Can You reuse SQL code in scalar UDFs?
The code to implement a given logic should be implemented once, and once only, and reused by all applications that need it. However, of course, due care must be taken when reusing SQL code. Careless reuse of code can lead to maintenance and performance issues, especially when this reuse takes the form of scalar UDFs.
How to reuse the result of a SQL query?
If you want to reuse the SQL text of the queries, then defining views is the best way, as described earlier. If you want to reuse the result of the queries, then you should consider global temporary tables. These temporary tables store data for the duration of session or transaction (whichever you choose).