Posted on 2012-03-10 11:25
lxasp 阅读(1164)
评论(0) 编辑 收藏 引用 所属分类:
ASP
创建“自动编号”字段的语法
字段名 AUTOINCREMENT(1,1) PRIMARY KEY ,
◆严重注意(真TMD的阉割!):"字段名"与AUTOINCREMENT之间只能有空格,不能含有例如 INT NOT NULL 等其他关键词否则报错!
专用ASP代码:
<%
'运行ACCESS的SQL语句专用ASP文件 %23 = # %25 = %
if request.querystring("go")="ex" then exsql
sub exsql
Dim tsql,a,i,t
Dim rs, conn
Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("youraccessfile.mdb")
tsql=request.form("tsql")
a=split(tsql,request.form("ck"))
for i=0 to ubound(a)
t=MSSQL2ACCESS( a(i) )
if len(trim(a(i)))>0 then
response.write t & "<hr>"
response.flush
conn.Execute t
end if
next
response.write "Finish Execute : " & i
response.end
' Set rs = CreateObject("ADODB.Recordset")
' rs.Open SQLz, conn, 1, 1
end sub
function MSSQL2ACCESS(s)
s=rxpgi(s,"(INTEGER|INT|NUMERIC\(\d*,\d*\))?\s*(NOT\s+NULL)?\s*IDENTITY","AUTOINCREMENT")
s=rxpgi(s,"CLUSTERED","")
s=rxpgi(s,"GETDATE","NOW")
s=rxpgi(s,vbcr," ")
s=rxpgi(s,vblf," ")
MSSQL2ACCESS=s
end function
Function rxpgi(str1, patrn, replStr)
Dim regEx
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.Global = True
regEx.IgnoreCase = True
rxpgi = regEx.Replace(str1, replStr)
End Function
%>
<form id="" name="" method="post" action="?go=ex" onsubmit="return true;"><div>
<textarea name="tsql" cols="120" rows="30"></textarea>
<br />
<input name="" id="" type="submit" value="!!-- 运行 --!!" />
自定义多条SQL语句分隔结束符:<input name="ck" id="" type="text" value=";" style="width:100px" />
</div></form>