then
table = request("table_name")
echo "以下是表 <font color=red>" & request("table_name") & "</font> 的结构: "
echo "<input type=''button'' name=''ok'' value='' 返 回 '' onClick=''javascript:history.go(-1)''>"
strsql = getsql(table)
end if
if strt = "2" then
echo "以下是 <font color=red> 数据库 </font> 的结构: "
echo "<input type=''button'' name=''ok'' value='' 返 回 '' onClick=''javascript:history.go(-1)''>"
set objSchema = Conn.OpenSchema(adSchemaTables)
Do While Not objSchema.EOF
if objSchema("TABLE_TYPE") = "TABLE" then
table = objSchema("TABLE_NAME")
strsql = strsql & getsql(table)''table & "|"''getsql(table)
end if
objSchema.MoveNext
Loop
objSchema.close
end if
echo "<textarea cols=110 rows=38>" & strsql & "</textarea>"
conn.close
end sub
''================================================================== 输出表结构
function getsql(table)
on error resume next
getsql = "-- 表结构 " & table & " 的SQL语句。" & chr(10)
dim primary,primarykey
Set primary = Conn.OpenSchema(adSchemaPrimaryKeys,Array(empty,empty,table))
if primary("COLUMN_NAME") <> "" then
primarykey = primary("COLUMN_NAME")
end if
primary.Close
set primary = nothing
tbl_struct = "CREATE TABLE [" & table & "] ( " & chr(10)
sql = "SELECT * FROM " & table
Set rs = Conn.Execute(sql)
if err = 0 then
for i = 0 to rs.fields.count-1
tbl_struct = tbl_struct & "[" & rs(i).name & "] "
typs = typ(rs(i).type)
if typs = "VARCHAR" or typs = "BINARY" or typs = "CHAR" then
tbl_struct = tbl_struct & typs & "(" & rs(i).definedsize & ")"
else
tbl_struct = tbl_struct & typs & " "
end if
attrib = rs(i).attributes
if (attrib and adFldIsNullable) = 0 then
tbl_struct = tbl_struct&" NOT NULL"
end if
if rs(i).Properties("ISAUTOINCREMENT") = True then
tbl_struct = tbl_struct & " IDENTITY"
end if
tbl_struct = tbl_struct & "," & chr(10)
next
if primarykey <> "" then
tbl_struct = tbl_struct & "PRIMARY KEY ([" & primarykey & "]));"
else
len_of_sql = Len(tbl_struct)
tbl_struct = Mid(tbl_struct,1,len_of_sql-2)
tbl_struct = tbl_struct & ");"
end if
else
tbl_struct = "CREATE TABLE [" & table & "];"
end if
getsql = getsql & tbl_struct & chr(10) & chr(10)
end function
sub help()
echo "SQL 常用语句:<br><br>"
echo "创建表:<br>"
echo "CREATE TABLE [表名] (<br>"
echo "[test1] int not null identity,<br>"
echo "[test2] binary not null,<br>"
echo "primary key ([test1]))<br><br>"
echo "