2

Does anyone know of any packages or source code that does simple statistical analysis, e.g., confidence intervals or ANOVA, inside a SQL Server stored procedure?

4 Answers 4

2

The reason you probably don't want to do that is because these calculations are CPU-intensive. SQL Server is usually licensed by the CPU socket (roughly $5k/cpu for Standard, $20k/cpu for Enterprise) so DBAs are very sensitive to any applications that want to burn a lot of CPU power on the SQL Server itself. If you started doing statistics calculations and suddenly the server needs another CPU, that's an expensive licensing proposition.

Instead, it makes sense to do these statistical calculations on a separate application server. Query the data over the wire to your app server, do the number-crunching there, and then send the results back via an update statement or stored proc. Yes, it's more work, but as your application grows, you won't be facing an expensive licensing bill.

3
  • What if licensing isn't an issue? I'm assuming keeping it within the database would reduce the network traffic between the servers, therefore reducing latency. Thoughts?
    – Icono123
    Dec 5, 2012 at 17:14
  • @Icono123 It would depend on the amount of data required to do the calculation. If it's easier to send the data across the wire than it is to do the calculation locally in the server, that affects the answer. It's pretty darned rare that licensing isn't the issue though.
    – Brent Ozar
    Dec 5, 2012 at 23:00
  • Thanks, when you deal with the government licensing isn't an issue :)
    – Icono123
    Dec 6, 2012 at 17:33
1

In more recent versions of SQL Server you can use .net objects natively. So any .net package will do. Other than that there's always external proc calls...

1

Unless you have to do it within the stored proc I'd retrieve the data and do it outside SQL Server. That way you can choose from any of the open source or commercial stats routines and it would probably be faster too.

0

I don't know if a commercial package like this exist. There could be multiple reasons for this, some of which have been outlined above. If what you are trying to accomplish is to avoid building statistical functions that process your data stored in SQL Server, you might want to try and integrate statistical packages with your database server by importing data from it. For example, R supports it and there is also CRAN

Once you have accomplished that and you still feel that you'd like to make statistical analysis run inside your SQL Server, the next steps would be to call your stats package from a stored procedure using a command line interface. Your best option here is probably xp_cmdshell, though it requires careful configuration in order not to compromise your SQL Server security.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.