﻿{"id":514,"date":"2009-12-16T01:00:00","date_gmt":"2009-12-15T17:00:00","guid":{"rendered":"http:\/\/blog.jixin.ntxz.net\/?p=514"},"modified":"2010-07-30T15:40:54","modified_gmt":"2010-07-30T07:40:54","slug":"sql%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b%e5%ad%a6%e4%b9%a0","status":"publish","type":"post","link":"http:\/\/www.ntxz.net\/?p=514","title":{"rendered":"SQL\u5b58\u50a8\u8fc7\u7a0b\u5b66\u4e60"},"content":{"rendered":"<p><strong><font size=2>\u4e00\u3001SQL\u5b58\u50a8\u8fc7\u7a0b\u7684\u6982\u5ff5\uff0c\u4f18\u70b9\u53ca\u8bed\u6cd5<\/font><\/strong> <\/p>\n<p><font size=2>\u3000\u3000\u6574\u7406\u5728\u5b66\u4e60\u7a0b\u5e8f\u8fc7\u7a0b\u4e4b\u524d\uff0c\u5148\u4e86\u89e3\u4e0b\u4ec0\u4e48\u662f\u5b58\u50a8\u8fc7\u7a0b?\u4e3a\u4ec0\u4e48\u8981\u7528\u5b58\u50a8\u8fc7\u7a0b\uff0c\u4ed6\u6709\u90a3\u4e9b\u4f18\u70b9<\/font><\/p>\n<p><font size=2>\u3000\u3000<strong>\u5b9a\u4e49<\/strong>\uff1a\u5c06\u5e38\u7528\u7684\u6216\u5f88\u590d\u6742\u7684\u5de5\u4f5c\uff0c\u9884\u5148\u7528SQL\u8bed\u53e5\u5199\u597d\u5e76\u7528\u4e00\u4e2a\u6307\u5b9a\u7684\u540d\u79f0\u5b58\u50a8\u8d77\u6765, \u90a3\u4e48\u4ee5\u540e\u8981\u53eb\u6570\u636e\u5e93\u63d0\u4f9b\u4e0e\u5df2\u5b9a\u4e49\u597d\u7684\u5b58\u50a8\u8fc7\u7a0b\u7684\u529f\u80fd\u76f8\u540c\u7684\u670d\u52a1\u65f6,\u53ea\u9700\u8c03\u7528execute,\u5373\u53ef\u81ea\u52a8\u5b8c\u6210\u547d\u4ee4\u3002<\/font><\/p>\n<p><font size=2>\u3000\u3000\u8bb2\u5230\u8fd9\u91cc,\u53ef\u80fd\u6709\u4eba\u8981\u95ee\uff1a\u8fd9\u4e48\u8bf4\u5b58\u50a8\u8fc7\u7a0b\u5c31\u662f\u4e00\u5806SQL\u8bed\u53e5\u800c\u5df2\u554a? <\/font><font color=#16387c size=2>Microsoft<\/font><font size=2>\u516c\u53f8\u4e3a\u4ec0\u4e48\u8fd8\u8981\u6dfb\u52a0\u8fd9\u4e2a\u6280\u672f\u5462?<\/font><\/p>\n<p><font size=2>\u3000\u3000\u90a3\u4e48\u5b58\u50a8\u8fc7\u7a0b\u4e0e\u4e00\u822c\u7684SQL\u8bed\u53e5\u6709\u4ec0\u4e48\u533a\u522b\u5462?<\/font><\/p>\n<p><font size=2>\u3000\u3000<strong>\u5b58\u50a8\u8fc7\u7a0b\u7684\u4f18\u70b9\uff1a<\/strong><\/font><\/p>\n<p><font size=2>\u3000\u30001.\u5b58\u50a8\u8fc7\u7a0b\u53ea\u5728\u521b\u9020\u65f6\u8fdb\u884c\u7f16\u8bd1\uff0c\u4ee5\u540e\u6bcf\u6b21\u6267\u884c\u5b58\u50a8\u8fc7\u7a0b\u90fd\u4e0d\u9700\u518d\u91cd\u65b0\u7f16\u8bd1\uff0c\u800c\u4e00\u822cSQL\u8bed\u53e5\u6bcf\u6267\u884c\u4e00\u6b21\u5c31\u7f16\u8bd1\u4e00\u6b21,\u6240\u4ee5\u4f7f\u7528\u5b58\u50a8\u8fc7\u7a0b\u53ef\u63d0\u9ad8\u6570\u636e\u5e93\u6267\u884c\u901f\u5ea6\u3002<\/font><\/p>\n<p><font size=2>\u3000\u30002.\u5f53\u5bf9\u6570\u636e\u5e93\u8fdb\u884c\u590d\u6742***\u4f5c\u65f6(\u5982\u5bf9\u591a\u4e2a\u8868\u8fdb\u884cUpdate,Insert,<\/font><font color=#16387c size=2>Query<\/font><font size=2>,Delete\u65f6)\uff0c\u53ef\u5c06\u6b64\u590d\u6742***\u4f5c\u7528\u5b58\u50a8\u8fc7\u7a0b\u5c01\u88c5\u8d77\u6765\u4e0e\u6570\u636e\u5e93\u63d0\u4f9b\u7684\u4e8b\u52a1\u5904\u7406\u7ed3\u5408\u4e00\u8d77\u4f7f\u7528\u3002<\/font><\/p>\n<p><font size=2>\u3000\u30003.\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528,\u53ef\u51cf\u5c11\u6570\u636e\u5e93\u5f00\u53d1\u4eba\u5458\u7684\u5de5\u4f5c\u91cf<\/font><\/p>\n<p><font size=2>\u3000\u30004.\u5b89\u5168\u6027\u9ad8,\u53ef\u8bbe\u5b9a\u53ea\u6709\u67d0\u6b64\u7528\u6237\u624d\u5177\u6709\u5bf9\u6307\u5b9a\u5b58\u50a8\u8fc7\u7a0b\u7684\u4f7f\u7528\u6743<\/font><\/p>\n<p><font size=2>\u3000\u3000<strong>\u5b58\u50a8\u8fc7\u7a0b\u7684\u79cd\u7c7b\uff1a<\/strong><\/font><\/p>\n<p><font size=2>\u3000\u30001.\u7cfb\u7edf\u5b58\u50a8\u8fc7\u7a0b\uff1a\u4ee5sp_\u5f00\u5934,\u7528\u6765\u8fdb\u884c\u7cfb\u7edf\u7684\u5404\u9879\u8bbe\u5b9a.\u53d6\u5f97\u4fe1\u606f.\u76f8\u5173\u7ba1\u7406\u5de5\u4f5c,<\/font><\/p>\n<p><font size=2>\u3000\u3000\u5982 sp_help\u5c31\u662f\u53d6\u5f97\u6307\u5b9a\u5bf9\u8c61\u7684\u76f8\u5173\u4fe1\u606f<\/font><\/p>\n<p><font size=2>\u3000\u30002.\u6269\u5c55\u5b58\u50a8\u8fc7\u7a0b \u4ee5XP_\u5f00\u5934,\u7528\u6765\u8c03\u7528<\/font><font color=#16387c size=2>***\u4f5c\u7cfb\u7edf<\/font><font size=2>\u63d0\u4f9b\u7684\u529f\u80fd<\/font><\/p>\n<p><font size=2>\u3000\u3000\u4ee5\u4e0b\u4e3a\u5f15\u7528\u7684\u5185\u5bb9\uff1a<\/font><\/p>\n<p><font size=2>\u3000\u3000exec master..xp_cmdshell &#8216;<\/font><font color=#16387c size=2>ping<\/font><font size=2> 10.8.16.1&#8242;<\/font><\/p>\n<p><font size=2>\u3000\u30003.\u7528\u6237\u81ea\u5b9a\u4e49\u7684\u5b58\u50a8\u8fc7\u7a0b,\u8fd9\u662f\u6211\u4eec\u6240\u6307\u7684\u5b58\u50a8\u8fc7\u7a0b<\/font><\/p>\n<p><font size=2>\u3000\u3000\u5e38\u7528\u683c\u5f0f<\/font><\/p>\n<p><font size=2>\u3000\u3000\u4ee5\u4e0b\u4e3a\u5f15\u7528\u7684\u5185\u5bb9\uff1a<\/font><\/p>\n<p><font size=2>\u3000\u3000Create procedure procedue_name<\/font><\/p>\n<p><font size=2>\u3000\u3000[@<\/font><font color=#16387c size=2>parameter<\/font><font size=2> data_type][output]<\/font><\/p>\n<p><font size=2>\u3000\u3000[with]{recompile|<\/font><font color=#16387c size=2>encryption<\/font><font size=2>}<\/font><\/p>\n<p><font size=2>\u3000\u3000as<\/font><\/p>\n<p><font size=2>\u3000\u3000sql_statement<\/font><\/p>\n<p><strong><font size=2>\u89e3\u91ca:<\/font><\/strong><\/p>\n<p><font size=2>\u3000\u3000output\uff1a\u8868\u793a\u6b64\u53c2\u6570\u662f\u53ef\u4f20\u56de\u7684<\/font><\/p>\n<p><font size=2>\u3000\u3000with {recompile|encryption}<\/font><\/p>\n<p><font size=2>\u3000\u3000recompile:\u8868\u793a\u6bcf\u6b21\u6267\u884c\u6b64\u5b58\u50a8\u8fc7\u7a0b\u65f6\u90fd\u91cd\u65b0\u7f16\u8bd1\u4e00\u6b21<\/font><\/p>\n<p><font size=2>\u3000\u3000encryption:\u6240\u521b\u5efa\u7684\u5b58\u50a8\u8fc7\u7a0b\u7684\u5185\u5bb9\u4f1a\u88ab\u52a0\u5bc6<\/font><\/p>\n<p><font size=2>\u3000\u3000<strong>\u4e8c\u3001SQL\u5b58\u50a8\u8fc7\u7a0b\u5b66\u4e60\uff1a\u5b58\u50a8\u8fc7\u7a0b\u7684\u521b\u5efa<\/strong><\/font><\/p>\n<p><font size=2>\u3000\u3000\u8868book\u7684\u5185\u5bb9\u5982\u4e0b<\/font><\/p>\n<p><font size=2>\u3000\u3000\u7f16\u53f7\u3000\u3000\u3000\u3000\u3000\u4e66\u540d\u3000\u3000\u3000\u3000\u3000\u3000\u4ef7\u683c<\/font><\/p>\n<p><font size=2>\u3000\u3000001 \u3000\u3000\u3000C\u8bed\u8a00\u5165\u95e8\u3000\u3000\u3000\u3000\u3000$30<\/font><\/p>\n<p><font size=2>\u3000\u3000002 \u3000<\/font><font color=#16387c size=2>PowerBuilder<\/font><font size=2>\u62a5\u8868\u5f00\u53d1&nbsp; $52<\/font><\/p>\n<p><font size=2>\u3000\u3000<strong>\u5b9e\u4f8b1:\u67e5\u8be2\u8868Book\u7684\u5185\u5bb9\u7684\u5b58\u50a8\u8fc7\u7a0b<\/strong><\/font><\/p>\n<table style=\"BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted\" cellSpacing=0 cellPadding=6 width=\"95%\" align=center border=0>\n<tbody>\n<tr>\n<td style=\"WORD-WRAP: break-word\" bgColor=#f3f3f3><font size=2>\u3000\u3000create&nbsp;proc&nbsp;query_book <br \/>\u3000\u3000as <br \/>\u3000\u3000select&nbsp;*&nbsp;from&nbsp;book <br \/>\u3000\u3000go <br \/>\u3000\u3000exec&nbsp;query_book<\/font><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><font size=2>\u3000\u3000<strong>\u5b9e\u4f8b2:\u52a0\u5165\u4e00\u7b14\u8bb0\u5f55\u5230\u8868book,\u5e76\u67e5\u8be2\u6b64\u8868\u4e2d\u6240\u6709\u4e66\u7c4d\u7684\u603b\u91d1\u989d<\/strong><\/font><\/p>\n<table style=\"BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted\" cellSpacing=0 cellPadding=6 width=\"95%\" align=center border=0>\n<tbody>\n<tr>\n<td style=\"WORD-WRAP: break-word\" bgColor=#f3f3f3><font size=2>\u3000\u3000Create&nbsp;proc&nbsp;insert_book <br \/>\u3000\u3000@param1&nbsp;char(10),@param2&nbsp;varchar(20),@param3&nbsp;money,@param4&nbsp;money&nbsp;output <br \/>\u3000\u3000with&nbsp;encryption&nbsp;&#8212;&#8212;&#8212;\u52a0\u5bc6 <br \/>\u3000\u3000as <br \/>\u3000\u3000insert&nbsp;book(\u7f16\u53f7,\u4e66\u540d\uff0c\u4ef7\u683c)&nbsp;Values(@param1,@param2,@param3) <br \/>\u3000\u3000select&nbsp;@param4=<\/font><font color=#16387c size=2>sum<\/font><font size=2>(\u4ef7\u683c)&nbsp;from&nbsp;book <br \/>\u3000\u3000go<\/font><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong><font size=2>\u6267\u884c\u4f8b\u5b50:<\/font><\/strong> <\/p>\n<table style=\"BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted\" cellSpacing=0 cellPadding=6 width=\"95%\" align=center border=0>\n<tbody>\n<tr>\n<td style=\"WORD-WRAP: break-word\" bgColor=#f3f3f3><font size=2>\u3000\u3000declare&nbsp;@total_price&nbsp;money <br \/>\u3000\u3000exec&nbsp;insert_book&nbsp;&#8216;003&#8217;,&#8217;<\/font><font color=#16387c size=2>Delphi<\/font><font size=2>&nbsp;\u63a7\u4ef6\u5f00\u53d1\u6307\u5357&#8217;,$100,@total_price <br \/>\u3000\u3000print&nbsp;&#8216;\u603b\u91d1\u989d\u4e3a&#8217;+convert(varchar,@total_price) <br \/>\u3000\u3000go<\/font><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><font size=2>\u3000\u3000\u5b58\u50a8\u8fc7\u7a0b\u76843\u79cd\u4f20\u56de\u503c:<\/font><\/p>\n<p><font size=2>\u3000\u30001.\u4ee5Return\u4f20\u56de\u6574\u6570<\/font><\/p>\n<p><font size=2>\u3000\u30002.\u4ee5output\u683c\u5f0f\u4f20\u56de\u53c2\u6570<\/font><\/p>\n<p><font size=2>\u3000\u30003.Recordset<\/font><\/p>\n<p><font size=2>\u3000\u3000\u4f20\u56de\u503c\u7684\u533a\u522b:<\/font><\/p>\n<p><font size=2>\u3000\u3000output\u548creturn\u90fd\u53ef\u5728\u6279\u6b21\u7a0b\u5f0f\u4e2d\u7528\u53d8\u91cf\u63a5\u6536,\u800crecordset\u5219\u4f20\u56de\u5230\u6267\u884c\u6279\u6b21\u7684\u5ba2\u6237\u7aef\u4e2d<\/font><\/p>\n<p><font size=2>\u3000\u3000<strong>\u5b9e\u4f8b3\uff1a\u8bbe\u6709\u4e24\u4e2a\u8868\u4e3aProduct,Order,\u5176\u8868\u5185\u5bb9\u5982\u4e0b\uff1a<\/strong><\/font><\/p>\n<p><font size=2>\u4ee5\u4e0b\u4e3a\u5f15\u7528\u7684\u5185\u5bb9\uff1a<\/font><\/p>\n<p><font size=2>\u3000\u3000<strong>Product<\/strong><\/font><\/p>\n<p><font size=2>\u3000\u3000\u4ea7\u54c1\u7f16\u53f7 \u4ea7\u54c1\u540d\u79f0 \u5ba2\u6237\u8ba2\u6570<\/font><\/p>\n<p><font size=2>\u3000\u3000001\u3000\u3000\u3000 \u94a2\u7b14\u3000\u3000\u300030<\/font><\/p>\n<p><font size=2>\u3000\u3000002 \u3000\u3000\u3000\u6bdb\u7b14 \u3000\u3000 50<\/font><\/p>\n<p><font size=2>\u3000\u3000003&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u94c5\u7b14&nbsp; \u3000\u3000100<\/font><\/p>\n<p><font size=2>\u3000\u3000<strong>order<\/strong><\/font><\/p>\n<p><font size=2>\u3000\u3000\u4ea7\u54c1\u7f16\u53f7 \u5ba2\u6237\u540d \u5ba2\u6237\u8ba2\u91d1<\/font><\/p>\n<p><font size=2>\u3000\u3000001 \u3000\u3000\u5357\u5c71\u533a \u3000$30<\/font><\/p>\n<p><font size=2>\u3000\u3000002 \u3000\u3000\u7f57\u6e56\u533a \u3000$50<\/font><\/p>\n<p><font size=2>\u3000\u3000003 \u3000\u3000\u5b9d\u5b89\u533a \u3000$4<\/font><\/p>\n<p><font size=2>\u3000\u3000\u8bf7\u5b9e\u73b0\u6309\u7f16\u53f7\u4e3a\u8fde\u63a5\u6761\u4ef6,\u5c06\u4e24\u4e2a\u8868\u8fde\u63a5\u6210\u4e00\u4e2a\u4e34\u65f6\u8868,\u8be5\u8868\u53ea\u542b\u7f16\u53f7.\u4ea7\u54c1\u540d.\u5ba2\u6237\u540d.\u8ba2\u91d1.\u603b\u91d1\u989d,<\/font><\/p>\n<div><font size=2>\u3000\u3000\u603b\u91d1\u989d=\u8ba2\u91d1*\u8ba2\u6570,\u4e34\u65f6\u8868\u653e\u5728\u5b58\u50a8\u8fc7\u7a0b\u4e2d<\/font><\/div>\n<div><font size=2>\u3000\u3000\u4ee3\u7801\u5982\u4e0b:<\/font><\/div>\n<table style=\"BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted\" cellSpacing=0 cellPadding=6 width=\"95%\" align=center border=0>\n<tbody>\n<tr>\n<td style=\"WORD-WRAP: break-word\" bgColor=#f3f3f3><font size=2>\u3000\u3000Create&nbsp;proc&nbsp;temp_sale <br \/>\u3000\u3000as <br \/>\u3000\u3000select&nbsp;a.\u4ea7\u54c1\u7f16\u53f7,a.\u4ea7\u54c1\u540d\u79f0,b.\u5ba2\u6237\u540d,b.\u5ba2\u6237\u8ba2\u91d1,a.\u5ba2\u6237\u8ba2\u6570*&nbsp;b.\u5ba2\u6237\u8ba2\u91d1&nbsp;as\u603b\u91d1\u989d <br \/>\u3000\u3000into&nbsp;#temptable&nbsp;from&nbsp;Product&nbsp;a&nbsp;inner&nbsp;join&nbsp;order&nbsp;b&nbsp;on&nbsp;a.\u4ea7\u54c1\u7f16\u53f7=b.\u4ea7\u54c1\u7f16\u53f7 <br \/>\u3000\u3000if&nbsp;@@error=0 <br \/>\u3000\u3000print&nbsp;&#8216;Good&#8217; <br \/>\u3000\u3000else <br \/>\u3000\u3000print&nbsp;&#8216;Fail&#8217; <br \/>\u3000\u3000go<\/font><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><font size=2>\u3000\u3000<strong>\u4e09\u3001SQL\u5b58\u50a8\u8fc7\u7a0b\u5b66\u4e60:\u5b58\u50a8\u8fc7\u7a0b\u7684\u8c03\u7528<\/strong><\/font><\/p>\n<p><font size=2>\u3000\u3000\u8c03\u7528\u5e26\u53c2\u6570\u5b58\u50a8\u8fc7\u7a0b\u7684\u51e0\u79cd\u65b9\u5f0f<\/font><\/p>\n<p><font size=2>\u3000\u30001) \u8fd9\u4e5f\u662f\u6700\u7b80\u5355\u7684\u65b9\u6cd5,\u4e24\u4e2a\u8f93\u5165\u53c2\u6570\uff0c\u65e0\u8fd4\u56de\u503c,\u7528\u4e8eInsert,Update,Delete***\u4f5c\u8f83\u591a\u3002<\/font><\/p>\n<p><font size=2>\u3000\u3000\u4ee5\u4e0b\u4e3a\u5f15\u7528\u7684\u5185\u5bb9\uff1a<\/font><\/p>\n<p><font size=2>\u3000\u3000conn.Execute &#8220;procname varvalue1,varvalue2&#8221;<\/font><\/p>\n<p><font size=2>\u3000\u30002) \u5982\u679c\u8981\u8fd4\u56de Recordset \u96c6:<\/font><\/p>\n<p><font size=2>\u3000\u3000\u4ee5\u4e0b\u4e3a\u5f15\u7528\u7684\u5185\u5bb9\uff1a<\/font><\/p>\n<p><font size=2>\u3000\u3000<\/font><font color=#16387c size=2>set<\/font><font size=2> rs = <\/font><font color=#16387c size=2>server<\/font><font size=2>.createobject(&#8220;adodb.recordset&#8221;)<\/font><\/p>\n<p><font size=2>\u3000\u3000rs.Open &#8220;Exec procname varvalue1, varvalue2&#8221;,conn<\/font><\/p>\n<p><font size=2>\u3000\u30003) \u4ee5\u4e0a\u4e24\u79cd\u65b9\u6cd5\u90fd\u4e0d\u80fd\u6709\u8fd4\u56de\u503c\uff0c(Recordset\u9664\u5916)\uff0c\u5982\u679c\u8981\u5f97\u5230\u8fd4\u56de\u503c\uff0c\u9700\u8981\u7528Command\u7684\u65b9\u6cd5\u3002<\/font><\/p>\n<p><font size=2>\u3000\u3000\u9996\u5148\u8bf4\u660e\uff0c\u8fd4\u56de\u503c\u6709\u4e24\u79cd\u3002\u4e00\u79cd\u662f\u5728\u5b58\u50a8\u8fc7\u7a0b\u4e2d\u76f4\u63a5return\u4e00\u4e2a\u503c\uff0c\u5c31\u8c61C\u548cVB\u7684\u51fd\u6570\u8fd4\u56de\u503c\u90a3\u6837;\u53e6\u4e00\u79cd\u662f\u53ef\u4ee5\u8fd4\u56de\u591a\u4e2a\u503c\uff0c\u5b58\u50a8\u8fd9\u4e9b\u503c\u7684\u53d8\u91cf\u540d\u79f0\u9700\u8981\u5728\u8c03\u7528\u53c2\u6570\u4e2d\u5148\u884c\u6307\u5b9a\u3002<\/font><\/p>\n<p><font size=2>\u3000\u3000<strong>\u56db\u3001\u7279\u6b8a\u7684\u5b58\u50a8\u8fc7\u7a0b-\u89e6\u53d1\u5668<\/strong><\/font><\/p>\n<p><font size=2>\u3000\u3000<strong>1.\u89e6\u53d1\u5668\u7684\u6982\u5ff5\u53ca\u4f5c\u7528<\/strong><\/font><\/p>\n<div><font size=2>\u3000\u3000\u89e6\u53d1\u5668\u662f\u4e00\u79cd\u7279\u6b8a\u7c7b\u578b\u7684\u5b58\u50a8\u8fc7\u7a0b\uff0c\u5b83\u4e0d\u540c\u4e8e\u6211\u4eec\u524d\u9762\u4ecb\u7ecd\u8fc7\u7684\u5b58\u50a8\u8fc7\u7a0b\u3002\u89e6\u53d1\u5668\u4e3b\u8981\u662f\u901a\u8fc7\u4e8b\u4ef6\u8fdb\u884c\u89e6\u53d1\u800c\u88ab\u6267\u884c\u7684\uff0c\u800c\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u901a\u8fc7\u5b58\u50a8\u8fc7\u7a0b\u540d\u5b57\u800c\u88ab\u76f4\u63a5\u8c03\u7528\u3002\u5f53\u5bf9\u67d0\u4e00\u8868\u8fdb\u884c\u8bf8\u5982Update\u3001 Insert\u3001 Delete \u8fd9\u4e9b***\u4f5c\u65f6\uff0cSQL Server \u5c31\u4f1a\u81ea\u52a8\u6267\u884c\u89e6\u53d1\u5668\u6240\u5b9a\u4e49\u7684SQL \u8bed\u53e5\uff0c\u4ece\u800c\u786e\u4fdd\u5bf9\u6570\u636e\u7684\u5904\u7406\u5fc5\u987b\u7b26\u5408\u7531\u8fd9\u4e9bSQL \u8bed\u53e5\u6240\u5b9a\u4e49\u7684\u89c4\u5219\u3002<\/font><\/div>\n<div><font size=2>\u3000\u3000\u89e6\u53d1\u5668\u7684\u4e3b\u8981\u4f5c\u7528\u5c31\u662f\u5176\u80fd\u591f\u5b9e\u73b0\u7531\u4e3b\u952e\u548c\u5916\u952e\u6240\u4e0d\u80fd\u4fdd\u8bc1\u7684\u590d\u6742\u7684\u53c2\u7167\u5b8c\u6574\u6027\u548c\u6570\u636e\u7684\u4e00\u81f4\u6027\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u89e6\u53d1\u5668\u8fd8\u6709\u5176\u5b83\u8bb8\u591a\u4e0d\u540c\u7684\u529f\u80fd\uff1a<\/font> <\/p>\n<p><font size=2>\u3000\u3000(1) \u5f3a\u5316\u7ea6\u675f(Enforce restriction)<\/font><\/p>\n<p><font size=2>\u3000\u3000\u89e6\u53d1\u5668\u80fd\u591f\u5b9e\u73b0\u6bd4CHECK \u8bed\u53e5\u66f4\u4e3a\u590d\u6742\u7684\u7ea6\u675f\u3002<\/font><\/p>\n<p><font size=2>\u3000\u3000(2) \u8ddf\u8e2a\u53d8\u5316Auditing changes<\/font><\/p>\n<p><font size=2>\u3000\u3000\u89e6\u53d1\u5668\u53ef\u4ee5\u4fa6\u6d4b\u6570\u636e\u5e93\u5185\u7684***\u4f5c\uff0c\u4ece\u800c\u4e0d\u5141\u8bb8\u6570\u636e\u5e93\u4e2d\u672a\u7ecf\u8bb8\u53ef\u7684\u6307\u5b9a\u66f4\u65b0\u548c\u53d8\u5316\u3002<\/font><\/p>\n<p><font size=2>\u3000\u3000(3) \u7ea7\u8054\u8fd0\u884c(Cascaded operation)\u3002<\/font><\/p>\n<p><font size=2>\u3000\u3000\u89e6\u53d1\u5668\u53ef\u4ee5\u4fa6\u6d4b\u6570\u636e\u5e93\u5185\u7684***\u4f5c\uff0c\u5e76\u81ea\u52a8\u5730\u7ea7\u8054\u5f71\u54cd\u6574\u4e2a\u6570\u636e\u5e93\u7684\u5404\u9879\u5185\u5bb9\u3002\u4f8b\u5982\uff0c\u67d0\u4e2a\u8868\u4e0a\u7684\u89e6\u53d1\u5668\u4e2d\u5305\u542b\u6709\u5bf9\u53e6\u5916\u4e00\u4e2a\u8868\u7684\u6570\u636e***\u4f5c(\u5982\u5220\u9664\uff0c\u66f4\u65b0\uff0c\u63d2\u5165)\u800c\u8be5***\u4f5c\u53c8\u5bfc\u81f4\u8be5\u8868\u4e0a\u89e6\u53d1\u5668\u88ab\u89e6\u53d1\u3002<\/font><\/p>\n<p><font size=2>\u3000\u3000(4) \u5b58\u50a8\u8fc7\u7a0b\u7684\u8c03\u7528(Stored procedure invocation)\u3002<\/font><\/p>\n<p><font size=2>\u3000\u3000\u4e3a\u4e86\u54cd\u5e94\u6570\u636e\u5e93\u66f4\u65b0\u89e6\uff0c\u53d1\u5668\u53ef\u4ee5\u8c03\u7528\u4e00\u4e2a\u6216\u591a\u4e2a\u5b58\u50a8\u8fc7\u7a0b\uff0c\u751a\u81f3\u53ef\u4ee5\u901a\u8fc7\u5916\u90e8\u8fc7\u7a0b\u7684\u8c03\u7528\u800c\u5728DBMS( \u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf)\u672c\u8eab\u4e4b\u5916\u8fdb\u884c***\u4f5c\u3002<\/font><\/p>\n<p><font size=2>\u3000\u3000\u7531\u6b64\u53ef\u89c1\uff0c\u89e6\u53d1\u5668\u53ef\u4ee5\u89e3\u51b3\u9ad8\u7ea7\u5f62\u5f0f\u7684\u4e1a\u52a1\u89c4\u5219\u6216\u590d\u6742\u884c\u4e3a\u9650\u5236\u4ee5\u53ca\u5b9e\u73b0\u5b9a\u5236\u8bb0\u5f55\u7b49\u4e00\u4e9b\u65b9\u9762\u7684\u95ee\u9898\u3002\u4f8b\u5982\uff0c\u89e6\u53d1\u5668\u80fd\u591f\u627e\u51fa\u67d0\u4e00\u8868\u5728\u6570\u636e\u4fee\u6539\u524d\u540e\u72b6\u6001\u53d1\u751f\u7684\u5dee\u5f02\uff0c\u5e76\u6839\u636e\u8fd9\u79cd\u5dee\u5f02\u6267\u884c\u4e00\u5b9a\u7684\u5904\u7406\u3002\u6b64\u5916\u4e00\u4e2a\u8868\u7684\u540c\u4e00\u7c7b\u578b(Insert\u3001 Update\u3001 Delete)\u7684\u591a\u4e2a\u89e6\u53d1\u5668\u80fd\u591f\u5bf9\u540c\u4e00\u79cd\u6570\u636e***\u4f5c\u91c7\u53d6\u591a\u79cd\u4e0d\u540c\u7684\u5904\u7406\u3002<\/font><\/p>\n<p><font size=2>\u3000\u3000\u603b\u4f53\u800c\u8a00\uff0c\u89e6\u53d1\u5668\u6027\u80fd\u901a\u5e38\u6bd4\u8f83\u4f4e\u3002\u5f53\u8fd0\u884c\u89e6\u53d1\u5668\u65f6\uff0c\u7cfb\u7edf\u5904\u7406\u7684\u5927\u90e8<\/font><font color=#16387c size=2>\u5206\u65f6<\/font><font size=2>\u95f4\u82b1\u8d39\u5728\u53c2\u7167\u5176\u5b83\u8868\u7684\u8fd9\u4e00\u5904\u7406\u4e0a\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u8868\u65e2\u4e0d\u5728\u5185\u5b58\u4e2d\u4e5f\u4e0d\u5728\u6570\u636e\u5e93\u8bbe\u5907\u4e0a\uff0c\u800c\u5220\u9664\u8868\u548c\u63d2\u5165\u8868\u603b\u662f\u4f4d\u4e8e\u5185\u5b58\u4e2d\u3002\u53ef\u89c1\u89e6\u53d1\u5668\u6240\u53c2\u7167\u7684\u5176\u5b83\u8868\u7684\u4f4d\u7f6e\u51b3\u5b9a\u4e86***\u4f5c\u8981\u82b1\u8d39\u7684\u65f6\u95f4\u957f\u77ed\u3002<\/font><\/p>\n<p><font size=2>\u3000\u3000<strong>2.\u89e6\u53d1\u5668\u7684\u79cd\u7c7b<\/strong><\/font><\/p>\n<p><font size=2>\u3000\u3000SQL Server 2000 \u652f\u6301\u4e24\u79cd\u7c7b\u578b\u7684\u89e6\u53d1\u5668\uff1a<\/font><font color=#16387c size=2>AF<\/font><font size=2>TER \u89e6\u53d1\u5668\u548cINSTEAD OF \u89e6\u53d1\u5668\u3002\u5176\u4e2dAFTER \u89e6\u53d1\u5668\u5373\u4e3aSQL Server 2000 \u7248\u672c\u4ee5\u524d\u6240\u4ecb\u7ecd\u7684\u89e6\u53d1\u5668\u3002\u8be5\u7c7b\u578b\u89e6\u53d1\u5668\u8981\u6c42\u53ea\u6709\u6267\u884c\u67d0\u4e00***\u4f5c(Insert Update Delete) \u4e4b\u540e\uff0c\u89e6\u53d1\u5668\u624d\u88ab\u89e6\u53d1\uff0c\u4e14\u53ea\u80fd\u5728\u8868\u4e0a\u5b9a\u4e49\u3002\u53ef\u4ee5\u4e3a\u9488\u5bf9\u8868\u7684\u540c\u4e00***\u4f5c\u5b9a\u4e49\u591a\u4e2a\u89e6\u53d1\u5668\u3002\u5bf9\u4e8eAFTER \u89e6\u53d1\u5668\uff0c\u53ef\u4ee5\u5b9a\u4e49\u54ea\u4e00\u4e2a\u89e6\u53d1\u5668\u88ab\u6700\u5148\u89e6\u53d1\uff0c\u54ea\u4e00\u4e2a\u88ab\u6700\u540e\u89e6\u53d1\uff0c\u901a\u5e38\u4f7f\u7528\u7cfb\u7edf\u8fc7\u7a0bsp_settriggerorder \u6765\u5b8c\u6210\u6b64\u4efb\u52a1\u3002<\/font><\/p>\n<p><font size=2>\u3000\u3000INSTEAD OF \u89e6\u53d1\u5668\u8868\u793a\u5e76\u4e0d\u6267\u884c\u5176\u6240\u5b9a\u4e49\u7684***\u4f5c(Insert\u3001 Update\u3001 Delete)\uff0c\u800c\u4ec5\u662f\u6267\u884c\u89e6\u53d1\u5668\u672c\u8eab\u3002\u65e2\u53ef\u5728\u8868\u4e0a\u5b9a\u4e49INSTEAD OF \u89e6\u53d1\u5668\uff0c\u4e5f\u53ef\u4ee5\u5728\u89c6\u56fe\u4e0a\u5b9a\u4e49INSTEAD OF \u89e6\u53d1\u5668\uff0c\u4f46\u5bf9\u540c\u4e00***\u4f5c\u53ea\u80fd\u5b9a\u4e49\u4e00\u4e2aINSTEAD OF \u89e6\u53d1\u5668\u3002<\/font><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001SQL\u5b58\u50a8\u8fc7\u7a0b\u7684\u6982\u5ff5\uff0c\u4f18\u70b9\u53ca\u8bed\u6cd5 \u3000\u3000\u6574\u7406\u5728\u5b66\u4e60\u7a0b\u5e8f\u8fc7\u7a0b\u4e4b\u524d\uff0c\u5148\u4e86\u89e3\u4e0b\u4ec0\u4e48\u662f\u5b58\u50a8\u8fc7\u7a0b?\u4e3a\u4ec0\u4e48\u8981\u7528\u5b58\u50a8\u8fc7\u7a0b\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,8],"tags":[],"class_list":["post-514","post","type-post","status-publish","format-standard","hentry","category-1","category-oldblog"],"views":249,"_links":{"self":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts\/514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=514"}],"version-history":[{"count":1,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts\/514\/revisions"}],"predecessor-version":[{"id":807,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts\/514\/revisions\/807"}],"wp:attachment":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=514"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}