首页  ·  知识 ·  编程语言
数据库结构显示出来的源代码
佚名  http://www.tiantiansoft.com  ASP  编辑:dezai  图片来源:网络
数据库结构显示出来的源代码 通过以上的代码即可显示表的结构,字段类型,长度,自动编号,主健

数据库结构显示出来的源代码

 

通过以上的代码即可显示表的结构,字段类型,长度,自动编号,主健。如果你仔细研究后就可以发现如何远程改变数据库的结构了,祝你好运!

要查看此演示,需要你建立一个数据源,request("table")改为你的表的名字。


main



欢迎查看chenyangasp演示程序

 
<%
on error resume next
table=request("table")
//获得表名
if table<>"" then
  response.write "数据表:"&table
Set primary = con.OpenSchema(adSchemaPrimaryKeys, _
        Array(empty, empty, table))
if primary("COLUMN_NAME")<>"" then
primarykey=primary("COLUMN_NAME")
end if
primary.close
set primary=nothing
%>



  
     
       
        字段

      
       
        类型

      
       
        设定大小

      
       
        允许空值

      
       
        自动编号
      
      主键
      
<%sql="select * from ["&table&"] "
  set rs=con.execute(sql)
  for i=0 to rs.fields.count-1
%>
     
       
        <%=rs(i).name%>
//字段名      

       
         
          <%
field_type=rs(i).type
select case field_type
    case adEmpty
      typ = "Empty"
    case adTinyInt
      typ = "TinyInt"
    case adSmallInt
      typ = "SmallInt"
    case adInteger
      typ = "Integer"
    case adBigInt
      typ = "BigInt"
    case adUnsignedTinyInt
      typ = "UnsignedTinyInt"
    case adUnsignedSmallInt
      typ = "UnsignedSmallInt"
    case adUnsignedInt
      typ = "UnsignedInt"
    case adUnsignedBigInt
      typ = "UnsignedBigInt"
    case adSingle
      typ = "Single"
    case adDouble
      typ = "Double"
    case adCurrency
      typ = "Currency"
    case adDecimal
      typ = "Decimal"
    case adNumeric
      typ = "Numeric"
    case adBoolean
      typ = "Boolean"
    case adError
      typ = "Error"
    case adUserDefined
      typ = "UserDefined"
    case adVariant
      typ = "Variant"
    case adIDispatch
      typ = "IDispatch"
    case adIUnknown
      typ = "IUnknown"
    case adGUID
      typ = "GUID"
    case adDATE
      typ = "DATE"
    case adDBDate
      typ = "DBDate"
    case adDBTime
      typ = "DBTime"
    case adDBTimeStamp
      typ = "DBTimeStamp"
    case adBSTR
      typ = "BSTR"
    case adChar
      typ = "Char"
    case adVarChar
      typ = "VarChar"
    case adLongVarChar
      typ = "LongVarChar"
    case adWChar
      typ = "WChar"
    case adVarWChar
      typ = "VarWChar"
    case adLongVarWChar
      typ = "LongVarWChar"
    case adBinary
      typ = "Binary"
    case adVarBinary
      typ = "VarBinary"
    case adLongVarBinary
      typ = "LongVarBinary"
    case adChapter
      typ = "Chapter"
    case adPropVariant
      typ = "PropVariant"
    case else
      typ = "Unknown"
  end select
response.write typ%>
//字段类型 
       
      
       
        <%=rs(i).definedsize%>
      
//字段长度

       
         
          <%
  attrib=rs(i).attributes
  if (attrib and adFldIsNullable)=0 then
    response.write "No"
  else
    response.write "Yes"
  end if
%>
        
      

//是否允许空值

      
         
<%if rs(i).Properties("ISAUTOINCREMENT") = True then%>
          
<%else%>
          
<%end if%>        
        
      

//是否为自动编号

       
         
          <%if rs(i).name=primarykey then%>
          
          <%else%>
          
          <%end if%>
        
      

//主健

     
    <%next %>
  

本文作者:佚名 来源:http://www.tiantiansoft.com
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读