最新整理站長(zhǎng)建站常用的SQL和ASP技巧大全免費(fèi)分享
下面最新整理一些站長(zhǎng)建站常用的SQL和ASP技巧大全,免費(fèi)提供給大家一起分享。
sql常用命令方法!!!
(1) 數(shù)據(jù)記錄篩選:
sql="select * from 數(shù)據(jù)表 where 字段名 like ''%字段值%'' order by 字段名 [desc]"
sql="select top 10 * from 數(shù)據(jù)表 where 字段名 order by 字段名 [desc]"
sql="select * from 數(shù)據(jù)表 where 字段名 in (''值1'',''值2'',''值3'')"
sql="select * from 數(shù)據(jù)表 where 字段名 between 值1 and 值2"
(2) 更新數(shù)據(jù)記錄:
sql="update 數(shù)據(jù)表 set 字段1=值1,字段2=值2 …… 字段n=值n where 條件表達(dá)式"
(3) 刪除數(shù)據(jù)記錄:
sql="delete from 數(shù)據(jù)表" (將數(shù)據(jù)表所有記錄刪除)
(4) 添加數(shù)據(jù)記錄:
sql="insert into 目標(biāo)數(shù)據(jù)表 select * from 源數(shù)據(jù)表" (把源數(shù)據(jù)表的記錄添加到目標(biāo)數(shù)據(jù)表)
(5) 數(shù)據(jù)記錄統(tǒng)計(jì)函數(shù):
AVG(字段名) 得出一個(gè)表格欄平均值
COUNT(*|字段名) 對(duì)數(shù)據(jù)行數(shù)的統(tǒng)計(jì)或?qū)δ骋粰谟兄档臄?shù)據(jù)行數(shù)統(tǒng)計(jì)
MAX(字段名) 取得一個(gè)表格欄最大的值
MIN(字段名) 取得一個(gè)表格欄最小的值
SUM(字段名) 把數(shù)據(jù)欄的值相加
引用以上函數(shù)的方法:
set rs=conn.excute(sql)
用 rs("別名") 獲取統(tǒng)的計(jì)值,其它函數(shù)運(yùn)用同上。
(5) 數(shù)據(jù)表的建立和刪除:
CREATE TABLE 數(shù)據(jù)表名稱(chēng)(字段1 類(lèi)型1(長(zhǎng)度),字段2 類(lèi)型2(長(zhǎng)度) …… )
例:CREATE TABLE tab01(name varchar(50),datetime default now())
DROP TABLE 數(shù)據(jù)表名稱(chēng) (永久性刪除一個(gè)數(shù)據(jù)表)
drop table yjkc
select * into yjkc from yjkc2
drop table yjkc2
SQL連接方式
set conn=server.createobject("ADODB.connection")
conn.open "PROVIDER=SQLOLEDB;DATA SOURCE=服務(wù)器;UID=用戶名;PWD=密碼;DATABASE=表名;"
access連接方式
dim connstr
on error resume next
connstr="DBQ="+server.mappath("數(shù)據(jù)庫(kù)路徑")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
包含頁(yè)
調(diào)用表
打開(kāi)數(shù)據(jù)庫(kù)之后固定修改某個(gè)字段
刪除內(nèi)容
sql="select * from 表名 where 字段=變量"
rs.open sql,conn,1,3
有圖片就刪除圖片
Picture=rs("newspic")
set fs=server.CreateObject("scripting.filesystemobject")
Picture=server.MapPath(Picture)
if fs.FileExists(Picture) then
fs.DeleteFile Picture,true
end if
rs.delete
rs.update
response.redirect request.servervariables("http_referer")
end if
分頁(yè)
<tr bgcolor="f5f5f5">
<td width=10% align=center>
<font color="">id
</td>
<td width=40% align=center>關(guān) 鍵 詞;</td>
<td width=10% align=center>價(jià) 格</td>
<td width=20% align=center>修 改</td>
<td width=20% align=center>刪 除</td>
</tr>
<%
If Request.QueryString("page") = "" or Request.QueryString("page") = 0 then
page = 1
Else
page = CINT(Request.QueryString("page"))
End If
if request("pm")="" then
set rs=server.CreateObject("adodb.recordset")
sql="select * from p_words order by id desc"
rs.open sql,conn,1,1
else
set rs=server.CreateObject("adodb.recordset")
sql="select * from p_words where pm_name like '%"&request("pm")&"%'"
rs.open sql,conn,1,1
end if
if rs.eof and rs.bof then%>
<tr >
<td width=10% align=center colspan="6" >
暫時(shí)沒(méi)有記錄。<br>
</td>
</tr>
<%
else
%>
<%
RS.PageSize=10'設(shè)置每頁(yè)記錄數(shù)
Dim TotalPages
TotalPages = RS.PageCount
If page>RS.Pagecount Then
page=RS.Pagecount
end if
RS.AbsolutePage=page
rs.CacheSize = RS.PageSize'設(shè)置最大記錄數(shù)
Dim Totalcount
Totalcount =INT(RS.recordcount)
StartPageNum=1
do while StartPageNum+10<=page
StartPageNum=StartPageNum+10
Loop
EndPageNum=StartPageNum+9
If EndPageNum>RS.Pagecount then EndPageNum=RS.Pagecount %>
<%I=0
p=RS.PageSize*(page-1)
do while (Not RS.Eof) and (I<RS.PageSize)
p=p+1%>
<form action="?act=move&id=<%=rs("id")%>" method=post name=form1>
<tr bgcolor="#FFFFFF">
<td align=center><%=rs("id")%></td>
<td><input type=text name="pm_name" size=12 value="<%=rs("pm_name")%>"></td>
<td align=center><input type=text name="pm_p" size=8 value="<%=rs("pm_p")%>"></td>
<td align=center><input type='submit' class='button' value='修改'></td>
<td align=center><input type="button" name="Submit" value="刪除" class="button" onclick="location='biglist.asp?act=del&id=<%=rs("id")%>'"></td>
</tr>
</form>
<%I=I+1
RS.MoveNext
Loop%>
<tr> <td colspan="6" align=right height=30>
共有<font color=red><%=rs.recordcount%></font>個(gè)關(guān)鍵詞,<font color=red><%=page%></font>/<%=TotalPages%>頁(yè)
【<a href="<%=request.ServerVariables("URL")%>?page=1">首頁(yè)</a>】
<% if page>1 then %>
【<a href="<%=request.ServerVariables("URL")%>?page=<%=StartPageNum-1%>">上一頁(yè)</a>】
<%else%>
<%end if%>
<% For I=StartPageNum to EndPageNum
if I<>page then %><A href="?page=<%=I%>"><u><%=I%></u> </A><% else %><font color=red><%=I%></font> <% end if %><% Next %><% if EndPageNum<RS.Pagecount then %>
【<a href="<%=request.ServerVariables("URL")%>?page=<%=EndcPageNum+i%>">下一頁(yè)</a>】
<%end if%>
【<a href="<%=request.ServerVariables("URL")%>?page=<%=TotalPages%>">尾頁(yè)</a>】
</td></tr>
<%
end if
rs.close
%>
</table>
常用JAVA