Upravit

Sdílet prostřednictvím


What is the C# Language Extension?

Applies to: SQL Server 2019 (15.x) and later versions

The C# Language Extension is a feature of SQL Server Language Extensions that can be used for executing C# code within SQL Server. You can pass an existing SQL Server table to a C# application as a DataFrame, perform operations in C# using rich libraries, and obtain back a result set. This C# language extension allows you to reuse existing C# code, calculations, logic, or extensive libraries that provide functionality you can't get in Transact-SQL (T-SQL).

The external C# language is defined with CREATE EXTERNAL LANGUAGE. The system stored procedure sp_execute_external_script is used as the interface for executing the C# code.

Note

The C# language extension is compatible with SQL Server 2019 (15.x) CU 3 and later versions. Currently, it integrates .NET Core on SQL Server for Windows only. Linux isn't supported.

What you can do

The C# language extension uses the extensibility framework for executing external C# code. Code execution is isolated from the core engine processes, but fully integrated with SQL Server query execution. You can execute C# code at the data's source, eliminating the need to pull data across the network.

You can do data cleaning, fast data querying, or any other processing in C# that can occur through a DataFrame. By embedding C# code in stored procedures, you can push business logic down into the database for better performance. This helps avoid unnecessary data movement and latency, because data doesn't need to be retrieved from SQL Server and moved into the app tier to do the business logic processing.

Get started

  1. Install SQL Server .NET Language Extension on Windows.

  2. Configure development tools.

  3. Write your first C# code. Use the following tutorial as a starting point. Tutorial: Search for a string using regular expressions (regex) in C#.