{"id":181,"date":"2011-09-03T10:30:43","date_gmt":"2011-09-03T02:30:43","guid":{"rendered":"http:\/\/www.royalwzy.com\/?p=181"},"modified":"2013-12-30T14:16:32","modified_gmt":"2013-12-30T06:16:32","slug":"sql-server-2008-%e6%9b%b4%e6%94%b9%e8%b7%9f%e8%b8%aa","status":"publish","type":"post","link":"http:\/\/www.royalwzy.com\/?p=181","title":{"rendered":"SQL Server 2008 \u66f4\u6539\u8ddf\u8e2a"},"content":{"rendered":"<p style=\"color: #333333; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u4e0eSQL SERVER 2008 CDC \u5f02\u6b65\u6355\u83b7\u6570\u636e\u53d8\u66f4\u7684\u4e0d\u540c,\u66f4\u6539\u8ddf\u8e2a\u662f\u540c\u6b65\u8fdb\u7a0b,\u662fDML(INSERT\/UPDATE\/DELETE)\u4e8b\u52a1\u7684\u4e00\u90e8\u5206,\u5b83\u53ef\u4ee5\u4f7f\u7528\u6700\u5c0f\u7684C\u76d8\u5b58\u50a8\u5f00\u9500\u6765\u4fa6\u6d4b\u6570\u636e\u884c\u7684\u51c0\u53d8\u66f4.\u90a3\u4e48\u5b83\u4e5f\u5c31\u4e0d\u80fd\u50cfCDC\u90a3\u6837\u53ef\u4ee5\u63d0\u4f9b\u7528\u6237\u8868\u7684\u5386\u53f2\u66f4\u6539\u4fe1\u606f.\u66f4\u6539\u662f\u4f7f\u7528\u5f02\u6b65\u8fdb\u7a0b\u6355\u83b7\u7684,\u6b64\u8fdb\u7a0b\u8bfb\u53d6\u4e8b\u52a1\u65e5\u5fd7,\u5e76\u4e14\u5bf9\u7cfb\u7edf\u9020\u6210\u7684\u5f71\u54cd\u5f88\u5c0f.<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u66f4\u6539\u8ddf\u8e2a\u6355\u83b7\u66f4\u6539\u4e86\u8868\u884c\u8fd9\u4e00\u4e8b\u5b9e,\u4f46\u4e0d\u4f1a\u6355\u83b7\u66f4\u6539\u7684\u6570\u636e.\u8fd9\u6837,\u5e94\u7528\u7a0b\u5e8f\u5c31\u53ef\u4ee5\u786e\u5b9a\u4f7f\u7528\u4ece\u7528\u6237\u8868\u4e2d\u76f4\u63a5\u83b7\u53d6\u7684\u6700\u65b0\u884c\u6570\u636e\u66f4\u6539\u7684\u884c.\u56e0\u6b64,\u4e0e\u53d8\u66f4\u6570\u636e\u6355\u83b7\u76f8\u6bd4,\u66f4\u6539\u8ddf\u8e2a\u53ef\u4ee5\u89e3\u7b54\u7684\u5386\u53f2\u95ee\u9898\u6bd4\u8f83\u6709\u9650.\u4f46\u662f,\u5bf9\u4e8e\u4e0d\u9700\u8981\u5386\u53f2\u4fe1\u606f\u7684\u90a3\u4e9b\u5e94\u7528\u7a0b\u5e8f,\u66f4\u6539\u8ddf\u8e2a\u4ea7\u751f\u7684\u5b58\u50a8\u5f00\u9500\u8981\u5c0f\u5f97\u591a,\u56e0\u4e3a\u5b83\u4e0d\u9700\u8981\u6355\u83b7\u66f4\u6539\u7684\u6570\u636e(\u4e0d\u9700\u8981\u89e6\u53d1\u5668\u548c\u8868\u65f6\u95f4\u6233).\u5b83\u4f7f\u7528\u540c\u6b65\u8ddf\u8e2a\u673a\u5236\u6765\u8ddf\u8e2a\u66f4\u6539.\u6b64\u529f\u80fd\u65e8\u5728\u6700\u5927\u9650\u5ea6\u5730\u51cf\u5c11DML \u64cd\u4f5c\u5f00\u9500.<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u603b\u7684\u6765\u8bf4\u6709\u4ee5\u4e0b\u51e0\u70b9:<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">1.<\/span><span lang=\"zh-CN\">\u51cf\u5c11\u4e86\u5f00\u53d1\u65f6\u95f4:\u7531\u4e8eSQL Server 2008 \u4e2d\u63d0\u4f9b\u4e86\u66f4\u6539\u8ddf\u8e2a\u529f\u80fd,\u56e0\u6b64\u65e0\u9700\u5f00\u53d1\u81ea\u5b9a\u4e49\u89e3\u51b3\u65b9\u6848.<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">2.<\/span><span lang=\"zh-CN\">\u4e0d\u9700\u8981\u67b6\u6784\u66f4\u6539:\u4f7f\u7528\u66f4\u6539\u8ddf\u8e2a\u4e0d\u9700\u8981\u6267\u884c\u4ee5\u4e0b\u4efb\u52a1<\/span><span lang=\"en-US\">:<\/span><span lang=\"zh-CN\">\u6dfb\u52a0\u5217<\/span><span lang=\"en-US\">;<\/span><span lang=\"zh-CN\">\u6dfb\u52a0\u89e6\u53d1\u5668<\/span><span lang=\"en-US\">;<\/span><span lang=\"zh-CN\">\u5982\u679c\u65e0\u6cd5\u5c06\u5217\u6dfb\u52a0\u5230\u7528\u6237\u8868,\u5219\u9700\u8981\u521b\u5efa\u8981\u5728\u5176\u4e2d\u8ddf\u8e2a\u5df2\u5220\u9664\u7684\u884c\u6216\u5b58\u50a8\u66f4\u6539\u8ddf\u8e2a\u4fe1\u606f\u7684\u7aef\u8868.<\/span><span lang=\"en-US\">o<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">3.<\/span><span lang=\"zh-CN\">\u5185\u7f6e\u6e05\u9664\u673a\u5236:\u66f4\u6539\u8ddf\u8e2a\u7684\u6e05\u9664\u64cd\u4f5c\u5728\u540e\u53f0\u81ea\u52a8\u6267\u884c.\u4e0d\u9700\u8981\u7aef\u8868\u4e2d\u5b58\u50a8\u7684\u6570\u636e\u7684\u81ea\u5b9a\u4e49\u6e05\u9664.<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">4.<\/span><span lang=\"zh-CN\">\u63d0\u4f9b\u66f4\u6539\u8ddf\u8e2a\u529f\u80fd\u7684\u76ee\u7684\u662f\u83b7\u53d6\u66f4\u6539\u4fe1\u606f:\u4f7f\u7528\u66f4\u6539\u8ddf\u8e2a\u529f\u80fd\u53ef\u4f7f\u4fe1\u606f\u67e5\u8be2\u548c\u4f7f\u7528\u66f4\u65b9\u4fbf.\u5217\u8ddf\u8e2a\u8bb0\u5f55\u63d0\u4f9b\u4e0e\u66f4\u6539\u7684\u6570\u636e\u76f8\u5173\u7684\u8be6\u7ec6\u4fe1\u606f.<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">5.<\/span><span lang=\"zh-CN\">\u964d\u4f4e\u4e86DML \u64cd\u4f5c\u7684\u5f00\u9500:\u540c\u6b65\u66f4\u6539\u8ddf\u8e2a\u59cb\u7ec8\u4f1a\u6709\u4e00\u4e9b\u5f00\u9500.\u4f46\u662f,\u4f7f\u7528\u66f4\u6539\u8ddf\u8e2a\u6709\u52a9\u4e8e\u4f7f\u5f00\u9500\u6700\u5c0f\u5316.\u5f00\u9500\u901a\u5e38\u4f1a\u4f4e\u4e8e\u4f7f\u7528\u5176\u4ed6\u89e3\u51b3\u65b9\u6848,\u5bf9\u4e8e\u9700\u8981\u4f7f\u7528\u89e6\u53d1\u5668\u7684\u89e3\u51b3\u65b9\u6848,\u5c24\u5176\u5982\u6b64.<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">6.<\/span><span lang=\"zh-CN\">\u66f4\u6539\u8ddf\u8e2a\u662f\u57fa\u4e8e\u63d0\u4ea4\u7684\u4e8b\u52a1\u8fdb\u884c\u7684:\u66f4\u6539\u7684\u987a\u5e8f\u57fa\u4e8e\u4e8b\u52a1\u63d0\u4ea4\u65f6\u95f4.\u5728\u5b58\u5728\u957f\u65f6\u95f4\u8fd0\u884c\u548c\u91cd\u53e0\u4e8b\u52a1\u7684\u60c5\u51b5\u4e0b,\u8fd9\u6837\u53ef\u83b7\u5f97\u53ef\u9760\u7684\u7ed3\u679c.\u5fc5\u987b\u4e13\u95e8\u8bbe\u8ba1\u4f7f\u7528timestamp<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u503c\u7684\u81ea\u5b9a\u4e49\u89e3\u51b3\u65b9\u6848,\u4ee5\u5904\u7406\u8fd9\u4e9b\u60c5\u51b5.<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">7.<\/span><span lang=\"zh-CN\">\u914d\u7f6e\u548c\u7ba1\u7406\u66f4\u6539\u8ddf\u8e2a\u7684\u6807\u51c6\u5de5\u5177:SQL Server 2008 \u63d0\u4f9b\u6807\u51c6\u7684DDL \u8bed\u53e5\u3001SQL Server Management\u00a0Studio<\/span><span lang=\"en-US\">,<\/span><span lang=\"zh-CN\">\u76ee\u5f55\u89c6\u56fe\u548c\u5b89\u5168\u6743\u9650.<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"zh-CN\">\u5177\u4f53\u6b65\u9aa4<\/span><span lang=\"en-US\">:<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">1.<\/span><span lang=\"zh-CN\">\u5efa\u7acb\u6d4b\u8bd5\u6570\u636e\u5e93<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">IF NOT EXISTS (SELECT name FROM SYS.databases WHERE name = N&#8217;CHANGE_TRACK_DB&#8217;)<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">BEGIN<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in 0in 0in 0.375in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">CREATE DATABASE CHANGE_TRACK_DB<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">END<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u8981\u542f\u7528\u6570\u636e\u5e93\u66f4\u6539\u8ddf\u8e2a\u529f\u80fd,\u9700\u8981\u914d\u7f6eCHANGE_TRACKING\u6570\u636e\u5e93\u9009\u9879.\u4e5f\u53ef\u4ee5\u914d\u7f6e\u8ddf\u8e2a\u7684\u6570\u636e\u5728\u6570\u636e\u5e93\u4fdd\u7559\u591a\u4e45,\u4ee5\u53ca\u662f\u5426\u542f\u7528\u81ea\u52a8\u6e05\u9664.\u914d\u7f6e\u4fdd\u7559\u671f\u5c06\u4f1a\u5f71\u54cd\u5230\u9700\u8981\u7ef4\u62a4\u7684\u8ddf\u8e2a\u6570\u636e\u7684\u5927\u5c0f.\u8be5\u503c\u8fc7\u9ad8\u53ef\u80fd\u4f1a\u5f71\u54cd\u5b58\u50a8.\u592a\u4f4e\u7684\u8bdd\u5728\u8fdc\u7a0b\u5e94\u7528\u7a0b\u5e8f\u540c\u6b65\u4e0d\u591f\u7684\u60c5\u51b5\u4e0b,\u4f1a\u5f15\u53d1\u901a\u53e6\u4e00\u5e94\u7528\u7a0b\u5e8f\u7684\u540c\u6b65\u95ee\u9898.<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">2.<\/span><span lang=\"zh-CN\">\u914d\u7f6e\u66f4\u6539\u8ddf\u8e2a<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">ALTER DATABASE CHANGE_TRACK_DB<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SET CHANGE_TRACKING = ON(CHANGE_RETENTION = 36HOURS, AUTO_CLEANUP = ON)<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u4f7f\u7528\u66f4\u6539\u8ddf\u8e2a\u65f6\u7684\u6700\u4f73\u5b9e\u8df5\u662f\u4e3a\u6570\u636e\u5e93\u542f\u7528\u5feb\u7167\u9694\u79bb.\u4e0d\u4f7f\u7528\u5feb\u7167\u9694\u79bb\u4f1a\u5f15\u53d1\u4e8b\u52a1\u4e0d\u4e00\u81f4\u7684\u53d8\u66f4\u4fe1\u606f.\u5bf9\u6709\u663e\u8457DML\u6d3b\u52a8\u7684\u6570\u636e\u5e93\u548c\u8868,\u4ee5\u4e00\u81f4\u7684\u65b9\u5f0f\u6355\u83b7\u66f4\u6539\u8ddf\u8e2a\u7684\u4fe1\u606f\u5f88\u91cd\u8981(\u6293\u53d6\u6700\u65b0\u7248\u672c\u5e76\u4f7f\u7528\u8be5\u7248\u672c\u53f7\u6765\u83b7\u53d6\u9002\u5f53\u7684\u6570\u636e)\u7531\u4e8e\u884c\u7248\u672c\u7684\u751f\u6210,\u542f\u7528\u5feb\u7167\u9694\u79bb\u4f1a\u5728tempdb\u4e2d\u589e\u52a0\u989d\u5916\u7684\u4f7f\u7528\u7a7a\u95f4.\u4f1a\u5e26\u6765I\/O\u5f00\u9500\u7684\u589e\u52a0.<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">3.<\/span><span lang=\"zh-CN\">\u542f\u7528\u5feb\u7167\u9694\u79bb<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">ALTER DATABASE CHANGE_TRACK_DB<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SET ALLOW_SNAPSHOT_ISOLATION ON<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">GO<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">4.<\/span><span lang=\"zh-CN\">\u901a\u8fc7\u67e5\u8be2sys.change_tracking_databases\u6765\u786e\u8ba4\u6570\u636e\u5e93\u662f\u5426\u4ee5\u6b63\u786e\u542f\u7528\u66f4\u6539\u8ddf\u8e2a.<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SELECT DB_NAME(DATABASE_ID) AS [DB_NAME], IS_AUTO_CLEANUP_ON, RETENTION_PERIOD, RETENTION_PERIOD_UNITS_DESC<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">FROM sys.change_tracking_databases<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">GO<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; margin: 0in;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><img decoding=\"async\" style=\"border-style: none;\" alt=\"\" src=\"http:\/\/hi.csdn.net\/attachment\/201102\/9\/0_1297262398BQnB.gif\" \/><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">5.<\/span><span lang=\"zh-CN\">\u521b\u5efa\u6d4b\u8bd5\u8868<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">USE CHANGE_TRACK_DB<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">GO<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">CREATE TABLE CHANGE_TRACKING_USER<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">(USERID\u00a0\u00a0INT NOT NULL PRIMARY KEY\u00a0\u00a0IDENTITY(1,1),<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">NAME VARCHAR(20) NOT NULL,<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">ADDRESS\u00a0\u00a0VARCHAR(100) NOT NULL)<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">GO<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u5bf9\u4e8e\u8981\u6253\u5f00\u66f4\u6539\u8ddf\u8e2a\u4ee5\u53ca\u8981\u8ddf\u8e2a\u54ea\u4e9b\u5217\u88ab\u8ddf\u65b0\u4e86\u7684\u8868,\u9700\u8981\u6253\u5f00\u8868\u7684CHANGE_TRACKING\u9009\u9879\u548cTRACK_COLUMNS_UPDATED\u9009\u9879.<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">ALTER TABLE CHANGE_TRACKING_USER<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">ENABLE CHANGE_TRACKING<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">WITH (TRACK_COLUMNS_UPDATED= ON)<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">6.<\/span><span lang=\"zh-CN\">\u67e5\u8be2sys.change_tracking_tables\u76ee\u5f55\u89c6\u56fe\u53ef\u4ee5\u83b7\u5f97\u542f\u7528\u8ddf\u8e2a\u66f4\u6539\u7684\u8be6\u7ec6\u4fe1\u606f.<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SELECT OBJECT_NAME(OBJECT_ID) AS [TB_NAME], IS_TRACK_COLUMNS_UPDATED_ON<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">FROM sys.change_tracking_tables<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">GO<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; margin: 0in;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><img decoding=\"async\" style=\"border-style: none;\" alt=\"\" src=\"http:\/\/hi.csdn.net\/attachment\/201102\/9\/0_1297262402oJ00.gif\" \/><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">7.<\/span><span lang=\"zh-CN\">\u5bf9\u8868\u8fdb\u884c\u63d2\u5165\u6570\u636e\u6765\u6355\u83b7\u66f4\u6539\u8ddf\u8e2a.<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">INSERT CHANGE_TRACKING_USER(NAME, ADDRESS)<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">VALUES(&#8216;Kobe&#8217;,&#8217;Lakers&#8217;),<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in 0in 0in 0.375in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">(&#8216;Jordon&#8217;, &#8216;Bull&#8217;),<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in 0in 0in 0.375in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">(&#8216;Wade&#8217;, &#8216;Heat&#8217;),<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in 0in 0in 0.375in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">(&#8216;Howard&#8217;, &#8216;Magic&#8217;)<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">GO<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">8.<\/span><span lang=\"zh-CN\">\u67e5\u770b\u6b63\u5728\u540c\u6b65\u7684\u662f\u4e00\u4e2a\u51fd\u6570CHANGE_TRACKING_CURRENT_VERSION(),\u8fd4\u56de\u7684\u662f\u6700\u540e\u63d0\u4ea4\u7684\u4e8b\u52a1\u7684\u7248\u672c\u53f7.\u6240\u6709\u53d1\u751f\u5728\u542f\u7528\u66f4\u6539\u8ddf\u8e2a\u8868\u4e2d\u7684DML\u64cd\u4f5c\u90fd\u4f1a\u7167\u6210\u7248\u672c\u53f7\u7684\u589e\u957f.\u7248\u672c\u53f7\u7528\u6765\u786e\u5b9a\u66f4\u6539.<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SELECT CHANGE_TRACKING_CURRENT_VERSION()<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; margin: 0in;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><img decoding=\"async\" style=\"border-style: none;\" alt=\"\" src=\"http:\/\/hi.csdn.net\/attachment\/201102\/9\/0_12972624079J4b.gif\" \/><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">9.<\/span><span lang=\"zh-CN\">\u51fd\u6570CHANGE_TRACKING_MIN_VALID_VERSION()\u53ef\u4ee5\u83b7\u5f97\u8868\u7684\u6700\u5c0f\u53ef\u7528\u7248\u672c\u53f7.\u5982\u679c\u65ad\u5f00\u8fde\u63a5\u7684\u7a0b\u5e8f\u4e0d\u540c\u6b65\u7684\u65f6\u95f4\u8d85\u8fc7\u4e86\u66f4\u6539\u8ddf\u8e2a\u4fdd\u7559\u671f\u9650.\u90a3\u4e48\u5c31\u8981\u5bf9\u5e94\u7528\u7a0b\u5e8f\u7684\u6570\u636e\u8fdb\u884c\u5f7b\u5e95\u7684\u5237\u65b0.<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SELECT CHANGE_TRACKING_MIN_VALID_VERSION(OBJECT_ID(&#8216;CHANGE_TRACKING_USER&#8217;))<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; margin: 0in;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><img decoding=\"async\" style=\"border-style: none;\" alt=\"\" src=\"http:\/\/hi.csdn.net\/attachment\/201102\/9\/0_1297262414o2Ex.gif\" \/><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">10.<\/span><span lang=\"zh-CN\">\u5bf9\u4e8e\u66f4\u6539\u7684\u4fa6\u6d4b\u6211\u4eec\u53ef\u4ee5\u7528\u51fd\u6570CHANGETABLE.\u8be5\u51fd\u6570\u6709\u79cd\u7528\u6cd5:\u4f7f\u7528CHANGES\u5173\u952e\u5b57\u6765\u68c0\u6d4b\u4ece\u6307\u5b9a\u7684\u540c\u6b65\u7248\u672c\u4ee5\u6765\u53d1\u751f\u7684\u66f4\u6539;\u6216\u8005\u4f7f\u7528VERSION\u5173\u952e\u5b57\u6765\u8fd4\u56de\u6700\u65b0\u7684\u66f4\u6539\u8ddf\u8e2a\u7248\u672c.<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"zh-CN\">SELECT USERID\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span lang=\"en-US\">\u00a0\u00a0\u00a0<\/span><span lang=\"zh-CN\">&#8211;\u8fd4\u56de\u7684\u662f\u4e3b\u952e<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in 0in 0in 0.375in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">,SYS_CHANGE_OPERATION\u00a0\u00a0\u00a0\u00a0&#8211;I \u4ee3\u8868INSERT, U\u4ee3\u8868UPDATE, D\u4ee3\u8868DELETE<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in 0in 0in 0.375in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">,SYS_CHANGE_VERSION\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8211;\u8fd4\u56de\u7684\u662f\u7248\u672c\u53f7,\u56e0\u4e3a\u8fd9\u6761\u6570\u636e\u662f\u5728\u540c\u4e00\u4e2aINSERT\u4e2d\u6dfb\u52a0\u7684,\u6240\u4ee5\u4e0b\u9762\u7684\u7ed3\u679c\u7248\u672c\u53f7\u76f8\u540c\u00a0\u00a0<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">FROM CHANGETABLE(CHANGES CHANGE_TRACKING_USER, 0) A &#8212; \u6b64\u51fd\u6570\u8fd4\u56de\u7684\u662f\u81ea\u7248\u672c\u4ee5\u6765\u7684\u66f4\u6539.\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u8868\u540d\u79f0<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; margin: 0in;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><img decoding=\"async\" style=\"border-style: none;\" alt=\"\" src=\"http:\/\/hi.csdn.net\/attachment\/201102\/9\/0_12972624196kwv.gif\" \/><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"zh-CN\">1<\/span><span lang=\"en-US\">1.<\/span><span lang=\"zh-CN\">\u5f53\u6536\u96c6\u540c\u6b65\u4fe1\u606f\u65f6,\u4f7f\u7528SET TRANSACTION ISOLATION LEVEL SNAPSHOT \u548cBEGIN TRAN..COMMIT TRAN\u6765\u5c01\u88c5\u6536\u96c6\u7684\u66f4\u6539\u4fe1\u606f\u548c\u76f8\u5173\u7684\u5f53\u524d\u66f4\u6539\u8ddf\u8e2a\u7248\u672c\u4ee5\u53ca\u6700\u5c0f\u7684\u53ef\u7528\u7248\u672c.\u4f7f\u7528\u5feb\u7167\u9694\u79bb\u5141\u8bb8\u66f4\u6539\u8ddf\u8e2a\u7684\u6570\u636e\u5177\u6709\u4e8b\u52a1\u4e00\u81f4\u6027\u7684\u5f62\u5f0f.<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">UPDATE CHANGE_TRACKING_USER<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SET NAME = &#8216;Kobe Bryant&#8217;<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">WHERE USERID = 1<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">UPDATE CHANGE_TRACKING_USER<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SET ADDRESS = &#8216;Lakers&#8217;<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">WHERE USERID = 4<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">DELETE FROM CHANGE_TRACKING_USER WHERE USERID = 2<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">&#8211;\u68c0\u67e5\u6700\u65b0\u7684\u7248\u672c\u53f7<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SELECT CHANGE_TRACKING_CURRENT_VERSION()<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; margin: 0in;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><img decoding=\"async\" style=\"border-style: none;\" alt=\"\" src=\"http:\/\/hi.csdn.net\/attachment\/201102\/9\/0_1297262424ZTTF.gif\" \/><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">12.<\/span><span lang=\"zh-CN\">\u5f53\u7a0b\u5e8f\u6536\u96c6\u4e86\u81ea\u6570\u636e\u7248\u672c\u540e\u7684\u6570\u636e.\u4e0b\u9762\u53ef\u4ee5\u68c0\u6d4b\u81ea\u7248\u672c\u8d77\u53d1\u751f\u7684\u6240\u6709\u66f4\u6539<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SELECT USERID, SYS_CHANGE_VERSION, SYS_CHANGE_OPERATION, SYS_CHANGE_COLUMNS<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">FROM CHANGETABLE(CHANGES CHANGE_TRACKING_USER, 1) AS T<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; margin: 0in;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><img decoding=\"async\" style=\"border-style: none;\" alt=\"\" src=\"http:\/\/hi.csdn.net\/attachment\/201102\/9\/0_1297262567rmmK.gif\" \/><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SYS_CHANGE_COLUMNS\u5217\u5f0f\u5305\u542b\u4ece\u6700\u65b0\u7248\u672c\u5f00\u59cb\u66f4\u65b0\u8fc7\u7684\u5217\u7684VARBINARY\u503c,\u53ef\u4ee5\u4f7f\u7528CHANGE_TRACKING_IS_COLUMN_IN_MASK\u51fd\u6570\u6765\u89e3\u91ca\u5b83.\u8be5\u51fd\u6570\u63a5\u53d7\u4e2a\u53c2\u6570:\u8868\u7684\u5217ID\u548cVARBINARY\u503c.<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">13.<\/span><span lang=\"zh-CN\">\u4e0b\u9762\u4f7f\u7528\u8fd9\u4e2a\u51fd\u6570\u6765\u68c0\u67e5NAME\u5217\u548cADDRESS\u5217\u662f\u5426\u88ab\u4fee\u6539\u8fc7.<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SELECT USERID,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8211;\u8be5\u51fd\u6570\u8fd4\u56de\u5bf9\u5e94\u7684\u5217ID<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">CHANGE_TRACKING_IS_COLUMN_IN_MASK(COLUMNPROPERTY(OBJECT_ID(&#8216;CHANGE_TRACKING_USER&#8217;),&#8217;NAME&#8217;,&#8217;COLUMNID&#8217;),<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in 0in 0in 0.375in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SYS_CHANGE_COLUMNS) NAME_IS_CHANGED,CHANGE_TRACKING_IS_COLUMN_IN_MASK(<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in 0in 0in 0.375in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">COLUMNPROPERTY(OBJECT_ID(&#8216;CHANGE_TRACKING_USER&#8217;),&#8217;ADDRESS&#8217;,&#8217;COLUMNID&#8217;)<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">,SYS_CHANGE_COLUMNS) ADDRESS_IS_CHANGED<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">FROM CHANGETABLE(CHANGES CHANGE_TRACKING_USER,1) AS T<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">WHERE SYS_CHANGE_OPERATION = &#8216;U&#8217;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8211;\u786e\u5b9a\u4fee\u6539\u7684\u5217<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; margin: 0in;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><img decoding=\"async\" style=\"border-style: none;\" alt=\"\" src=\"http:\/\/hi.csdn.net\/attachment\/201102\/9\/0_1297262573QUBx.gif\" \/><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">14.<\/span><span lang=\"zh-CN\">CHANGETABLE \u901a\u8fc7VERSION \u53c2\u6570\u6765\u8fd4\u56de\u6700\u65b0\u7684\u7248\u672c.<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SELECT A.USERID, NAME, ADDRESS, SYS_CHANGE_VERSION<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">FROM CHANGE_TRACKING_USER A<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">CROSS APPLY CHANGETABLE(VERSION CHANGE_TRACKING_USER, (USERID), (A.USERID)) T<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; margin: 0in;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><img decoding=\"async\" style=\"border-style: none;\" alt=\"\" src=\"http:\/\/hi.csdn.net\/attachment\/201102\/9\/0_1297262577z10N.gif\" \/><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"zh-CN\">1<\/span><span lang=\"en-US\">5.<\/span><span lang=\"zh-CN\">\u4e0b\u9762\u518d\u6f14\u793a\u4e00\u4e2aUPDATE\u6765\u6f14\u793a\u7248\u672c\u7684\u4e0d\u540c.<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">UPDATE CHANGE_TRACKING_USER<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SET ADDRESS = &#8216;MIAMI HEAT&#8217;<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">WHERE USERID = 3<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SELECT CHANGE_TRACKING_CURRENT_VERSION() &#8211;\u68c0\u67e5\u6700\u65b0\u7684\u7248\u672c\u53f7<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; margin: 0in;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><img decoding=\"async\" style=\"border-style: none;\" alt=\"\" src=\"http:\/\/hi.csdn.net\/attachment\/201102\/9\/0_1297262581GpU7.gif\" \/><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SELECT A.USERID, NAME, ADDRESS, SYS_CHANGE_VERSION<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">FROM CHANGE_TRACKING_USER A<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">CROSS APPLY CHANGETABLE(VERSION CHANGE_TRACKING_USER, (USERID), (A.USERID)) T<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; margin: 0in;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><img decoding=\"async\" style=\"border-style: none;\" alt=\"\" src=\"http:\/\/hi.csdn.net\/attachment\/201102\/9\/0_12972625866zSN.gif\" \/><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"zh-CN\">\u53ef\u4ee5\u770b\u5230USERID=3\u7684\u7248\u672c\u53f7\u4e3a<\/span><span lang=\"en-US\">5<\/span><span lang=\"zh-CN\">,\u8fd9\u662f\u56e0\u4e3a\u7248\u672c\u53f7\u662f\u4e00\u81f4\u9012\u589e\u7684<\/span><span lang=\"en-US\">(<\/span><span lang=\"zh-CN\">\u7b2c<\/span><span lang=\"en-US\">11<\/span><span lang=\"zh-CN\">\u6b65\u7248\u672c\u53f7\u5df2\u7ecf\u5230<\/span><span lang=\"en-US\">4),<\/span><span lang=\"zh-CN\">\u6240\u4ee5\u73b0\u5728\u6700\u65b0\u7684\u7248\u672c\u53f7\u4f4d.\u6ca1\u6709\u4fee\u6539\u7684\u884c\u7248\u672c\u53f7\u4e0d\u53d8.<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">16.<\/span><span lang=\"zh-CN\">\u6700\u540e\u6d4b\u8bd5\u5982\u4f55\u901a\u8fc7DML\u64cd\u4f5c\u63d0\u4f9b\u66f4\u6539\u8ddf\u8e2a\u5e94\u7528\u7a0b\u5e8f\u4e0a\u4e0b\u6587\u4fe1\u606f,\u53ef\u4ee5\u786e\u5b9a\u662f\u54ea\u4e00\u5e94\u7528\u7a0b\u5e8f\u5bf9\u90a3\u4e9b\u884c\u8fdb\u884c\u4e86\u6570\u636e\u4fee\u6539.\u5b83\u7684\u4f5c\u7528\u662f\u5982\u679c\u6709\u591a\u4e2a\u5e94\u7528\u7a0b\u5e8f\u5bf9\u6570\u636e\u6e90\u8fdb\u884c\u6570\u636e\u540c\u6b65,\u8fd9\u5c06\u4f1a\u662f\u6709\u7528\u7684\u4fe1\u606f.\u4f7f\u7528CHANGE_TRACKING_CONTEXT\u51fd\u6570\u6765\u67e5\u8be2,\u51fd\u6570\u53ea\u6709\u4e00\u4e2a\u8f93\u5165\u53c2\u6570CONTEXT,\u5b83\u662fVARBINARY\u6570\u636e\u7c7b\u578b.<\/span><\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u9996\u5148\u8981\u4fdd\u5b58\u4e0a\u4e0b\u6587\u4fe1\u606f\u7684\u53d8\u91cf,\u7136\u540e\u5728CHANGE_TRACKING_CONTEXT\u51fd\u6570\u4e2d\u4f7f\u7528\u53d8\u91cf,\u518d\u5411\u66f4\u6539\u8ddf\u8e2a\u8868\u4e2d\u63d2\u5165\u4e00\u6761\u65b0\u884c<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">DECLARE @CONTEXT VARBINARY(128) = CAST(&#8216;DS_ALEX&#8217; AS VARBINARY(128));<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">WITH CHANGE_TRACKING_CONTEXT(@CONTEXT)<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">INSERT CHANGE_TRACKING_USER(NAME,ADDRESS)<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">VALUES(&#8216;James&#8217;, &#8216;Heat&#8217;)<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">&#8211;\u73b0\u5728\u67e5\u8be2\u4ece\u7248\u672c\u53d1\u751f\u7684\u6240\u6709\u66f4\u6539.<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SELECT USERID, SYS_CHANGE_OPERATION, SYS_CHANGE_VERSION, CAST(SYS_CHANGE_CONTEXT AS VARCHAR(50)) AppContext<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">FROM CHANGETABLE(CHANGES CHANGE_TRACKING_USER, 5) AS T<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; margin: 0in;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><img decoding=\"async\" style=\"border-style: none;\" alt=\"\" src=\"http:\/\/hi.csdn.net\/attachment\/201102\/9\/0_12972625919r9s.gif\" \/><\/span><\/span><\/p>\n<p style=\"color: #333333; font-style: normal; font-variant: normal; margin: 0in; font-family: 'Courier New'; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u4ee5\u4e0a\u4e3b\u8981\u6d89\u53ca\u4e86\u5efa\u5e93\u5efa\u8868,<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">ALTER DATABASE &#8230;.ENABLE CHANGE_TRACKING. \u542f\u7528\u6570\u636e\u5e93\u66f4\u6539\u8ddf\u8e2a<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">CHANGE_RETENTION \u548cAUTO_CLEANUP \u6307\u5b9a\u66f4\u6539\u8ddf\u8e2a\u4fdd\u7559\u671f\u9650\u548c\u81ea\u52a8\u6e05\u9664.<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u67e5\u8be2SYS.CHANGE_TRACKING_DATABASES\u76ee\u5f55\u89c6\u56fe\u68c0\u67e5\u6570\u636e\u5e93\u66f4\u6539\u8ddf\u8e2a\u7684\u72b6\u6001.<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">ALTER TABLE &#8230;ENABLE CHANGE_TRACKING<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">TRACK_COLUMNS_UPDATED \u6307\u5b9a\u5217\u7ea7\u522b\u66f4\u6539\u4e5f\u4f1a\u88ab\u8ddf\u8e2a.<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">SYS.CHANGE_TRACKING_TABLES\u76ee\u5f55\u89c6\u56fe\u786e\u8ba4\u8868\u7684\u66f4\u6539\u8ddf\u8e2a\u72b6\u6001<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u4e00\u4e9b\u68c0\u6d4b\u66f4\u6539\u8ddf\u8e2a\u6570\u636e\u7684\u4e0d\u540c\u51fd\u6570:<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">CHANGE_TRACKING_CURRENT_VERSION() \u8fd4\u56de\u6700\u540e\u63d0\u4ea4\u7684\u4e8b\u52a1\u7248\u672c\u53f7<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">CHANGE_TRACKING_MIN_VALID_VERSION() \u8fd4\u56de\u66f4\u6539\u8ddf\u8e2a\u8868\u7684\u6700\u5c0f\u53ef\u7528\u7248\u672c\u53f7<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">CHANGETABLE:VERSION \u8fd4\u56de\u6700\u65b0\u7684\u66f4\u6539\u7248\u672c<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">CHANGES \u68c0\u6d4b\u81ea\u6307\u5b9a\u540c\u6b65\u7248\u672c\u4ee5\u6765\u7684\u66f4\u6539<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">CHANGE_TRACKING_IS_COLUMN_IN_MASK \u68c0\u6d4b\u66f4\u6539\u8ddf\u8e2a\u8868\u4e2d\u90a3\u4e9b\u5217\u88ab\u66f4\u65b0<\/span><\/span><\/p>\n<p style=\"color: #333333; font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">CHANGE_TRACKING_CONTEXT \u901a\u8fc7DML\u64cd\u4f5c\u5b58\u50a8\u66f4\u6539\u4e0a\u4e0b\u6587,\u4ece\u800c\u53ef\u4ee5\u8ddf\u8e2a\u54ea\u4e00\u5e94\u7528\u7a0b\u5e8f\u4fee\u6539\u4e86\u4ec0\u4e48\u6570\u636e.<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0eSQL SERVER 2008 CDC \u5f02\u6b65\u6355\u83b7\u6570\u636e\u53d8\u66f4\u7684\u4e0d\u540c,\u66f4\u6539\u8ddf\u8e2a\u662f\u540c\u6b65\u8fdb\u7a0b,\u662fDML(INSERT\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[16],"class_list":["post-181","post","type-post","status-publish","format-standard","hentry","category-sqlserver","tag-sql_server_2008_r2"],"_links":{"self":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts\/181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=181"}],"version-history":[{"count":0,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts\/181\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}