Click here to Skip to main content
15,881,027 members
Articles / Programming Languages / ASP

Online DB Administration

Rate me:
Please Sign up or sign in to vote.
3.88/5 (16 votes)
17 Mar 2003 235.9K   2.5K   58  
Online administration of your database. Create or modify tables, keys, and indexes. Edit or insert data.
<%@language=javascript%>
<!--#include file=common.asp-->
<!--#include file=b.func.asp-->
<%
	function GetRecordCount(sTable) {
		var sql, nRecords;
		
		if(IsJet(Object.Conn))
			sql = 'select count(1) from [' + sTable + ']';
		else
			sql = 'select count(1) from "' + sTable + '"';
		
		var rs = Object.Conn.Execute(sql);
		nRecords = rs(0).Value;
		rs.Close();
		rs = null;
		return nRecords;
	}

	function Content() {
		var oCat = Server.CreateObject("ADOX.Catalog");
		var bViews = false;
  		oCat.ActiveConnection = Object.Conn;

		var rsKeys = Object.Conn.OpenSchema(adSchemaForeignKeys);

		Out('<table class="list" cellspacing="0" cellpadding="0">\n');
		Out('<tr><th colspan="4">Tables</th><th>Commands</th><th>Records</th><th>Created</th><th>Modified</th><th>References</th><th>Referenced By</th></tr>\n');
  		for(var e = new Enumerator(oCat.Tables);!e.atEnd();e.moveNext()) {
  			var sRef = '';
  			var sRefBy = '';
  		
  			var oTable = e.item();
  			if(oTable.Type=="VIEW") bViews = true;
  			if(oTable.Type!="TABLE") continue;

			// Find references and referenced by
			if(rsKeys.RecordCount>0) {
				rsKeys.MoveFirst();
				while(!rsKeys.EOF) {
					if(rsKeys("FK_TABLE_NAME").Value == oTable.Name)
						sRef += rsKeys("PK_TABLE_NAME").Value + ' ';
					rsKeys.MoveNext();
				}

				rsKeys.MoveFirst();
				while(!rsKeys.EOF) {
					if(rsKeys("PK_TABLE_NAME").Value == oTable.Name)
						sRefBy += rsKeys("FK_TABLE_NAME").Value + ' ';
					rsKeys.MoveNext();
				}
			}
			
			if(!sRef.length) sRef = '&nbsp;';
			if(!sRefBy.length) sRefBy = '&nbsp;';
	  					
			Out('<tr valign="top">\n');
			Out('<td><img src="images/table.gif" align="absmiddle"/>&nbsp;<a href="data.asp?table='+oTable.Name+'">' + oTable.Name + '</a></td>\n');
			Out('<td><a href="columns.asp?table='+oTable.Name+'">Columns</a></td>\n');
			Out('<td><a href="indexes.asp?table='+oTable.Name+'">Indexes</a></td>\n');
			Out('<td><a href="keys.asp?table='+oTable.Name+'">Keys</a></td>\n');
			Out('<td><a href="javascript:TruncateTable(\''+oTable.Name+'\')">Truncate</a>');
			Out(' | <a href="csv.asp?table='+oTable.Name+'">CSV</a>');
			Out(' | <a href="javascript:DropTable(\''+oTable.Name+'\')">Drop</a></td>\n');
			Out('<td align="right">'+GetRecordCount(oTable.Name)+'</td>\n');
			Out('<td>'+jsFormatDateTime(oTable.DateCreated,2)+'</td>\n');
			Out('<td>'+jsFormatDateTime(oTable.DateModified,2)+'</td>\n');
			Out('<td>'+sRef+'</td>\n');
			Out('<td>'+sRefBy+'</td>\n');
			Out('</tr>');
  		}
  		Out('<tr><td colspan="10"><a href="createtable.asp">Create a new table</a></td></tr>\n');
  		Out('</table>\n');

		rsKeys.Close();
		rsKeys = null;
  		oCat = null;
  		
		Out('<br>');
		Out('<table class="list" cellspacing="0" cellpadding="0">\n');
		Out('<tr>\n');
  		Out('<td>&nbsp;<a href="list_views.asp">Views</a>&nbsp;</td>\n');
  		//Out('<td>&nbsp;<a href="list_procs.asp">Procedures</a>&nbsp;</td>\n');
  		//Out('<td>&nbsp;<a href="list_users.asp">Users</a>&nbsp;</td>\n');
  		Out('<td>&nbsp;<a href="schema.asp">Schemas</a>&nbsp;</td></tr>\n');
  		Out('</table>\n');
	}

	PageSetup();
	NewPageHeader();
	Content();
	NewPageFooter();
	PageCleanup();
%>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Norway Norway
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions