SQL CLR ¼¯³É
Ò»¡¢ÅäÖà SQL Server£¬Ê¹Ö®ÔÊÐí CLR ¼¯³É:
¡¡¡¡1.µ¥»÷“¿ªÊ¼”°´Å¥£¬ÒÀ´ÎÖ¸Ïò“ËùÓгÌÐò”¡¢Microsoft SQL Server 2005 ºÍ“ÅäÖù¤¾ß”£¬È»ºóµ¥»÷“ÍâΧӦÓÃÅäÖÃÆ÷”¡£
¡¡¡¡2.ÔÚ SQL Server 2005 ÍâΧӦÓÃÅäÖÃÆ÷¹¤¾ßÖУ¬µ¥»÷“¹¦ÄܵÄÍâΧӦÓÃÅäÖÃÆ÷”¡£
¡¡¡¡3.Ñ¡ÔñÄúµÄ·þÎñÆ÷ʵÀý£¬Õ¹¿ª“Êý¾Ý¿âÒýÇæ”Ñ¡ÏȻºóµ¥»÷“CLR ¼¯³É”¡£
¡¡¡¡4.Ñ¡Ôñ“ÆôÓà CLR ¼¯³É”¡£
´ËÍ⣬Äú¿ÉÒÔÔÚ SQL Server ÖÐÔËÐÐÒÔϲéѯ£¨´Ë²éѯÐèÒª ALTER SETTINGS ȨÏÞ£©:
USE [database]
sp_configure 'clr enabled', 1;
GO
RECONFIGURE;
GO
¶þ¡¢´´½¨ SQL Server Project£¬ÅäÖÃÊý¾Ý¿âÁ¬½ÓÐÅÏ¢¡£ÓÒ¼ü´ò¿ª¸ÃÏîÄ¿ÊôÐÔ£¬Ñ¡Ôñ“database ”£¬½«Permission LevelÉèΪ“unsafe”
Èý¡¢
ÏîÄ¿´´½¨ºóÌí¼ÓÒ»¸ö.cs Îļþ£¬ÈçÏÂÑÝʾÈçºÎ½øÐбíÖµº¯ÊýÀ©Õ¹
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Server;
using System.Diagnostics;
using System.Data.SqlTypes;
using System.Collections;
public partial class FuncTest
{
//±íÖµº¯Êý¶¨Òå.µÚÒ»¸ö·½·¨ (InitMethod) ¸³Óè SqlFunction ÊôÐÔ£¬ÓÃÓÚ½«ËüÖ¸¶¨Îª¸Ã±íÖµº¯ÊýµÄÈë¿Úµã
//´Ë·½·¨±ØÐë·µ»Ø IEnumerable »ò IEnumerator ¶ÔÏ󡣸öÔÏó°üº¬½«ÓÃÓÚÌî³ä·µ»Ø±íµÄÊý¾Ý¡£
//Ö´Ðиú¯Êýʱ£¬SQL Server ½«Ñ»··ÃÎÊ IEnumerator ¶ÔÏóÖеÄÿ¸ö¶ÔÏ󣬲¢Ê¹ÓÃËüÀ´Ìî³äÊý¾ÝÐС£
//Ϊ´Ë£¬ËüÒª½«¸Ã¶ÔÏ󴫵ݵ½¸ÃÀàÖеĵڶþ¸ö·½·¨ FillRow¡£´Ë·½·¨»á½«¸Ã¶ÔÏóת»»³É·µ»Ø±íÖеÄijһÐС£
//´Ë·½·¨ÔÚ SqlFunction ÊôÐ﵀ FillRowMethodName ²ÎÊýÖÐÖ¸¶¨
//²¿ÊðÏîÄ¿ºóÔÚÊý¾Ý¿âÖлáÉú³ÉÏàÓ¦µÄ±íÖµº¯Êýdbo.ReadEventLog
[SqlFunction(TableDefinition = "logTime datetime,Message nvarchar(4000),Category nvarchar(4000),InstanceId bigint",
Name = "ReadEventLog", FillRowMethodName = "F
Ïà¹ØÎĵµ£º
±¾ÎĽÚÑ¡×ÔMSDNµÄÎÄÕ¡¶ÎåÖÖÌá¸ß SQL ÐÔÄܵķ½·¨¡·£¬Ìá³öÈçºÎÌá¸ß»ùÓÚSQL ServerÓ¦ÓóÌÐòµÄÔËÐÐЧÂÊ£¬·Ç³£ÖµµÃÍƼö¡£¶ÔһЩTrafficºÜ¸ßµÄÓ¦ÓÃϵͳ¶øÑÔ£¬ÈçºÎÌá¸ßºÍ¸Ä½øSQLÖ¸ÁÊǷdz£ÖØÒªµÄ£¬Ò²ÊÇÒ»¸öºÜºÃµÄÍ»ÆƵ㡣
*ÎÄÕÂÖ÷Òª°üÀ¨ÈçÏÂһЩÄÚÈÝ£¨Èç¸ÐÐËȤ£¬ÇëÖ±½Ó·ÃÎÊÏÂÃæµÄURLÔĶÁÍêÕûµÄÖÐÓ¢ÎÄÎĵµ£©£º
1, ´Ó INSE ......
Sql ServerÖеÄÈÕÆÚÓëʱ¼äº¯Êý
1. µ±Ç°ÏµÍ³ÈÕÆÚ¡¢Ê±¼ä
select getdate()
2. dateadd ÔÚÏòÖ¸¶¨ÈÕÆÚ¼ÓÉÏÒ»¶Îʱ¼äµÄ»ù´¡ÉÏ£¬·µ»ØÐ嵀 datetime Öµ
ÀýÈ磺ÏòÈÕÆÚ¼ÓÉÏ2Ìì
select dateadd(day,2,'2004-10-15') --·µ»Ø£º2004-10-17 00:00:00.000
......
Ò»¡¢Êʺ϶ÁÕ߶ÔÏó£ºÊý¾Ý¿â¿ª·¢³ÌÐòÔ±£¬Êý¾Ý¿âµÄÊý¾ÝÁ¿ºÜ¶à£¬Éæ¼°µ½¶ÔSP£¨´æ´¢¹ý³Ì£©µÄÓÅ»¯µÄÏîÄ¿¿ª·¢ÈËÔ±£¬¶ÔÊý¾Ý¿âÓÐŨºñÐËȤµÄÈË¡£ ¡¡
¶þ¡¢½éÉÜ£ºÔÚÊý¾Ý¿âµÄ¿ª·¢¹ý³ÌÖУ¬¾³£»áÓöµ½¸´ÔÓµÄÒµÎñÂß¼ºÍ¶ÔÊý¾Ý¿âµÄ²Ù×÷£¬Õâ¸öʱºò¾Í»áÓÃSPÀ´·â×°Êý¾Ý¿â²Ù×÷¡£Èç¹ûÏîÄ¿µÄSP½Ï¶à£¬ÊéдÓÖûÓÐÒ»¶¨µÄ¹æ·¶£¬½«»áÓ°ÏìÒÔºóµÄϵͳά»¤ ......
SQLº¯Êý
ÔÚSQLÖУ¬º¯Êý¶ÔÊý¾Ý»òÊý¾Ý×éÖ´ÐвÙ×÷£¬È»ºó·µ»ØÐèÒªµÄÖµ¡£º¯Êý±í´ïʽ¿ÉÒÔ³öÏÖÔÚSELECTÁбíÖУ¬»òÕß
ÔÚÈκÎÔÊÐí³öÏÖµÄλÖÃÉÏ¡£SQL°üº¬ÁËÆßÖÖº¯Êý:
(1)¾ÛºÏº¯Êý:·µ»Ø»ã×ÜÖµ¡£
(2)תÐͺ¯Êý:½«Ò»ÖÖÊý¾ÝÀàÐÍת»»ÎªÁíÍâÒ»ÖÖ¡£
(3)ÈÕÆÚº¯Êý:´¦ÀíÈÕÆÚºÍʱ¼ä¡£
(4)Êýѧº¯Êý:Ö´ÐÐËãÊõÔËËã¡£
(5)×Ö·û´®º¯Êý:¶Ô×Ö·û´ ......