{"id":2855,"date":"2013-09-27T03:44:45","date_gmt":"2013-09-27T03:44:45","guid":{"rendered":"http:\/\/enjoyasp.net\/?p=2855"},"modified":"2013-09-27T03:49:21","modified_gmt":"2013-09-27T03:49:21","slug":"2855","status":"publish","type":"post","link":"https:\/\/enjoyasp.net\/index.php\/2013\/09\/27\/2855\/","title":{"rendered":"\u89e6\u53d1\u5668\u7684\u66ff\u4ee3-cdc\u6570\u636e\u53d8\u66f4\u8bb0\u5f55\u66f4\u597d\u7684\u65b9\u5f0f"},"content":{"rendered":"<pre class=\"brush:sql;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;\">\r\n\r\nSQL Server 2008\u63d0\u4f9b\u4e86\u5185\u5efa\u7684\u65b9\u6cd5&ldquo;&rdquo;\u53d8\u66f4\u6570\u636e\u6355\u83b7&ldquo;&rdquo;\uff08Change Data Capture \u5373CDC\uff09\u4ee5\u5b9e\u73b0\u5f02\u6b65\u8ddf\u8e2a\u7528\u6237\u8868\u7684\u6570\u636e\u4fee\u6539\uff0c\u800c\u4e14\u8fd9\u4e00\u529f\u80fd\u62e5\u6709\u6700\u5c0f\u7684\u6027\u80fd\u5f00\u9500\u3002\u53ef\u4ee5\u7528\u4e8e\u5176\u4ed6\u6570\u636e\u6e90\u7684\u6301\u7eed\u66f4\u65b0\uff0c\u4f8b\u5982\u5c06OLTP\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u53d8\u66f4\u8fc1\u79fb\u5230\u6570\u636e\u4ed3\u5e93\u6570\u636e\u5e93\u3002\r\n\r\n--\u5f00\u542fcdc\r\nEXEC sys.sp_cdc_enable_db\r\n\r\n--net_changes\u8bf4\u7684\u662f\u9488\u5bf9\u4e00\u884c\u8bb0\u5f55\uff0c\u5982\u679c\u6709\u591a\u4e2a\u66f4\u6539\u7684\u8bdd\uff0c\u90a3\u4e48\u4ee5\u6700\u540e\u7684\u4e00\u6761\u4e3a\u51c6\u3002\r\nEXEC sys.sp_cdc_enable_table @source_schema=&#39;dbo&#39;,@source_name=&#39;frmuser&#39;,@capture_instance=&#39;frmuser&#39;,@supports_net_changes=0,@role_name=null \r\n\r\n--\u786e\u8ba4\u8868\u5df2\u7ecf\u88ab\u8ddf\u8e2a  \r\n  \r\nSELECT is_tracked_by_cdc FROM sys.tables  \r\nWHERE name = &#39;frmuser&#39; and schema_id = SCHEMA_ID(&#39;dbo&#39;)  \r\n\r\nEXEC sys.sp_cdc_help_change_data_capture &#39;dbo&#39;, &#39;frmuser&#39; \r\n\r\n--\u66f4\u6539\u8868\u6570\u636e\u67e5\u8be2\u6548\u679c\r\nUPDATE a\r\nSET a.isvalid  = 0\r\nFROM frmuser a\r\nWHERE Account =&#39;sa&#39;\r\n\r\n\r\nSELECT TOP 50 * \r\nFROM [cdc].[frmuser_CT]\r\n\r\nDECLARE @FromLSN varbinary(10) =  \r\nsys.fn_cdc_map_time_to_lsn  \r\n( &#39;smallest greater than or equal&#39; , &#39;2013-09-27 08:30&#39;)  \r\n  \r\nDECLARE @ToLSN varbinary(10) =  \r\nsys.fn_cdc_map_time_to_lsn  \r\n( &#39;largest less than or equal&#39; , &#39;2013-09-27 23:59:59&#39;)  \r\n  \r\n--\u6ce8\u610f\u82e5\u5728\u4e0a\u9762\u7684\u65e5\u671f\u8303\u56f4\u5185\u65e0\u6570\u636e\u7684\u8bdd\uff0c\u5c06\u63d0\u793a\u53c2\u6570\u4e0d\u8db3\r\nSELECT  \r\nCASE __$operation  \r\nWHEN 1 THEN &#39;DELETE&#39;  \r\nWHEN 2 THEN &#39;INSERT&#39;  \r\nWHEN 3 THEN &#39;Before UPDATE&#39;  \r\nWHEN 4 THEN &#39;After UPDATE&#39;  \r\nEND   ,a.*\r\nFROM [cdc].[fn_cdc_get_all_changes_frmuser]  \r\n(@FromLSN, @ToLSN, &#39;all&#39;)   a\r\n\r\n\r\n--\u64a4\u9500CDC\r\nEXEC sys.sp_cdc_disable_table &#39;dbo&#39;, \r\n&#39;FactInternetSales&#39;,&#39;All&#39;\r\n\r\nEXEC sys.sp_cdc_disable_db\r\n\r\n<\/pre>\n<div>\n<pre class=\"brush:sql;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;\">\r\n\u66f4\u6539\u662f\u4e0d\u4f1a\u6c38\u8fdc\u4fdd\u5b58\uff0c\u4f1a\u5b9a\u671f\u6e05\u9664<\/pre>\n<\/div>\n<div>\n\t\u6355\u83b7\u548c\u6e05\u9664\u4f5c\u4e1a\u90fd\u662f\u4f7f\u7528\u9ed8\u8ba4\u53c2\u6570\u521b\u5efa\u7684\u3002\u5c06\u7acb\u5373\u542f\u52a8\u6355\u83b7\u4f5c\u4e1a\u3002\u5b83\u8fde\u7eed\u8fd0\u884c\uff0c\u6bcf\u4e2a\u626b\u63cf\u5468\u671f\u6700\u591a\u53ef\u5904\u7406 1000 \u4e2a\u4e8b\u52a1\uff0c\u5e76\u5728\u4e24\u4e2a\u5468\u671f\u4e4b\u95f4\u505c\u987f 5 \u79d2\u949f\u3002\u6e05\u9664\u4f5c\u4e1a\u5728\u6bcf\u5929\u51cc\u6668 2 \u70b9\u8fd0\u884c\u4e00\u6b21\u3002\u5b83\u5c06\u66f4\u6539\u8868\u9879\u4fdd\u7559\u4e09\u5929\uff084320 \u5206\u949f\uff09\uff0c\u53ef\u4f7f\u7528\u5355\u4e2a\u5220\u9664\u8bed\u53e5\u6700\u591a\u5220\u9664 5000 \u9879\u3002<\/div>\n<div>\n\t&nbsp;<\/div>\n<pre class=\"brush:sql;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;\" style=\"width: 875.125px;\">\r\n\r\n<\/pre>\n<p><\/p>\n<div>\n\t<a href=\"http:\/\/database.51cto.com\/art\/201108\/288049.htm\">SQL Server 2008\u6570\u636e\u5e93\u4e2dCDC\u7684\u529f\u80fd\u4f7f\u7528\u53ca\u8bf4\u660e<\/a><\/div>\n<div>\n\t&nbsp;<\/div>\n<div>\n\t<a href=\"http:\/\/blog.csdn.net\/downmoon\/article\/details\/7443627\">SQL Server 2008\u4e2d\u65b0\u589e\u7684\u53d8\u66f4\u6570\u636e\u6355\u83b7\uff08CDC\uff09\u548c\u66f4\u6539\u8ddf\u8e2a<\/a><\/div>\n<div>\n\t&nbsp;<\/div>\n<div>\n\t<a href=\"http:\/\/www.cnblogs.com\/chenxizhang\/archive\/2009\/04\/28\/1445297.html\">SQL Server 2008 \u7684CDC\u529f\u80fd<\/a><\/div>\n<div>\n\t&nbsp;<\/div>\n<div>\n\t<a href=\"http:\/\/technet.microsoft.com\/zh-cn\/library\/cc645937.aspx\">\u5173\u4e8e\u53d8\u66f4\u6570\u636e\u6355\u83b7 (SQL Server)<\/a><\/div>\n<div>\n\t&nbsp;<\/div>\n","protected":false},"excerpt":{"rendered":"<p>SQL Server 2008\u63d0\u4f9b\u4e86\u5185\u5efa\u7684\u65b9\u6cd5&ldquo;&rdquo;\u53d8\u66f4\u6570\u636e\u6355\u83b7&ldquo;&#038;rdqu [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-2855","post","type-post","status-publish","format-standard","hentry","category-sql-server"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/2855","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/comments?post=2855"}],"version-history":[{"count":0,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/2855\/revisions"}],"wp:attachment":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/media?parent=2855"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/categories?post=2855"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/tags?post=2855"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}