PROCEDURES AND FUNCTIONS IN .NET LANGUAGES In summary,

PROCEDURES AND FUNCTIONS IN .NET LANGUAGES In summary, to create a TVF, you make a class that implements both ISqlReader and ISqlRecord. You also create a static function that creates an instance of this class and returns it through the ISqlReader or ISql Record interface. Then you catalog the function as you would any other CLR function in SQL Server, noting that it returns a TABLE. The ISql Record interface must return the appropriate data types for the columns you specify in this table. Triggers Triggers in SQL Server may be implemented by a CLR method. Methods that implement a trigger must return a void and have no parameters. The following code is an example of a C# method that can be used as a trigger. public class Triggers { public static void OnMyUpdate() { … code that checks/modifies database } } Since a method that implements a trigger has no inputs or outputs, the only thing of consequence it can do, just as it is for a T-SQL trigger, is check what the operation that caused the trigger did to the database and possibly prevent it, change it, or roll it back. To do these operations, the CLR code must use SQL commands. Chapter 4 discusses using SQL commands as part of stored procedures, functions, and triggers implemented using a CLR language. The CLR function that implements a trigger does so in a context called the SqlTriggerContext. The SqlTriggerContext is discussed in Chapter 4. It makes available to the method the INSERTED and DELETED logical tables that triggers use to determine what operation was done. Triggers implemented using a CLR method are added to a database using a syntax similar to the one used for adding T-SQL triggers. The following code is an example of adding a trigger to a database. CREATE TRIGGER OnMyUpdate ON Invoices AS EXTERNAL NAME Triggers.CInvoices.OnMyUpdate The behavior and operation of CLR triggers is the same as for T-SQL triggers.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services

Bookmark the permalink.

Comments are closed.