asp實(shí)現(xiàn)的查詢某關(guān)鍵詞在MSSQL數(shù)據(jù)庫(kù)位置的代碼
更新時(shí)間:2010年04月22日 21:57:20 作者:
整體而言,這段SQL只適宜用在小型數(shù)據(jù)庫(kù)上,ASP中的循環(huán)也沒(méi)效率,大庫(kù)還是別用了,小庫(kù)可以考慮。如果是大庫(kù)的話,請(qǐng)聯(lián)系皇子要另外一份牛人寫的SQL查詢語(yǔ)句。
功能是:以一個(gè)關(guān)鍵字為索引,搜索整個(gè)數(shù)據(jù)庫(kù),然后返回那個(gè)關(guān)鍵字所在的表名和列名。(很贊...特別是入侵的時(shí)候找不到用戶名與密碼所在的表的時(shí)候,如果能直接通過(guò)輸入admin這個(gè)關(guān)鍵詞找出字段...省得一個(gè)表一個(gè)表的看了。)于是根據(jù)那段語(yǔ)句,寫了個(gè)asp的腳本,方便大家以后搜尋數(shù)據(jù)庫(kù)。
代碼如下:
<%
'Confirm a keyword's position of a database(which table & which column)
'By oldjun(http://www.oldjun.com)
'Based on huangzi(http://www.2chuizi.com)'s sql
Server.ScriptTimeout=999999999
Response.Buffer =true
On Error Resume Next
keyword=request("keyword")
if keyword="" then
response.write "Need keyword!"
response.End
End if
dim conn
Set conn = Server.CreateObject("ADODB.Connection")
Dim ConnStr
'ConnectionString,Pls change!
ConnStr="Driver={SQL SERVER};Server=localhost;UID=sa;PWD=sa;Database=master"
Conn.open ConnStr
conn.execute("CREATE TABLE huangzi_table(id int identity(1,1),biaoid int,biaoname nvarchar(1000))")
conn.execute("insert huangzi_table select [id],[name] from sysobjects where xtype='U'")
set rs =conn.execute("select count(id) as tnum from huangzi_table")
tnum=rs("tnum")
rs.close
set rs=nothing
for i=1 to tnum
set rsbiao =conn.execute("select biaoid from huangzi_table where id="&i&"")
biaoid=rsbiao("biaoid")
set rst =conn.execute("select [biaoname] from huangzi_table where biaoid="&biaoid&"")
tname=rst("biaoname")
set rsl=conn.execute("select count([name]) as lnum from syscolumns where id="&biaoid&"")
lnum=rsl("lnum")
for j=1 to lnum
topnum=j-1
set rslie=conn.execute("select top 1 [name] from syscolumns where id="&biaoid&" and [name] not in
(select top "&topnum&" [name] from syscolumns where id="&biaoid&")")
liename=rslie("name")
set rsresult=conn.execute("select top 1 ["&liename&"] from ["&tname&"] where CAST(["&liename&"] AS NVARCHAR(1000))='"&keyword&"'")
if rsresult.bof or rsresult.eof then
'response.write "Nothing-"&tname&":"&liename
'response.write "<br>"
else
result=rsresult(liename)
response.write result&"("&tname&":"&liename&")"
response.write "<br>"
End if
rslie.close
set rslie=nothing
rsresult.close
set rsresult=nothing
next
rsbiao.close
set rsbiao=nothing
rst.close
set rst=nothing
rsl.close
set rsl=nothing
next
conn.execute("DROP TABLE huangzi_table")
%>
注:效率很差,使用時(shí)可能出現(xiàn)假死, 請(qǐng)耐心等待,大庫(kù)還是別用了;代碼簡(jiǎn)單,實(shí)現(xiàn)的簡(jiǎn)單功能,沒(méi)技術(shù)含量,留著以后備用;換連接語(yǔ)句的時(shí)候有個(gè)緩存問(wèn)題,建議重啟下瀏覽器!
代碼如下:
復(fù)制代碼 代碼如下:
<%
'Confirm a keyword's position of a database(which table & which column)
'By oldjun(http://www.oldjun.com)
'Based on huangzi(http://www.2chuizi.com)'s sql
Server.ScriptTimeout=999999999
Response.Buffer =true
On Error Resume Next
keyword=request("keyword")
if keyword="" then
response.write "Need keyword!"
response.End
End if
dim conn
Set conn = Server.CreateObject("ADODB.Connection")
Dim ConnStr
'ConnectionString,Pls change!
ConnStr="Driver={SQL SERVER};Server=localhost;UID=sa;PWD=sa;Database=master"
Conn.open ConnStr
conn.execute("CREATE TABLE huangzi_table(id int identity(1,1),biaoid int,biaoname nvarchar(1000))")
conn.execute("insert huangzi_table select [id],[name] from sysobjects where xtype='U'")
set rs =conn.execute("select count(id) as tnum from huangzi_table")
tnum=rs("tnum")
rs.close
set rs=nothing
for i=1 to tnum
set rsbiao =conn.execute("select biaoid from huangzi_table where id="&i&"")
biaoid=rsbiao("biaoid")
set rst =conn.execute("select [biaoname] from huangzi_table where biaoid="&biaoid&"")
tname=rst("biaoname")
set rsl=conn.execute("select count([name]) as lnum from syscolumns where id="&biaoid&"")
lnum=rsl("lnum")
for j=1 to lnum
topnum=j-1
set rslie=conn.execute("select top 1 [name] from syscolumns where id="&biaoid&" and [name] not in
(select top "&topnum&" [name] from syscolumns where id="&biaoid&")")
liename=rslie("name")
set rsresult=conn.execute("select top 1 ["&liename&"] from ["&tname&"] where CAST(["&liename&"] AS NVARCHAR(1000))='"&keyword&"'")
if rsresult.bof or rsresult.eof then
'response.write "Nothing-"&tname&":"&liename
'response.write "<br>"
else
result=rsresult(liename)
response.write result&"("&tname&":"&liename&")"
response.write "<br>"
End if
rslie.close
set rslie=nothing
rsresult.close
set rsresult=nothing
next
rsbiao.close
set rsbiao=nothing
rst.close
set rst=nothing
rsl.close
set rsl=nothing
next
conn.execute("DROP TABLE huangzi_table")
%>
注:效率很差,使用時(shí)可能出現(xiàn)假死, 請(qǐng)耐心等待,大庫(kù)還是別用了;代碼簡(jiǎn)單,實(shí)現(xiàn)的簡(jiǎn)單功能,沒(méi)技術(shù)含量,留著以后備用;換連接語(yǔ)句的時(shí)候有個(gè)緩存問(wèn)題,建議重啟下瀏覽器!
您可能感興趣的文章:
- access數(shù)據(jù)庫(kù)的一些少用操作,ASP,創(chuàng)建數(shù)據(jù)庫(kù)文件,創(chuàng)建表,創(chuàng)建字段,ADOX
- ASP ACCESS 日期操作語(yǔ)句小結(jié) By Stabx
- asp 獲取access系統(tǒng)表,查詢等操作代碼
- Asp 操作Access數(shù)據(jù)庫(kù)時(shí)出現(xiàn)死鎖.ldb的解決方法
- asp.net(C#) Access 數(shù)據(jù)操作類
- asp 在線備份與恢復(fù)sqlserver數(shù)據(jù)庫(kù)的代碼
- asp終極防范SQL注入漏洞
- asp連接mysql數(shù)據(jù)庫(kù)詳細(xì)實(shí)現(xiàn)代碼
- asp連接access、sql數(shù)據(jù)庫(kù)代碼及數(shù)據(jù)庫(kù)操作代碼
- asp操作access提示無(wú)法從指定的數(shù)據(jù)表中刪除原因分析及解決
- ASP中巧用Split()函數(shù)生成SQL查詢語(yǔ)句的實(shí)例
- asp執(zhí)行帶參數(shù)的sql語(yǔ)句實(shí)例
- ASP 連接 SQL SERVER 2008的方法
- ASP通過(guò)ODBC連接SQL Server 2008數(shù)據(jù)庫(kù)的方法
- ASP語(yǔ)言實(shí)現(xiàn)對(duì)SQL SERVER數(shù)據(jù)庫(kù)的操作
相關(guān)文章
asp獲取數(shù)據(jù)庫(kù)中表名和字段名的代碼
今天冒出來(lái)一個(gè)想法,在僅知道數(shù)據(jù)庫(kù)名的情況下,用asp得到數(shù)據(jù)庫(kù)中的所有表名、所有表的字段名、以及所有字段中的內(nèi)容。經(jīng)過(guò)一段時(shí)間查詢資料和修改,終于做出來(lái)了,現(xiàn)在與大家分享。2008-09-09ASP連接SQL2005數(shù)據(jù)庫(kù)連接代碼
動(dòng)態(tài)網(wǎng)頁(yè)開(kāi)發(fā) ASP連接SQL2005數(shù)據(jù)庫(kù)連接代碼2009-11-11用ASP和SQL實(shí)現(xiàn)基于Web的事件日歷
用ASP和SQL實(shí)現(xiàn)基于Web的事件日歷...2006-09-09如何在不支持?jǐn)?shù)據(jù)庫(kù)的asp主頁(yè)上運(yùn)用ado
如何在不支持?jǐn)?shù)據(jù)庫(kù)的asp主頁(yè)上運(yùn)用ado...2006-09-09ASP在SQL Server 2000中新建帳號(hào)和權(quán)限
ASP在SQL Server 2000中新建帳號(hào)和權(quán)限...2006-08-08為什么ASP中執(zhí)行動(dòng)態(tài)SQL總報(bào)錯(cuò)誤信息?提示語(yǔ)句語(yǔ)法錯(cuò)誤
為什么ASP中執(zhí)行動(dòng)態(tài)SQL總報(bào)錯(cuò)誤信息?提示語(yǔ)句語(yǔ)法錯(cuò)誤...2007-04-04