SQL ServerÖÐʹÓÃCLRµ÷ÓÃ.NET·½·¨
½éÉÜ
ÎÒÃÇÒ»ÆðÀ´×ö¸öʾÀý£¬ÔÚ.NETÖÐн¨Ò»¸öÀ࣬²¢ÔÚÕâ¸öÀàÀïн¨Ò»¸ö·½·¨£¬È»ºóÔÚSQL ServerÖе÷ÓÃÕâ¸ö·½·¨¡£°´ÕÕ΢ÈíËùÊö£¬Í¨¹ýËÞÖ÷ Microsoft .NET Framework 2.0 ¹«¹²ÓïÑÔÔËÐпâ (CLR)£¬SQL Server 2005ÏÔÖøµØÔöÇ¿ÁËÊý¾Ý¿â±à³ÌÄ£ÐÍ¡£ ÕâʹµÃ¿ª·¢ÈËÔ±¿ÉÒÔÓÃÈκÎCLRÓïÑÔ£¨ÈçC#¡¢VB.NET»òC++µÈ£©À´Ð´´æ´¢¹ý³Ì¡¢´¥·¢Æ÷ºÍÓû§×Ô¶¨Ò庯Êý¡£
ÎÒÃÇÈçºÎʵÏÖÕâЩ¹¦ÄÜÄØ£¿
ΪÁËʹÓÃCLR£¬ÎÒÃÇÐèÒª×öÈçϼ¸²½£º
1¡¢ÔÚ.NETÖÐн¨Ò»¸öÀ࣬²¢ÔÚÕâ¸öÀàÀïн¨Ò»¸öpublic·½·¨¡£
2¡¢±àÒëÕâ¸öÀàΪһ¸öDLL¡£
3¡¢ÔÚSQL ServerÖÐ×¢²áÕâ¸öDLL¡£
4¡¢Ð½¨Ò»¸öSQL Serverº¯ÊýÀ´·ÃÎÊÖ¸¶¨µÄ.NET·½·¨¡£
½ÓÏÂÀ´£¬ÎÒÃÇÒ»ÆðÀ´Íê³ÉÒ»¸öʾÀý
Ê×ÏÈ£¬ÔÚVisual StudioÖÐн¨Ò»¸öÃûΪ“SQLServerCLRTest”µÄÀà¿âÏîÄ¿¡£ È»ºó£¬Ð½¨Ò»¸öÃûΪ“CLRFunctions”µÄÀ࣬²¢ÔÚÆäÄÚÌí¼ÓÒ»¸öÃûΪ“HelloWold”µÄ·½·¨£¬´úÂëÈçÏ£º
public class CLRFunctions
{
public static string HelloWorld(string Name)
{
return ("Hello " + Name);
}
}
ÕâÊÇÒ»¸ö·Ç³£¼òµ¥µÄ·½·¨£¨ÎªÁËÈÃSQL Server¿ÉÒÔµ÷ÓÃËü£¬Ëü±ØÐëÒªÊÇpublicºÍstaticµÄ£©£¬Õâ¸ö·½·¨ÓÐÒ»¸östringÀàÐ͵IJÎÊý£¬·µ»ØÐÅϢΪ“Hello”¼ÓÉÏÄã´«ÈëµÄ²ÎÊý¡£
ÏÖÔÚ£¬ÎÒÃÇÐèÒª±àÒëÕâ¸öÏîĿΪһ¸öDLL£¬²¢ÔÚSQL ServerÖÐ×¢²áËü¡£ ÕâÒ²ÊDZȽϼòµ¥µÄ£¬ÔÚVSÖÐÓÒ¼üµ¥»÷ÏîÄ¿£¬Ñ¡Ôñ“Éú³É”ºó³ÌÐò¾Í»áÉú³ÉÒ»¸öDLL¡£ Èç¹ûÄãµÄÏîÄ¿Êǵ÷ÊÔģʽµÄ»°£¬ÄÇô¾Í¿ÉÒÔÔÚÈçÏÂËùʾÄÇÑùµÄ·¾¶ÀïÕÒµ½±àÒëºÃµÄDLL¡£
C:\Documents and Settings\mark.smith\My Documents\Visual Studio 2005\Projects\SQLServerCLRTest\SQLServerCLRTest\bin\Debug\SQLServerCLRTest.dll
ÕÒµ½Õâ¸öDLLºó£¬ÎÒÃǾͿÉÒÔ°ÑËü¿½±´µ½ÎÒÃǵÄSQL Server»úÆ÷ÉÏÁË£¬Èç¹ûÊÇÏàͬ»úÆ÷µÄ»°ÎÒÃÇÖ»Òª¼ÇסÕâ¸ö·¾¶¼´¿É¡£
ÆôÓÃCLR¹¦ÄÜ
ĬÈÏÇé¿öÏ£¬SQL ServerÖеÄCLRÊǹرյģ¬ËùÒÔÎÒÃÇÐèÒªÖ´ÐÐÈçÏÂÃüÁî´ò¿ªCLR£º
exec sp_configure 'clr enabled',1
reconfigure
go
×¢²áDLL
ΪÁ˵÷ÓÃÎÒÃÇдµÄÄǸö·½·¨£¬ÐèÒªÔÚSQL ServerÖÐ×¢²áÎÒÃǸոձàÒëºÃµÄÄǸöDLL¡£ ÎÒÃÇ¿ÉÒÔÔÚÊý¾Ý¿âÖÐʹÓÃÈçÏÂÃüÁîÀ´×¢²áDLL£¨Â·¾¶ÎªÄãµÄDLLÎļþµÄ·¾¶£©
CREATE ASSEMBLY asmHelloWorld from 'C:\SQLServerCLRTest.dll'
ÔÚSQL ServerÖе÷ÓÃÎÒÃǵÄ.NET·½·¨
ΪÁ˵÷ÓÃ.NET·½·¨£¬ÎÒÃÇ¿ÉÒÔдһ¸öSQL Server×Ô¶¨Ò庯Êý£¬²¢ÔÚÆäÄÚʹÓÃ&ld
Ïà¹ØÎĵµ£º
·ÀSQLÊý×Ö×¢È뺯Êý
http://blog.csdn.net/cncco/archive/2007/10/03/1810540.aspx
·ÀSQL×¢È뺯Êý
³ÌÐò´úÂ룺
º¯Êý²¿·Ö========================================================================
'------------------------------------------------
'ÓÃ;:¼ì²éÊÇ·ñΪÊý×Ö,ÒÔ¼°Êý×ÖÊÇ·ñ³¬³ö·¶Î§
'ÊäÈë:¼ì²é×Ö·û,´ ......
ÊéÇ©£ºÇå³ýËùÓÐÊéÇ©¡£ CTRL-SHIFT-F2
ÊéÇ©£º²åÈë»òɾ³ýÊéÇ©(Çл»)¡£ CTRL+F2
ÊéÇ©£ºÒƶ¯µ½ÏÂÒ»¸öÊéÇ©¡£ F2 ¹¦Äܼü
ÊéÇ©£ºÒƶ¯µ½ÉÏÒ»¸öÊéÇ©¡£ SHIFT+F2
È¡Ïû²éѯ¡£ ALT+BREAK
Á¬½Ó£ºÁ¬½Ó¡£ CTRL+O
Á¬½Ó£º¶Ï¿ªÁ¬½Ó¡£ CTRL+F4
Á¬½Ó£º¶Ï¿ªÁ¬½Ó²¢¹Ø±Õ×Ó´°¿Ú¡£ CTRL+F4
Êý¾Ý¿â¶ÔÏóÐÅÏ¢¡£ ALT+F1
±à¼£ºÇå³ý»î¶¯ ......
ʵÑéÄÚÈÝ£º
ÕÆÎÕSQL Server 2000µÄÔ¤±àÒë³ÌÐòNSQLPREP.EXEµÄʹÓã¨ÒԿα¾ÀýÌâ1½øÐе÷ÊÔ£©£»
ʵÑé²½Ö裺
Ò»¡¢Êý¾Ý¿â»·¾³ÅäÖÃ
1¡¢´´½¨xueshengÊý¾Ý¿â£¬½¨Á¢student±íµÈ£»
2¡¢¹Ø±Õsql server 2000·þÎñ¹ÜÀíÆ÷£»
3¡¢½«devtoolsÎļþ¼Ð¿½±´µ½£ºC:\Program Files\Microsoft SQL Server
4¡¢½«BinnÎļþ¼Ð¿½±´µ½£ºC:\Program ......
/*»ñÈ¡Öظ´¼Ç¼ÖнÏСµÄÄǸöID*/ create table tmp_Repeat as select min(id) as id from poi group by idcode having count(*) >1; /*±¸·Ýɾ³ýµÄÊý¾Ý*/ select * from poi where id in (select id from tmp_repeat) /*ɾ³ýÖظ´¼Ç¼ÖÐID½ÏСµÄÄÇÌõ
select replace('°¢¹ðÊǸöºÃº¢×Ó','°¢¹ð','СÏÍ') from du ......
MS SQLÈëÃÅ»ù´¡:Ë÷ÒýÊÓͼ
ÊÕ²Ø
¡¡
¡¡ÔÚÇ°ÃæÎÒÃÇÒѾÌáµ½¹ýÓйØÊÓͼµÄÏÂÊö¹Ûµã£ºÓÉÓÚÊÓͼ·µ»ØµÄ½á¹û¼¯Óë¾ßÓÐÐÐÁнṹµÄ±íÓÐ×ÅÏàͬµÄ±í¸ñÐÎʽ£¬²¢ÇÒÎÒÃÇ¿ÉÒÔÔÚSQL
Óï¾äÖÐÏñÒýÓñíÄÇÑùÒýÓÃÊÓͼ£¬ËùÒÔÎÒÃdz£°ÑÊÓͼ³ÆΪÐé±í¡£±ê×¼ÊÓͼµÄ½á¹û¼¯²¢²»ÒÔ ......