SQL Server Structure Browser

Source: Internet
Author: User
Tags count dsn prev
Reprint from the Foreigner.

Very cool, just modify a few parameters on it, very helpful

<%@ 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;
%>
<meta http-equiv= "Content-type" content= "text/html; Charset=<%=charset%> ">
<title>ms SQL Structure Viewer Version 1.2</title>
<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>
&LT;TR&GT;&LT;TD align=center>
<font color=white size=+1><b>ms SQL webtools >> Table Structure viewer</b></font></td >
&LT;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 are 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%>>
&LT;TD bgcolor=<%=trcolor2%> align=right><b><%=i%></b></td><td>
<%=rs (0)%></td>
&LT;TD align=right> <%=rs (1)%></td>
&LT;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= "";
%>
&LT;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%>>
&LT;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>");
}
%>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.