SQL SERVER 2008 ¸ü¸Ä¸ú×Ù
SQL SERVER 2008 ¸ü¸Ä¸ú×Ù
/*
¿´Ê飬¿´Áª»úÆڼ䡣¡£¡£Ë³´ø°Ñ¿´µ½µÄдÏÂ
ÓëSQL SERVER 2008 CDC Òì²½²¶»ñÊý¾Ý±ä¸üµÄ²»Í¬,¸ü¸Ä¸ú×ÙÊÇͬ²½½ø³Ì,
ÊÇDML(INSERT/UPDATE/DELETE)ÊÂÎñµÄÒ»²¿·Ö,Ëü¿ÉÒÔʹÓÃ×îСµÄCÅÌ´æ´¢
¿ªÏúÀ´Õì²âÊý¾ÝÐеľ»±ä¸ü.ÄÇôËüÒ²¾Í²»ÄÜÏñCDCÄÇÑù¿ÉÒÔÌṩÓû§±íµÄ
ÀúÊ·¸ü¸ÄÐÅÏ¢. ¸ü¸ÄÊÇʹÓÃÒì²½½ø³Ì²¶»ñµÄ,´Ë½ø³Ì¶ÁÈ¡ÊÂÎñÈÕÖ¾,²¢
ÇÒ¶ÔϵͳÔì³ÉµÄÓ°ÏìºÜС.
¸ü¸Ä¸ú×Ù²¶»ñ¸ü¸ÄÁ˱íÐÐÕâÒ»ÊÂʵ,µ«²»»á²¶»ñ¸ü¸ÄµÄÊý¾Ý.ÕâÑù,Ó¦ÓóÌ
Ðò¾Í¿ÉÒÔÈ·¶¨Ê¹ÓôÓÓû§±íÖÐÖ±½Ó»ñÈ¡µÄ×îÐÂÐÐÊý¾Ý¸ü¸ÄµÄÐÐ.Òò´Ë,Óë±ä
¸üÊý¾Ý²¶»ñÏà±È,¸ü¸Ä¸ú×Ù¿ÉÒÔ½â´ðµÄÀúÊ·ÎÊÌâ±È½ÏÓÐÏÞ.µ«ÊÇ,¶ÔÓÚ²»Ðè
ÒªÀúÊ·ÐÅÏ¢µÄÄÇЩӦÓóÌÐò,¸ü¸Ä¸ú×Ù²úÉúµÄ´æ´¢¿ªÏúҪСµÃ¶à,ÒòΪËü²»
ÐèÒª²¶»ñ¸ü¸ÄµÄÊý¾Ý(²»ÐèÒª´¥·¢Æ÷ºÍ±íʱ¼ä´Á).ËüʹÓÃͬ²½¸ú×Ù»úÖÆÀ´
¸ú×Ù¸ü¸Ä.´Ë¹¦ÄÜÖ¼ÔÚ×î´óÏ޶ȵؼõÉÙDML ²Ù×÷¿ªÏú.
×ܵÄÀ´ËµÓÐÒÔϼ¸µã:
1 ¼õÉÙÁË¿ª·¢Ê±¼ä: ÓÉÓÚSQL Server 2008 ÖÐÌṩÁ˸ü¸Ä¸ú×Ù¹¦ÄÜ,Òò´ËÎÞÐ迪·¢×Ô¶¨Òå½â¾ö·½°¸.
2 ²»ÐèÒª¼Ü¹¹¸ü¸Ä: ʹÓøü¸Ä¸ú×Ù²»ÐèÒªÖ´ÐÐÒÔÏÂÈÎÎñ£ºÌí¼ÓÁÐ;Ìí¼Ó´¥·¢Æ÷;Èç¹ûÎÞ·¨½«ÁÐÌí¼Óµ½ÓÃ
»§±í,ÔòÐèÒª´´½¨ÒªÔÚÆäÖиú×ÙÒÑɾ³ýµÄÐлò´æ´¢¸ü¸Ä¸ú×ÙÐÅÏ¢µÄ¶Ë±í.
3 ÄÚÖÃÇå³ý»úÖÆ: ¸ü¸Ä¸ú×ÙµÄÇå³ý²Ù×÷ÔÚºǫ́×Ô¶¯Ö´ÐÐ.²»ÐèÒª¶Ë±íÖд洢µÄÊý¾ÝµÄ×Ô¶¨ÒåÇå³ý.
4 Ìṩ¸ü¸Ä¸ú×Ù¹¦ÄܵÄÄ¿µÄÊÇ»ñÈ¡¸ü¸ÄÐÅÏ¢: ʹÓøü¸Ä¸ú×Ù¹¦ÄÜ¿ÉʹÐÅÏ¢²éѯºÍʹÓøü·½±ã.Áиú×Ù
¼Ç¼ÌṩÓë¸ü¸ÄµÄÊý¾ÝÏà¹ØµÄÏêϸÐÅÏ¢.
5 ½µµÍÁËDML ²Ù×÷µÄ¿ªÏú: ͬ²½¸ü¸Ä¸ú×ÙʼÖÕ»áÓÐһЩ¿ªÏú.µ«ÊÇ,ʹÓøü¸Ä¸ú×ÙÓÐÖúÓÚʹ¿ªÏú×îС
 
Ïà¹ØÎĵµ£º
SQLÓï¾äµÄÓÅ»¯¾ÍÊǽ«ÐÔÄܽϵ͵ÄSQLÓï¾äת»»´ï³ÉͬÑùÄ¿µÄÐÔÄÜÓÅÒìµÄSQLÓï¾ä
ÏÂÃæÎÒÃÇÒ»ÆðÀ´¿´¿´Ò»Ð©¿ÉÒÔÓÅ»¯SQLµÄ·½·¨£¬Ï£Íû´ó¼Ò¶àÌá³öÒâ¼ûÎÒÃǹ²Í¬Ñ§Ï°»òÕßÊÇ´ó¼ÒÓÐʲôºÃµÄÓÅ»¯·½·¨¿ÉÒÔÌá³öÀ´¹²Ïíһϡ£
µÚÒ»ÖÖÓÅ»¯£¨Ê¹ÓÃÖ¸¶¨ÁдúÌæ”*”£©
ʹÓÓ*”¿ÉÒÔ½µµÍ±àдSQLÓï ......
ÔÚSQL Server 2008ÖÐÒýÈëÁËhierarchyidÀ´´¦ÀíÊ÷×´½á¹¹¡£ÏÂÃæ¼òµ¥¾ÍÒÔAdventureWorks(ÎÞhierarchyid)ºÍAdventureWorks2008(ÓÐhierarchyid)ÀïµÄHumanResources.EmployeeΪÀý£¬À´ËµÃ÷Ò»ÏÂÔÚеÄhierarchyidÖÐÈçºÎ½øÐÐflat»¯µÄdimension³éÈ¡¡£
AdventureWorksÊÇ΢ÈíΪSQL ServerÌṩµÄÊý¾Ý¿âÐéÄâ°¸Àý¡£
AdventureWorksÖÐËùÒªµ ......
select upper(name) from syscolumns
where id =any
(
select Id from sysobjects where name='tb_city'
)
lower
select row_number() over(order by firmid) from dbo.tb_BuildingMaterial
Éú³É ×ÔÔö 123
select rank() over(order by firmid) from dbo.tb_BuildingMaterial
Éú³É×ÔÔö123 ¸ù¾ÝÅ ......
1.×Ö·û´®º¯Êý
³¤¶ÈÓë·ÖÎöÓÃ
datalength(Char_expr) ·µ»Ø×Ö·û´®°üº¬×Ö·ûÊý,µ«²»°üº¬ºóÃæµÄ¿Õ¸ñ
substring(expression,start,length) ²»¶à˵ÁË,È¡×Ó´®
right(char_expr,int_expr) ·µ»Ø×Ö·û´®ÓÒ±ßint_expr¸ö×Ö·û
×Ö·û²Ù×÷Àà
upper(char_expr) תΪ´óÐ ......
ÓÐÖ´ÐÐsqlÌõ¼þÓï¾äwhere id in(@²ÎÊý)µÄʱºò£¬Èç¹û´¦Àí²»µ±£¬¾Í»á³öÏÖÎÊÌ⣺
ÈçÏÂÃæÕâ¸ö´æ´¢¹ý³Ì£º
alter proc Web_gettwtwgoldgameserverGoldSell
@ID int
as
declare @twgoldsellID nvarchar(1000)
select @twgoldsellID=twgoldsellID from twgoldgameserver where ID=@ID
set @twgoldsellID=replace(@twgoldsell ......