I have a database which has many stored procedure which execute in the first of month. They should read based on rules from some tables and insert calculated results on other table. There are huge number of queries. Can I find another better solution instead of stored procedures?
SQL Server 2008
If you really wanted to you could write a service (e.g. windows service) to do the work but I would suggest stored procedures are probably best. This of course does depend on what the procedures do.
Related
We are using a SAP HANA environment to connect to various databases (SQL Server, Oracle, Teradata). Now one of our sources (the SQL server one) contains a lot of stored procedures to calculate transient values. We would need to have these values as well in SAP HANA and are thinking about the best way:
Ideally, HANA can call the stored procedure of SQL and get back the result data, but I could not find information about this. Is this possible?
Another option is to write a little program (Java) in HANA that can call the stored procedure on SQL Server and then give back the data (either directly, or by storing is some temporary table on SQL side and then read in with HANA).
Other ideas?
Does anybody have suggestions on this?
As long as you can run SQL queries you could see if using OPENROWSET would work for you.
Using OPENROWSET with stored procedure as source you can then consume data as it would SQL rowset.
SELECT * FROM
OPENROWSET ('SQLOLEDB','Server=(local);TRUSTED_CONNECTION=YES;','exec master.dbo.sp_who')
AS tbl
Using SAP HANA Smart Data Integration (SDI) remote sources, you are able to access/federate to remote tables, views and stored procedures.
First create the remote source, then wrap the Stored Procedure in a Virtual Procedure, these can be created via the Web IDE or SQL. You would use the CREATE VIRTUAL PROCEDURE statement as described below.
Create Virtual Procedure with Web IDE
CREATE VIRTUAL PROCEDURE via SQL
We have the same app source (with some custom "if x client then") and basically the same SQL Server database structure. But, some clients need slightly different stored procedures.
What would be best practice in this scenario for long term maintaining the databases and keeping the correct structure? As of now, for example when I change the procedure in one database and need to do the same in 9/10 others I just ALTER procedure and USE different database. But, I can't keep track of which procedures are different in that special snowflake client.
Any ideas? The plan is of course to get more clients so that's looking for trouble.
I try to push the "one fits all" concept but hey, what can you do...
Maybe have that "if x client then" as case statement in a SQL Server stored procedure and then you can just ALTER mindlessly?
I am currently using USE [databaseName] in my stored procedures. However, is there a way that I can point this at the current local database and not give a database name? I know this may sound a bit obscure but its highly likely that I will be using these Stored Procedures in many different databases.
remove the USE [databaseName] from your stored procedure.
By default, the stored procedure will run on the current database (in which SP is created)
I have been writing a CLR stored procedure that moves data from one database to another. I went with the CLR stored procedure because I like the .NET framework's ability to connect to remote servers better than I like linked servers, or openrowset, but I now find that my class is mostly embedded SQL strings. I was considering just using the CLR stored procedures to retrieve the data onto the local SQL Server, and then using a regular SQL stored procedure for the actual inserts and updates.
I'm not worried about pre-compilation of the procedure or performance, and I do like that the CLR procedure allows me to see all of the logic in one place, read from top to bottom.
Are there any reasons I should consider moving to a TSQL solution instead of CLR?
Thanks.
There are multiple reasons why you would stick to a regular stored procedure. I'll try to give you an overview of the ones that I know of:
Performance.
Memory issues. SQL Server only operates with its own max memory settings. CLR's go out of this bound. This could comprimise other applications (and the OS) running on this server.
Updatebility. You can update a Stored procedure with a simple script. CLR's are more complicated to update
Security. CLR's often require more security settings than regular t-sql.
As a general rule you only want to use CLR for:
interaction with the OS, such as reading from a file or dropping a message in MSMQ
performing complex calculations, especially when you already have the code written in a .NET language to do the calculation.
I have a TON of views that are rather long and dependent/depended on other views. I also have some stored procedures that need to be run weekly and these procedures need to use some of the SQL statements in the views so instead of putting the statements in the procedures I was hoping I could just run the view.
Is that possible? I'll be running these from SQL Server 2008 btw
SQL 101:
A Select statement can be run on a table or view.
So, yes, any code that can access at able can also access a view. Given the necessary permissions.
As I said - this is beginner SQL knowledge. I will add it to my list of interiew questions for junior developers.
A stored procedure is, in essence, nothing more than a canned ad-hoc statement. Yes, it offers many other features but the point is anything you can type in an interactive query window can also be run in a stored procedure.
Views are not restricted to being run in a stored procedure.
Yes you can query tables and views inside your stored procedure.