简体   繁体   English

SQL CLR中的存储过程

[英]stored procedure in SQL CLR

How do you write a stored procedure using C# in SQLCLR? 如何在SQLCLR中使用C#编写存储过程?

Currently I am using SQL Server Management Studio and I write stored procedures using T-SQL such as create proc sp_item as .... . 目前,我正在使用SQL Server Management Studio,并使用T-SQL编写存储过程,例如create proc sp_item as ....

See: 看到:

Basically, there are Visual Studio templates which allow you to get started with SQL CLR projects. 基本上,有Visual Studio模板可让您开始使用SQL CLR项目。 Fill in the blanks, write your actual code, and you can even deploy those CLR assemblies into SQL Server directly from within Visual Studio. 填写空白,编写实际代码,甚至可以直接从Visual Studio中将这些CLR程序集部署到SQL Server中。

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存储proc的操作-为此,T-SQL存储proc变得更好,更快。

SQL-CLR is great to extend SQL Server with stuff like string manipulation, date handling, ability to call eg web services or other stuff. SQL-CLR很好地扩展了 SQL Server的功能,例如字符串处理,日期处理,调用功能(例如Web服务或其他功能)。 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! 我建议不要 仅仅因为您可以或者仅仅因为它很酷就尝试用C#SQL CLR存储的proc替换所有T-SQL存储的proc-使用正确的工具完成正确的工作! Mass operations on sets are better left to T-SQL. 集中的批量操作最好留给T-SQL使用。

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): 除了Marc提供的链接之外,我还写了一个简短的教程来编写SQLCLR表值函数(FYI,需要免费注册才能查看SQL Server Central上的文章):

CLR Table-Valued Function Example with Full Streaming (STVF / TVF) 具有完整流的SLR表值函数示例(STVF / TVF)

I have also been writing a series of articles about working with SQLCLR in general: 我也一直在写一系列有关使用SQLCLR的文章:

Stairway to SQLCLR SQLCLR的阶梯


Also, you should not use sp_ as a prefix in stored procedure names. 同样,您不应在存储过程名称中使用sp_作为前缀。 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. 这是一种特殊的语法,由于导致SQL Server首先在master检查该存储过程,从而降低了性能, 然后 ,如果在那里没有找到,它将搜索当前数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM