{"id":215,"date":"2011-03-24T10:46:25","date_gmt":"2011-03-24T02:46:25","guid":{"rendered":"http:\/\/www.royalwzy.com\/?p=215"},"modified":"2013-12-30T13:59:31","modified_gmt":"2013-12-30T05:59:31","slug":"%e6%b8%85%e7%a9%ba%e6%95%b0%e6%8d%ae%e5%ba%93%e4%b8%ad%e6%89%80%e6%9c%89%e8%a1%a8%e6%95%b0%e6%8d%ae%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.royalwzy.com\/?p=215","title":{"rendered":"\u6e05\u7a7a\u6570\u636e\u5e93\u4e2d\u6240\u6709\u8868\u6570\u636e\u7684\u65b9\u6cd5"},"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;\">\u5176\u5b9e\u5220\u9664\u6570\u636e\u5e93\u4e2d\u6570\u636e\u7684\u65b9\u6cd5\u5e76\u4e0d\u590d\u6742\uff0c\u4e3a\u4ec0\u4e48\u6211\u8fd8\u8981\u591a\u6b64\u4e00\u4e3e\u5462\uff0c\u4e00\u662f\u6211\u8fd9\u91cc\u4ecb\u7ecd\u7684\u662f\u5220\u9664\u6570\u636e\u5e93\u7684\u6240\u6709\u6570\u636e\uff0c\u56e0\u4e3a\u6570\u636e\u4e4b\u95f4\u53ef\u80fd\u5f62\u6210\u76f8\u4e92\u7ea6\u675f\u5173\u7cfb\uff0c\u5220\u9664\u64cd\u4f5c\u53ef\u80fd\u9677\u5165\u6b7b\u5faa\u73af\uff0c\u4e8c\u662f\u8fd9\u91cc\u4f7f\u7528\u4e86\u5fae\u8f6f\u672a\u6b63\u5f0f\u516c\u5f00\u7684<span style=\"color: red;\">sp_MSForEachTable<\/span>\u5b58\u50a8\u8fc7\u7a0b\u3002<\/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;\">\u4e5f\u8bb8\u5f88\u591a\u8bfb\u8005\u670b\u53cb\u90fd\u7ecf\u5386\u8fc7\u8fd9\u6837\u7684\u4e8b\u60c5\uff1a\u8981\u5728\u5f00\u53d1\u6570\u636e\u5e93\u57fa\u7840\u4e0a\u6e05\u7406\u4e00\u4e2a\u7a7a\u5e93\uff0c\u4f46\u7531\u4e8e\u5bf9\u6570\u636e\u5e93\u7ed3\u6784\u7f3a\u4e4f\u6574\u4f53\u4e86\u89e3\uff0c\u5728\u5220\u9664\u4e00\u4e2a\u8868\u7684\u8bb0\u5f55\u65f6\uff0c\u5220\u9664\u4e0d\u4e86\uff0c\u56e0\u4e3a\u53ef\u80fd\u6709\u5916\u952e\u7ea6\u675f\uff0c\u4e00\u4e2a\u5e38\u89c1\u7684\u6570\u636e\u5e93\u7ed3\u6784\u662f\u4e00\u4e2a\u4e3b\u8868\uff0c\u4e00\u4e2a\u5b50\u8868\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\u4e00\u822c\u90fd\u5f97\u5148\u5220\u9664\u5b50\u8868\u8bb0\u5f55\uff0c\u518d\u5220\u9664\u4e3b\u8868\u8bb0\u5f55\u3002<\/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;\">\u8bf4\u9053\u5220\u9664\u6570\u636e\u8bb0\u5f55\uff0c\u5f80\u5f80\u9a6c\u4e0a\u4f1a\u60f3\u5230\u7684\u662fdelete\u548ctruncate\u8bed\u53e5\uff0c\u4f46\u5728\u9047\u5230\u5728\u4e24\u4e2a\u6216\u591a\u4e2a\u8868\u4e4b\u95f4\u5b58\u5728\u7ea6\u675f\u7684\u8bdd\uff0c\u8fd9\u4e24\u4e2a\u8bed\u53e5\u53ef\u80fd\u90fd\u4f1a\u5931\u6548\uff0c\u800c\u4e14\u6700\u8981\u547d\u7684\u662f\u8fd9\u4e24\u4e2a\u547d\u4ee4\u90fd\u53ea\u80fd\u4e00\u6b21\u64cd\u4f5c\u4e00\u4e2a\u8868\u3002\u90a3\u4e48\u771f\u6b63\u9047\u5230\u8981\u5220\u9664SQL Server\u6570\u636e\u5e93\u4e2d\u6240\u6709\u8bb0\u5f55\u65f6\uff0c\u8be5\u600e\u4e48\u529e\u5462\uff1f\u6709\u4e24\u4e2a\u9009\u62e9\uff1a<\/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;\">1.\u6309\u7167\u5148\u540e\u987a\u5e8f\u9010\u4e2a\u5220\u9664\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u5728\u8868\u975e\u5e38\u591a\u7684\u60c5\u51b5\u4e0b\u663e\u5f97\u5f88\u4e0d\u73b0\u5b9e\uff0c\u5373\u4fbf\u662f\u8868\u6570\u91cf\u4e0d\u591a\uff0c\u4f46\u7ea6\u675f\u6bd4\u8f83\u591a\u65f6\uff0c\u4f60\u8fd8\u662f\u8981\u82b1\u8d39\u5927\u91cf\u7684\u65f6\u95f4\u548c\u7cbe\u529b\u53bb\u7814\u7a76\u5176\u95f4\u7684\u7ea6\u675f\u5173\u7cfb\uff0c\u7136\u540e\u627e\u51fa\u5148\u5220\u54ea\u4e2a\u8868\uff0c\u518d\u5220\u54ea\u4e2a\u8868\uff0c\u6700\u540e\u53c8\u5220\u54ea\u4e2a\u8868\u3002<\/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;\">2.\u7981\u7528\u6240\u6709\u7ea6\u675f\uff0c\u5220\u9664\u6240\u6709\u6570\u636e\uff0c\u6700\u540e\u518d\u542f\u7528\u7ea6\u675f\uff0c\u8fd9\u6837\u5c31\u4e0d\u7528\u82b1\u65f6\u95f4\u548c\u7cbe\u529b\u53bb\u7814\u7a76\u4ec0\u4e48\u7ea6\u675f\u4e86\uff0c\u53ea\u9700\u8981\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u5b58\u50a8\u8fc7\u7a0b\u5c31\u53ef\u4ee5\u81ea\u52a8\u5b8c\u6210\u8fd9\u4e2a\u4efb\u52a1\u3002<\/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;\">\u4ece\u8fd9\u4e24\u4e2a\u9009\u62e9\u4e2d\u4e0d\u96be\u770b\u51fa\u7b2c\u4e8c\u4e2a\u9009\u62e9\u662f\u6700\u7b80\u5355\u6709\u6548\u7684\u4e86\uff0c\u90a3\u4e48\u5728\u4f7f\u7528\u7b2c\u4e8c\u4e2a\u9009\u62e9\u65f6\uff0c\u5177\u4f53\u8be5\u600e\u4e48\u5b9e\u65bd\u5462\uff1f<\/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\u5f97\u7f16\u5199\u4ee3\u7801\u5faa\u73af\u68c0\u67e5\u6240\u6709\u7684\u8868\uff0c\u8fd9\u91cc\u6211\u63a8\u8350\u4e00\u4e2a\u5b58\u50a8\u8fc7\u7a0bsp_MSForEachTable\uff0c\u56e0\u4e3a\u5728\u5fae\u8f6f\u7684\u5b98\u65b9\u6587\u6863\u4e2d\u6ca1\u6709\u5bf9\u8fd9\u4e2a\u5b58\u50a8\u8fc7\u7a0b\u6709\u63cf\u8ff0\uff0c\u5f88\u591a\u5f00\u53d1\u4eba\u5458\u4e5f\u8bb8\u90fd\u8fd8\u672a\u66fe\u542c\u8bf4\uff0c\u6240\u4ee5\u4f60\u5728\u4e92\u8054\u7f51\u4e0a\u641c\u7d22\u5f97\u5230\u7684\u89e3\u51b3\u529e\u6cd5\u5927\u591a\u5f88\u590d\u6742\uff0c\u4e5f\u8bb8\u6709\u7684\u4eba\u4f1a\u8ba4\u4e3a\uff0c\u65e2\u7136\u6ca1\u6709\u5b98\u65b9\u6587\u6863\uff0c\u8fd9\u4e2a\u5b58\u50a8\u8fc7\u7a0b\u53ef\u80fd\u4f1a\u4e0d\u7a33\u5b9a\uff0c\u6253\u5fc3\u7406\u4e0a\u4f1a\u6392\u65a5\u5b83\uff0c\u4f46\u4e8b\u5b9e\u5e76\u975e\u5982\u6b64\u3002\u4e0b\u9762\u6765\u5148\u770b\u4e00\u4e2a\u5b8c\u6574\u7684\u811a\u672c\uff1a<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: red; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">CREATE PROCEDURE sp_DeleteAllData<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: red; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">AS<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: red; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">EXEC sp_MSForEachTable &#8216;ALTER TABLE ? NOCHECK CONSTRAINT ALL&#8217;<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: red; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">EXEC sp_MSForEachTable &#8216;ALTER TABLE ? DISABLE TRIGGER ALL&#8217;<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: red; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">EXEC sp_MSForEachTable &#8216;DELETE FROM ?&#8217;<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: red; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"zh-CN\">EXEC sp_MSForEachTable &#8216;TRUNCATE TABLE ?&#8217;<\/span><span lang=\"en-US\">\u00a0&#8212;\u00a0<\/span><span lang=\"zh-CN\">\u622a\u65ad\u8868<\/span><span lang=\"en-US\">,<\/span><span lang=\"zh-CN\">\u6bd4\u8f83\u5feb<\/span><\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: red; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">EXEC sp_MSForEachTable &#8216;ALTER TABLE ? CHECK CONSTRAINT ALL&#8217;<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: red; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">EXEC sp_MSForEachTable &#8216;ALTER TABLE ? ENABLE TRIGGER ALL&#8217;<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: red; font-size: 9pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">EXEC sp_MSForEachTable &#8216;SELECT * FROM ?&#8217;<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: red; 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;\">\u8fd9\u4e2a\u811a\u672c\u521b\u5efa\u4e86\u4e00\u4e2a\u547d\u540d\u4e3asp_DeleteAllData\u7684\u5b58\u50a8\u8fc7\u7a0b\uff0c\u524d\u9762\u4e24\u884c\u8bed\u53e5\u5206\u522b\u7981\u7528\u7ea6\u675f\u548c\u89e6\u53d1\u5668\uff0c\u7b2c\u4e09\u6761\u8bed\u53e5\u624d\u662f\u771f\u6b63\u5730\u5220\u9664\u6240\u6709\u6570\u636e\uff0c\u63a5\u4e0b\u91cc\u7684\u8bed\u53e5\u5206\u522b\u8fd8\u539f\u7ea6\u675f\u548c\u89e6\u53d1\u5668\uff0c\u6700\u540e\u4e00\u6761\u8bed\u53e5\u662f\u663e\u793a\u6bcf\u4e2a\u8868\u4e2d\u7684\u8bb0\u5f55\uff0c\u5f53\u7136\u8fd9\u6761\u8bed\u53e5\u4e5f\u53ef\u4ee5\u4e0d\u8981\uff0c\u6211\u53ea\u662f\u60f3\u786e\u8ba4\u4e00\u4e0b\u662f\u5426\u6e05\u7a7a\u4e86\u6240\u6709\u8868\u800c\u5df2\u3002<\/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;\">\u4f60\u53ef\u4ee5\u5728\u4efb\u4f55\u6570\u636e\u5e93\u4e0a\u8fd0\u884c\u8fd9\u4e2a\u5b58\u50a8\u8fc7\u7a0b\uff0c\u5f53\u7136\u4e0d\u8981\u5728\u751f\u6210\u6570\u636e\u5e93\u4e0a\u8fd0\u884c\uff0c\u53ef\u522b\u602a\u6211\u6ca1\u544a\u8bc9\u4f60\uff01\u4e0d\u7ba1\u600e\u6837\uff0c\u8fd8\u662f\u5148\u5907\u4efd\u4e00\u4e0b\u6570\u636e\u5e93\uff0c\u4f7f\u7528\u5907\u4efd\u6570\u636e\u5e93\u8fd8\u539f\uff0c\u7136\u540e\u518d\u8fd0\u884c\u8be5\u5b58\u50a8\u8fc7\u7a0b\uff0c\u5475\u5475\uff0c\u5373\u4f7f\u662f\u4e00\u4e2a\u5927\u578b\u6570\u636e\u5e93\uff0c\u4e5f\u8981\u4e0d\u591a\u957f\u65f6\u95f4\uff0c\u4f60\u7684\u6570\u636e\u5e93\u5c31\u6210\u4e00\u4e2a\u7a7a\u5e93\u4e86\u3002<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5176\u5b9e\u5220\u9664\u6570\u636e\u5e93\u4e2d\u6570\u636e\u7684\u65b9\u6cd5\u5e76\u4e0d\u590d\u6742\uff0c\u4e3a\u4ec0\u4e48\u6211\u8fd8\u8981\u591a\u6b64\u4e00\u4e3e\u5462\uff0c\u4e00\u662f\u6211\u8fd9\u91cc\u4ecb\u7ecd\u7684\u662f\u5220\u9664\u6570\u636e\u5e93\u7684\u6240\u6709\u6570\u636e\uff0c\u56e0\u4e3a\u6570\u636e\u4e4b [&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-215","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\/215","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=215"}],"version-history":[{"count":0,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts\/215\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=215"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}