{"id":637,"date":"2010-10-26T17:03:41","date_gmt":"2010-10-26T09:03:41","guid":{"rendered":""},"modified":"2014-03-11T22:34:05","modified_gmt":"2014-03-11T14:34:05","slug":"%e5%bd%bb%e5%ba%95%e8%a7%a3%e5%86%b3xxx-org%e6%95%b0%e6%8d%ae%e5%ba%93sql%e6%b3%a8%e5%85%a5%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/www.xiaoyebailong.com\/index.php\/2010\/10\/26\/637.htm","title":{"rendered":"\u5f7b\u5e95\u89e3\u51b3xxx.org\u6570\u636e\u5e93sql\u6ce8\u5165\u95ee\u9898"},"content":{"rendered":"<p>\u8fd1\u65e5\u5f88\u591a\u4f7f\u7528SQL SERVER\u4f5c\u4e3a\u6570\u636e\u5e93\u7684\u7ad9\u957f\u670b\u53cb\u90fd\u4e2d\u4e86xxx.org\u7684\u6076\u610f\u4ee3\u7801\uff0c\u5173\u4e8e\u5982\u4f55\u5f7b\u5e95\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\uff0c\u771f\u662f\u6101\u574f\u4e86\u4e00\u4e9b\u65b0\u624b\u7ad9\u957f\uff0c\u5c31\u8fde\u4e00\u4e9b\u7ecf\u9a8c\u4e30\u5bcc\u7684\u8001\u7ad9\u957f\u4e5f\u6709\u7684\u65e0\u80fd\u4e3a\u529b\uff0c\u70c8\u706b\u7f51\u5c0f\u7f16\u7ecf\u8fc7\u5b9e\u6218\u548c\u7f51\u4e0a\u67e5\u627e\u8d44\u6599\uff0c\u73b0\u5728\u5c06\u89e3\u51b3\u65b9\u6cd5\u516c\u5e03\u7ed9\u5927\u5bb6\uff1a<\/p>\n<p>\u5982\u4f55\u6700\u5feb\u901f\u5ea6\u5220\u9664\uff1f <br \/>\n&quot; &lt;script src=http:\/\/xxx.org\/c.js&gt; &lt;\/script&gt; &quot; <br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; <br \/>\n\u8fdb\u5165SQL\u67e5\u8be2\u5206\u6790\u5668 <br \/>\n\u9009\u62e9\u4f60\u7684\u6570\u636e\u5e93 <br \/>\n\u7b2c\u4e00\u6b65\uff1a\u5148sql\u8868\u4fee\u6539\u6240\u6709\u8005\u4e3adbo <br \/>\nEXEC sp_MSforeachtable &#8216;exec sp_changeobjectowner &#8216; &#8216;? &#8216; &#8216;, &#8216; &#8216;dbo &#8216; &#8216; &#8216;<\/p>\n<p>\u7b2c\u4e8c\u6b65\uff1a\u7edf\u4e00\u5220\u9664\u5b57\u6bb5\u88ab\u6302\u7684js <br \/>\ndeclare @delStr nvarchar(500) <br \/>\nset @delStr= &#8216; &lt;script src=http:\/\/xxx.org\/c.js&gt; &lt;\/script&gt; &#8216;<\/p>\n<p>set nocount on<\/p>\n<p>declare @tableName nvarchar(100),@columnName nvarchar(100),@tbID int,@iRow int,@iResult int <br \/>\ndeclare @sql nvarchar(500)<\/p>\n<p>set @iResult=0 <br \/>\ndeclare cur cursor for <br \/>\nselect name,id from sysobjects where xtype= &#8216;U &#8216;<\/p>\n<p>open cur <br \/>\nfetch next from cur into @tableName,@tbID<\/p>\n<p>while @@fetch_status=0 <br \/>\nbegin <br \/>\ndeclare cur1 cursor for <br \/>\n&#8211;xtype in (231,167,239,175,35) \u4e3achar,varchar,nchar,nvarchar,text\u7c7b\u578b <br \/>\nselect name from syscolumns where xtype in (231,167,239,175,35) and <a href=\"mailto:id=@tbID\">id=@tbID<\/a> <br \/>\nopen cur1 <br \/>\nfetch next from cur1 into @columnName <br \/>\nwhile @@fetch_status=0 <br \/>\nbegin <br \/>\nset @sql= &#8216;update [ &#8216; + @tableName + &#8216;] set [ &#8216;+ @columnName + &#8216;]= replace([ <a href=\"mailto:'+@columnName\">&#8216;+@columnName<\/a>+ &#8216;], &#8216; &#8216; <a href=\"mailto:'+@delStr\">&#8216;+@delStr<\/a>+ &#8216; &#8216; &#8216;, &#8216; &#8216; &#8216; &#8216;) where [ <a href=\"mailto:'+@columnName\">&#8216;+@columnName<\/a>+ &#8216;] like &#8216; &#8216;% <a href=\"mailto:'+@delStr\">&#8216;+@delStr<\/a>+ &#8216;% &#8216; &#8216; &#8216; <br \/>\nexec sp_executesql @sql <br \/>\nset @iRow=@@rowcount <br \/>\nset @iResult=@iResult+@iRow <br \/>\nif @iRow&gt; 0 <br \/>\nbegin <br \/>\nprint &#8216;\u8868\uff1a <a href=\"mailto:'+@tableName\">&#8216;+@tableName<\/a>+ &#8216;,\u5217: <a href=\"mailto:'+@columnName\">&#8216;+@columnName<\/a>+ &#8216;\u88ab\u66f4\u65b0 &#8216;+convert(varchar(10),@iRow)+ &#8216;\u6761\u8bb0\u5f55; &#8216; <br \/>\nend <br \/>\nfetch next from cur1 into @columnName<\/p>\n<p>end <br \/>\nclose cur1 <br \/>\ndeallocate cur1<\/p>\n<p>fetch next from cur into @tableName,@tbID <br \/>\nend <br \/>\nprint &#8216;\u6570\u636e\u5e93\u5171\u6709 &#8216;+convert(varchar(10),@iResult)+ &#8216;\u6761\u8bb0\u5f55\u88ab\u66f4\u65b0!!! &#8216;<\/p>\n<p>close cur <br \/>\ndeallocate cur <br \/>\nset nocount off <br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; <br \/>\n\u5f7b\u5e95\u675c\u7eddSQL\u6ce8\u5165<\/p>\n<p>1.\u4e0d\u8981\u4f7f\u7528sa\u7528\u6237\u8fde\u63a5\u6570\u636e\u5e93 <br \/>\n2\u3001\u65b0\u5efa\u4e00\u4e2apublic\u6743\u9650\u6570\u636e\u5e93\u7528\u6237\uff0c\u5e76\u7528\u8fd9\u4e2a\u7528\u6237\u8bbf\u95ee\u6570\u636e\u5e93 <br \/>\n3\u3001[\u89d2\u8272]\u53bb\u6389\u89d2\u8272public\u5bf9sysobjects\u4e0esyscolumns\u5bf9\u8c61\u7684select\u8bbf\u95ee\u6743\u9650 <br \/>\n4\u3001[\u7528\u6237]\u7528\u6237\u540d\u79f0-&gt; \u53f3\u952e\uff0d\u5c5e\u6027\uff0d\u6743\u9650\uff0d\u5728sysobjects\u4e0esyscolumns\u4e0a\u9762\u6253&ldquo;&times;&rdquo; <br \/>\n5\u3001\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u68c0\u6d4b\uff08\u5931\u8d25\u8868\u793a\u6743\u9650\u6b63\u786e\uff0c\u5982\u80fd\u663e\u793a\u51fa\u6765\u5219\u8868\u660e\u6743\u9650\u592a\u9ad8\uff09\uff1a <br \/>\nDECLARE @T varchar(255), <br \/>\n@C varchar(255) <br \/>\nDECLARE Table_Cursor CURSOR FOR <br \/>\nSelect a.name,b.name from sysobjects a,syscolumns b <br \/>\nwhere a.id=b.id and a.xtype= &#8216;u &#8216; and (b.xtype=99 or b.xtype=35 or b.xtype=231 or b.xtype=167) <br \/>\nOPEN Table_Cursor <br \/>\nFETCH NEXT FROM Table_Cursor INTO @T,@C <br \/>\nWHILE(@@FETCH_STATUS=0) <br \/>\nBEGIN print @c <br \/>\nFETCH NEXT FROM Table_Cursor INTO @T,@C <br \/>\nEND <br \/>\nCLOSE Table_Cursor <br \/>\nDEALLOCATE Table_Cursor <br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; <br \/>\n\u8ba9xxx.org c.js\u6ce8\u5165\u89c1\u9b3c\u53bb\u5427\uff01<br \/>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd1\u65e5\u5f88\u591a\u4f7f\u7528SQL SERVER\u4f5c\u4e3a\u6570\u636e\u5e93\u7684\u7ad9\u957f\u670b\u53cb\u90fd\u4e2d\u4e86xxx.org\u7684\u6076\u610f\u4ee3\u7801\uff0c\u5173\u4e8e\u5982\u4f55\u5f7b\u5e95\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\uff0c\u771f\u662f\u6101\u574f\u4e86\u4e00\u4e9b\u65b0\u624b\u7ad9\u957f\uff0c\u5c31\u8fde\u4e00\u4e9b\u7ecf\u9a8c\u4e30\u5bcc\u7684\u8001\u7ad9\u957f\u4e5f\u6709\u7684\u65e0\u80fd\u4e3a\u529b\uff0c\u70c8\u706b\u7f51\u5c0f\u7f16\u7ecf\u8fc7\u5b9e\u6218\u548c\u7f51\u4e0a\u67e5\u627e\u8d44\u6599\uff0c\u73b0\u5728\u5c06\u89e3\u51b3\u65b9\u6cd5\u516c\u5e03\u7ed9\u5927\u5bb6\uff1a \u5982\u4f55&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"topic":[],"class_list":["post-637","post","type-post","status-publish","format-standard","hentry","category-technology"],"_links":{"self":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/comments?post=637"}],"version-history":[{"count":1,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/637\/revisions"}],"predecessor-version":[{"id":66490,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/637\/revisions\/66490"}],"wp:attachment":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/media?parent=637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/categories?post=637"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/tags?post=637"},{"taxonomy":"topic","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/topic?post=637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}