有替代Transact-SQL的方法吗

时间:2021-09-13 12:38:26

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:

多年来,我第一次在SQL Server 2008中进行T-SQL编程,并忘记了语言到底有多糟糕:

  • 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!)
  • 异常处理是贫穷。例外并不像它们在其他语言中那样存在。除非你自己编写代码,否则不会重新抛出,而raiserror函数甚至不能正确拼写(这让我头疼!)
  • 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
  • 如果需要在存储的proc中执行查找,那么操作结果是很痛苦的。如果结果包含某种排序列,则必须使用游标或使用嵌套查找合并while循环

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.

我意识到我可以使用c#来编写我的存储过程,但是这需要允许服务器允许CLR函数,这在我的工作环境中不是一个选项。

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...

有谁知道SQL Server中是否有T-SQL的替代方案,或者是否有什么计划来介绍一些东西。肯定会有更现代的选择……

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

附注:这并不是要引发一场激烈的战争,我真正感兴趣的是选择是什么。

3 个解决方案

#1


8  

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!).

T-SQL没有问题;它完成了预期的工作(除了添加控制流结构之外,但我离题了!)

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).

也许看一下LINQ吧?您可以编写CLR存储过程,但我不建议这样做,除非是针对某些缺失的特性(或繁重的字符串处理)。

#2


3  

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.

所有其他数据库存储过程语言(PL/SQL、SQL/PSM)都有类似的问题。就我个人而言,我认为这些语言非常适合它们的用途——它们最适合用于编写数据驱动的逻辑,尤其是如果您希望在多个应用程序中重用数据驱动的逻辑。

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.

我想我的问题是,为什么你希望你的程序作为数据库服务器进程的一部分运行?在应用程序或中级软件级别上,您想要做的不是更好地解决了吗?在那里,您可以选择任何语言或数据处理工具。

#3


2  

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

在我看来,SQL Server中T-SQL的唯一替代方法就是不使用SQL Server

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,

根据您的点处理字符串whit分隔符,这些字符串从哪里来?您可以尝试集成服务和“ssis包”来将数据从一个传输到另一个。还有一种很好的方法可以通过链接服务访问非SQL数据,

#1


8  

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!).

T-SQL没有问题;它完成了预期的工作(除了添加控制流结构之外,但我离题了!)

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).

也许看一下LINQ吧?您可以编写CLR存储过程,但我不建议这样做,除非是针对某些缺失的特性(或繁重的字符串处理)。

#2


3  

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.

所有其他数据库存储过程语言(PL/SQL、SQL/PSM)都有类似的问题。就我个人而言,我认为这些语言非常适合它们的用途——它们最适合用于编写数据驱动的逻辑,尤其是如果您希望在多个应用程序中重用数据驱动的逻辑。

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.

我想我的问题是,为什么你希望你的程序作为数据库服务器进程的一部分运行?在应用程序或中级软件级别上,您想要做的不是更好地解决了吗?在那里,您可以选择任何语言或数据处理工具。

#3


2  

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

在我看来,SQL Server中T-SQL的唯一替代方法就是不使用SQL Server

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,

根据您的点处理字符串whit分隔符,这些字符串从哪里来?您可以尝试集成服务和“ssis包”来将数据从一个传输到另一个。还有一种很好的方法可以通过链接服务访问非SQL数据,