欢迎光临
我们一直在努力

源码推荐——SQL SERVER结构浏览器

建站超值云服务器,限时71元/月

从老外那儿转帖过来的

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

<%@ 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 >> 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.xprec, 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>precision</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>

<%=rs( 0)%></td>

<td align=right> <%=rs( 1)%></td>

<td align=right> <%=rs( 2)%></td>

<%

if( rs( 1)== numeric|| rs( 1)== decimal){

prec= rs( 3);

scale= rs( 4);

} else prec= scale= ;

colstat= "";

if( rs( 7)== 1) colstat+= ", identity";

if( rs( 5)== 1) colstat+= ", primary key";

if( rs( 6)== 1) colstat+= ", nullable";

if( colstat== "")

colstat= " ";

else

colstat= colstat.substring( 2);

cdefault= rs( 8);

if( !isdef( cdefault)) cdefault= " ";

else {

cdefault= ""+ cdefault;

cdefault= cdefault.substring( 1, cdefault.length- 1);

}

foreign= rs( 9);

if( !isdef( foreign)) foreign= " ";

%>

<td align=right><%=prec%></td><td><%=scale%></td>

<td><%=cdefault%></td><td><%=colstat%></td><td><%=foreign%></td>

</tr>

<%

}

%>

</table>

<%

}

if( isdef( tbl)){

response.write( "<font color=white><b>"+ tbl+ "</b></font></a><br>\n");

rs= conn.execute( "select count( *) from "+ tbl);

recordcount= rs( 0);

response.write( "<font color=white>"+ recordcount+ " records total</font><br>");

rs= conn.execute( "select * from "+ tbl);

if( !isdef( row))

row= 0;

if( !rs.eof)

rs.move( row);

%>

<table bgcolor=#9fbfcf border=1 cellpadding=1 cellspacing=0><tr bgcolor=#cfcfcf><th>n/n</th>

<%

var colcount= rs.fields.count;

for( i1= 0; i1< colcount; i1++)

response.write( "<th>"+ rs.fields( i1).name+ "</th>");

response.write( "</tr>\n");

prev= row- pgsize;

if( prev< 0&& row> 0) prev= 0;

for( i= row+ 1, cntr= 0;

cntr< pgsize&& !rs.eof;

rs.movenext(), i++, cntr++

){

if( trcolor== trcolor1) trcolor= trcolor2;

else trcolor= trcolor1;

%>

<tr bgcolor=<%=trcolor%>>

<td bgcolor=<%=trcolor2%> align=right><b><%=i%></b></td>

<%

for( i1= 0; i1< colcount; i1++)

response.write( "<td>"+ rs.fields( i1).value+ "</td>");

response.write( "</tr>\n");

}

if( cntr> 0){

response.write( "<tr bgcolor=#cfcfcf><th>n/n</th>");

for( i1= 0; i1< colcount; i1++)

response.write( "<th>"+ rs.fields( i1).name+ "</th>");

response.write( "</tr>\n");

}

response.write( "</table>\n<table width=50% border=0>");

if( prev>= 0){

qs= new string( request.querystring);

prev= qs.substring( 0, qs.lastindexof( "=")+ 1)+ prev;

response.write( "<td><a href=tbstru.asp?"+ prev+ "><font color=white><b><< previous</a> </b></font></td>\n");

}

if( !rs.eof){

qs= new string( request.querystring);

if( qs.lastindexof( "&row=")+ 1)

next= qs.substring( 0, qs.lastindexof( "=")+ 1)+ ( i- 1);

else

next= qs+ "&row="+ ( i- 1);

response.write( "<td align=right><a href=tbstru.asp?"+ next+ "><font color=white><b>next >></b></font></a></td>\n");

}

response.write( "</table>");

}

%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 源码推荐——SQL SERVER结构浏览器
分享到: 更多 (0)