三度网教程:是一个免费提供流行视频软件教程、在线学习分享的学习平台!

SQL SERVER结构浏览器

时间:2023-9-7作者:未知来源:三度网教程人气:


从老外那儿转帖过来的

很酷,只要修改几个参数就可以了,很有帮助

<%@ LANGUAGE = JScript %>
<%
        var ConnStr= "DSN=admin";    //
    var UserLogin= "sa";        // input empty Login and Password,
    var UserPassword= "";    // if your DSN works via WinNT trust connection
    var CharSet= "gb2312";        // as sample "windows-1251"
    var PgSize= 10;    
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=<%=CharSet%>">
<title>MS SQL Structure Viewer Version 1.2</title>
</head>
<body bgcolor=#2f2f2f link=#000000 vlink=#000000 alink=#000000 topmargin=1 leftmargin=1>
<table width='100%' bgcolor=gray cellpadding=0 cellspacing=0><td>
<table width='100%' cellpadding=0 cellspacing=1>
<tr><td align=center>
    <font color=white size=+1><b>MS SQL WebTools &gt;&gt; Table Structure Viewer</b></font></td>
    <td align=right>
    <font color=black><small><b>written by
    <a href="mailto:little@ivc.tagmet.ru">
    <font color=black><small><b>Alexander Tkalich</b></small></a></b></small></font>
</td></tr>
</table>
</td>
</table>
<p>
<%
var trColor1= "#7f9faf", trColor2= "#bfcfd7";
var trColor= trColor1;

function isDef( Value){
    if( Value== ( Value+ "")) return true;
    return false;
}

function QOutSelect( Conn, Name, Value, FirstName, FirstValue, SQL, SSize){
    var Rs= Conn.Execute( SQL);
    Response.Write( "<select name='"+ Name+ "' size="+ SSize+ ">");
    if( FirstName!= "")
        Response.Write( "<option value='"+ FirstValue+ "'>"+ FirstName);
    for( ; !Rs.EOF; Rs.MoveNext()){
        Id= Rs( 0);
        Nm= Rs( 1);
        if( Value== ""+ Id) S= 'selected'; else S= '';
        Response.Write( "<option value='"+ Id+ "' "+ S+ ">"+ Nm+ "\n");
    }
    Response.Write( "</select>");
}

var S, DbName, TbName, Tbl, Row;
if( !isDef( DbName= Request.Form( "DbName")))
    DbName= Request.QueryString( "DbName");
if( !isDef( TbId= Request.Form( "TbId")))
    TbId= Request.QueryString( "TbId");
Tbl= Request.QueryString( "Tbl");
Row= Request.QueryString( "Row")/ 1;
%>

<center>

<%
var Conn= Server.CreateObject("ADODB.Connection");
Conn.Open( ConnStr, UserLogin, UserPassword);

if( !isDef( Tbl)){
%>

<form name='f' method=post action='TbStru.asp'>
<input type=hidden name=CurrentDb value='<%=DbName%>'>
<table border=1 bgcolor=#7f9faf cellpadding=0 cellspacing=0><td>
<table border=0 cellpadding=8 cellspacing=0><tr valign=bottom><td align=center><b>Databases</b><br>

<%
    QOutSelect( Conn, "DbName' onChange='document.f.submit();", DbName, "", "",
        "select name, name from master.dbo.sysdatabases Order by name", 10);
    Response.Write( '</td>');
    if( isDef( DbName)){
        Response.Write( '<td align=center><b>Tables & Views</b><br>');
        QOutSelect( Conn, "TbId' onChange='document.f.submit();", TbId, '', '',
            "select id, name from "+ DbName+ ".dbo.sysobjects where type in ('U','V') and category<>2 Order By Name", 10);
        Response.Write( '</td>');
    }
    if( isDef( DbName)) S= 'Show structure';
    else S= 'Show list of tables';
    Response.Write(
        "\n<td><table height='100%' border=0>\n"+
        "<tr valign=bottom><td><input type=submit value='"+ S+ "'></td></tr>\n"+
        "</table></td></tr></table></td></table></form><p>\n"
    );
}

if( !isDef( CurrentDb= Request.Form( "CurrentDb")))
    CurrentDb= Request.QueryString( "CurrentDb");
if( !isDef( Tbl)&& isDef( DbName)&& DbName+ ""== CurrentDb+ ""&& isDef( TbId)){
    Rs= Conn.Execute(
            "select O.name, U.name"+
            " from "+ DbName+ ".dbo.sysobjects O, "+
            DbName+ ".dbo.sysusers U"+
            " where O.id="+ TbId+ " and U.uid=O.uid"
    );
    TbName= Rs( 0);
    TbOwner= Rs( 1);
    Response.Write(
        "<a target='_blank' href='TbStru.asp?Tbl=["+ DbName+ "].["+ TbOwner+ "].["+ TbName+ "]&TbId="+ TbId+
        "&DbName="+ DbName+ "'>"+
        "<font color=white><b>"+ DbName+ "."+ TbOwner+ "."+ TbName+ "</b></font></a>\n"
    );
    Response.Write( "<br>\n");
    Rs= Conn.Execute(
            "select C.name, T.name, C.length, C.xdivc, C.xscale,"+
            " C.colstat, C.isnullable,"+
            " case when C.autoval is null then 0 else 1 end,"+
            " SC.text, "+
            "( select CForgin.name+ ' of '+ '<a href=\"TbStru.asp?"+
                "DbName="+ DbName+ "&CurrentDb="+ DbName+
                "&TbName='+ O.name+ '&TbId='+ Convert( varchar, Sr.rkeyid)+ '"+
                "\"><b>'+ O.name+ '</b></a>'"+
                " from "+ DbName+ ".dbo.sysreferences Sr,"+
                DbName+ ".dbo.sysobjects O,"+
                DbName+ ".dbo.syscolumns CForgin"+
                " where Sr.fkeyid="+ TbId+ " and Sr.fkey1=C.colid and Sr.rkeyid=O.id"+
                " and CForgin.id=O.id and CForgin.colid=Sr.rkey1"+
            ") from "+ DbName+ ".dbo.syscolumns C, "+
            DbName+ ".dbo.systypes T, "+
            DbName+ ".dbo.syscomments SC "+
            "where C.id="+ TbId+ " and C.xtype=T.xusertype and C.cdefault*=SC.id "+
            "order by C.colid"
    );
%>
    <input type=hidden name=DbName value='<%=DbName%>'>
    <input type=hidden name=CurrentDb value='<%=DbName%>'>
    <input type=hidden name='TbId' value='<%=TbId%>'>
    <table border=1 bordercolor=#5f5f5f bgcolor=#cfcfcf cellpadding=3 cellspacing=0>
    <tr bgcolor=<%=trColor%>><th>Nn</th><th>Name</th><th>Type</th><th>length</th>
        <th>divcision</th><th>scale</th><th>default value</th><th>properties</th><th>relation</th></tr>
<%
    for( TrColor= '', i= 1; !Rs.EOF; i++, Rs.MoveNext()){
        if( trColor== trColor1) trColor= trColor2;
        else trColor= trColor1;
%>
        <tr bgcolor=<%=trColor%>>
        <td bgcolor=<%=trColor2%> align=right><b><%=i%></b></td><td>&nbsp;
        <%=Rs( 0)%></td>
        <td align=right>&nbsp;<%=Rs( 1)%></td>
        <td align=right>&nbsp;<%=Rs( 2)%></td>
<%
        if( Rs( 1)== 'numeric'

关键词:  SQL  SERVER结构浏览器





Copyright © 2012-2018 三度网教程(http://www.3du8.cn) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版