stored procedure in SQL CLR

試著忘記壹切 提交于 2019-12-21 23:22:03

问题


How do you write a stored procedure using C# in SQLCLR?

Currently I am using SQL Server Management Studio and I write stored procedures using T-SQL such as create proc sp_item as .....


回答1:


See:

  • Building my first SQL CLR stored procedure
  • CLR Assembly RegEx Functions for SQL Server by Example
  • Choosing between CLR and T-SQL stored procedures: a simple benchmark

Basically, there are Visual Studio templates which allow you to get started with SQL CLR projects. Fill in the blanks, write your actual code, and you can even deploy those CLR assemblies into SQL Server directly from within Visual Studio.

One word of caution: I would refrain from doing set-based updates and inserts and stuff like that in a SQL CLR stored proc - for that, T-SQL stored procs are just plain better and faster.

SQL-CLR is great to extend SQL Server with stuff like string manipulation, date handling, ability to call e.g. web services or other stuff. I would recommend against trying to replace all T-SQL stored procs with C# SQL CLR stored procs just because you can or just because it's cool - use the right tool for the right job! Mass operations on sets are better left to T-SQL.




回答2:


In addition to the links provided by Marc, I also wrote a short tutorial on writing SQLCLR Table-Valued Functions (FYI, free registration is required to view articles on SQL Server Central):

CLR Table-Valued Function Example with Full Streaming (STVF / TVF)

I have also been writing a series of articles about working with SQLCLR in general:

Stairway to SQLCLR


Also, you should not use sp_ as a prefix in stored procedure names. That is a special syntax that degrades performance due to causing SQL Server to first check for that stored procedure in master, and then, if not found there, it will search the current database.



来源:https://stackoverflow.com/questions/5336800/stored-procedure-in-sql-clr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!