views:

117

answers:

3

For the first time in years I've been doing some T-SQL programming in SQL Server 2008 and had forgotten just how bad the language really is:

  • Flow control (all the begin/end stuff) feels clunky
  • Exception handling is poor. Exceptions dont bubble in the same way they do in every other language. There's no re-throwing unless you code it yourself and the raiserror function isn't even spelt correctly (this caused me some headaches!)
  • String handling is poor
  • The only sequence type is a table. I had to write a function to split a string based on a delimiter and had to store it in a table which had the string parts along with a value indicating there position in the sequence.
  • If you need to doa lookup in the stored proc then manipulating the results is painful. You either have to use cursors or hack together a while loop with a nested lookup if the results contain some sort of ordering column

I realize I could code up my stored procedures using C#, but this will require permissioning the server to allow CLR functions, which isn't an option at my workplace.

Does anyone know if there are any alternatives to T-SQL within SQL Server, or if there are any plans to introduce something. Surely there's got to be a more modern alternative...

PS: This isn't intended to start a flame-war, I'm genuinely interested in what the options are.

+7  A: 

There is nothing wrong with T-SQL; it does the job it was intended for (except perhaps for the addition of control flow structures, but I digress!).

Perhaps take a look at LINQ? You can write CLR Stored Procedures, but I don't recommended this unless it is for some feature that's missing (or heavy string handling).

Mitch Wheat
@Mitch: Just because it does the job it doesn't strictly mean there's nothing wrong with it. Is you have to wrestle with the language to get simple things done then it would suggest to me it's not the best language. SQL Server is an enterprise class DB, it ought to have an enterprise class language, not something that appears cobbled together.
Sean
@Sean: T-SQL is a set-based SQL programming language - it does that job extremely well. T-SQL is **not** a procedural language - it handles those constructs not so well, but that's not what it's intended for in the first place.
marc_s
I agree with with Mitch and Marc here. TSQL is excellent at set based operations. And once you know how to use it properly can be a very powerful tool. Perhaps if Sean has too much control flow in procedures there is too much business logic in the database layer...get rid of flow control and you get rid of all your issues.
JoshBerke
+2  A: 

From My point of view only alternative to T-SQL within SQL Server is to NOT use SQL Slerver

According to your point handling stings whit delimiter , From where cames these strings ? You could try Integration services and "ssis packages" for converting data from one to other. Also there is nice way to access non SQL data over Linked Serves,

adopilot
+2  A: 

All other database stored procedure languages (PL/SQL, SQL/PSM) have about the same issues. Personally, i think these languages are exactly right for what they are intended to be used for - they are best used to do code data-driven logic, esp. if you want to reuse that for multiple applications.

So I guess my counter question to you is, why do you want your program to run as part of the database server process? Isn't what you're trying to do better solved at the application or middle-ware level? There you can take any language or data-processing tool of your choosing.

Roland Bouman
Yes, some of the processing will be done at the the middleware level, but there's still a reasonable amount to do in the stored procedures. Also, in the Microsoft world where in the middleware level? There's no real "app server" concept like WebLogic or JBoss, instead you've got a combination of SQL Server, MSMQ and IIS.
Sean
Sean, i tend to call anything that's not immediately bolted to the front-end or the back-end middleware. You re-affirm that you will be doing it in stored procedures, but I think you still need to answer to yourself: "why? - what would you lose if you did it in an external component?"
Roland Bouman
PL/SQL is way superior to T-SQL, it has error handling that actually works and it has packages.
SQL Cowboy
@Roland: I'm looking for cross language support. By coding up some of the functionality in T-SQL I'd planned to have thin libraries from C#, Java, Python and C++. By moving more of the functionality up a level if introduces more language interop issues, whereas calling stored procedures it's pretty easy from any language.
Sean
@SQL Cowboy: look, you don't have to explain to me what features PL/SQL does and doesn't have. I am well aware of them. The similarities between actually programming PL/SQL and T-SQL procedures are larger than the differences. @Sean that is a valid point, and I won't argue it. I am not a .NET deverloper, but since it seems you're bound to the MS platform anyway, doesn't this (.NET) solve most of these problems?
Roland Bouman