Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » General » Downloads
 
Add your own
alternative version

Online DB Administration

, 17 Mar 2003
Online administration of your database. Create or modify tables, keys, and indexes. Edit or insert data.
<%@language=javascript%>
<!--#include file=common.asp-->

<script language="javascript" runat="server">
var	sLines;

function AddLine(sLine) {
	if(''+sLines=='undefined') sLines = '';
	sLines += '\n' + sLine;
}
function EndLine() {
	Out('<html><head><sc'+'ript type="text/javascript">');
	Out('\nfunction _onload() {');
	Out(sLines);
	Out('\n}');
	Out('\n</sc'+'ript></head><body onload="_onload()"></body></html>');
	PageCleanup();
	Response.End();
}
</script>
<%
	PageSetup();
	Response.Buffer = true;

	if(Request.QueryString("c").Count==1) {
		var oConn;
		var nID;
		var rs;
	
		switch(Request.QueryString("c").Item - 0) {
		case 11: // drop table
			if(Request.QueryString("table").Count==1) {
				var sTable = Request.QueryString("table").Item;
				var sql;

				try {
					if(IsJet(Object.Conn))
						sql = 'drop table [' + sTable + ']';
					else
						sql = 'drop table "' + sTable + '"';
					Object.Conn.Execute(sql);
				}
				catch(e) {
					AddLine('alert("'+e.description+'");');
					EndLine();
				}
				AddLine('alert("'+sTable+' was dropped.");');
				AddLine('parent.location.reload(true);');
				EndLine();
			}
			break;
		case 12: // truncate table
			if(Request.QueryString("table").Count==1) {
				var sTable = Request.QueryString("table").Item;
				var sql;

				try {
					if(IsJet(Object.Conn))
						sql = 'delete from [' + sTable + ']';
					else
						sql = 'delete from "' + sTable + '"';
					Object.Conn.Execute(sql);
				}
				catch(e) {
					AddLine('alert("'+e.description+'");');
					EndLine();
				}
				AddLine('alert("'+sTable+' was truncated.");');
				AddLine('parent.location.reload(true);');
				EndLine();
			}
			break;
		case 13: // drop index
			if(Request.QueryString("table").Count==1 && Request.QueryString("index").Count==1) {
				var sTable = Request.QueryString("table").Item;
				var sIndex = Request.QueryString("index").Item;

				var oCat = Server.CreateObject("ADOX.Catalog");
				oCat.ActiveConnection = Object.Conn;

				try {
					oCat.Tables(sTable).Indexes.Delete(sIndex);
					oCat.Tables(sTable).Indexes.Refresh();
				}
				catch(e) {
					AddLine('alert("'+e.description+'");');
					EndLine();
				}
				AddLine('alert("'+sTable+'.'+sIndex+' was dropped.");');
				AddLine('parent.location.reload(true);');
				EndLine();
			}
			break;
		case 14: // drop key
			if(Request.QueryString("table").Count==1 && Request.QueryString("key").Count==1) {
				var sTable = Request.QueryString("table").Item;
				var sKey = Request.QueryString("key").Item;
				var sql;
				
				if(IsJet(Object.Conn)) {
					sql = 'alter table [' + sTable + '] drop constraint [' + sKey + ']';
				} else {
					sql = 'alter table "' + sTable + '" drop constraint "' + sKey + '"';
				}

				try {
					Object.Conn.Execute(sql);
				}
				catch(e) {
					AddLine('alert("'+e.description+'");');
					EndLine();
				}
				AddLine('alert("'+sTable+'.'+sKey+' was dropped.");');
				AddLine('parent.location.reload(true);');
				EndLine();
			}
			break;
		case 15: // drop column
			if(Request.QueryString("table").Count==1 && Request.QueryString("column").Count==1) {
				var sql;
				var err = '';
			
				var sTable = Request.QueryString("table").Item;
				var sColumn = Request.QueryString("column").Item;

				if(IsJet(Object.Conn))
					sql = 'alter table [' + sTable + '] drop column [' + sColumn + ']';
				else
					sql = 'alter table "' + sTable + '" drop column "' + sColumn + '"';

				try {
					Object.Conn.Execute(sql);
				}
				catch(e) {
					AddLine('alert("'+e.description+'");');
					EndLine();
				}
				AddLine('alert("'+sTable+'.'+sColumn+' was dropped.");');
				AddLine('parent.location.reload(true);');
				EndLine();
			}
			break;
		case 16: // drop view
			if(Request.QueryString("table").Count==1) {
				var sTable = Request.QueryString("table").Item;
				var sql;

				try {
					if(IsJet(Object.Conn))
						sql = 'drop view [' + sTable + ']';
					else
						sql = 'drop view "' + sTable + '"';
					Object.Conn.Execute(sql);
				}
				catch(e) {
					AddLine('alert("'+e.description+'");');
					EndLine();
				}
				AddLine('alert("'+sTable+' was dropped.");');
				AddLine('parent.location.reload(true);');
				EndLine();
			}
			break;
		default:
			Out('Unknown command ' + Request.QueryString("c").Item);
			PageCleanup();
			Response.End();
			break;
		}
	}
%>

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

Share

About the Author

Bjornar Henden
Web Developer
Norway Norway
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 18 Mar 2003
Article Copyright 2002 by Bjornar Henden
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid