{"id":70253,"date":"2005-03-11T11:01:00","date_gmt":"2005-03-11T11:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/03\/11\/how-can-i-delete-a-table-from-a-jet-database\/"},"modified":"2005-03-11T11:01:00","modified_gmt":"2005-03-11T11:01:00","slug":"how-can-i-delete-a-table-from-a-jet-database","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-delete-a-table-from-a-jet-database\/","title":{"rendered":"How Can I Delete a Table from a Jet Database?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! Can I delete a table from a Jet database using a script?<BR><BR>&#8212; AK<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, AK. Of course you can delete a table from a Jet database using a script; after all, you can do <I>anything<\/I> using a script!<\/P>\n<P>Well, OK, maybe not DHCP server stuff. And maybe you can\u2019t change the display resolution of your computer. And maybe not &#8211; well, let\u2019s just say that when it comes to <I>databases<\/I> you can do pretty much anything using a script. Including deleting a table.<\/P>\n<P>Let\u2019s take a look at a script that opens a hypothetical database named Inventory.mdb and then deletes a table named HardwareBackup:<\/P><PRE class=\"codeSample\">Set objCatalog = CreateObject(&#8220;ADOX.Catalog&#8221;)\nSet objConnection = CreateObject(&#8220;ADODB.Connection&#8221;)<\/p>\n<p>objConnection.Open _\n    &#8220;Provider= Microsoft.Jet.OLEDB.4.0; &#8221; &amp; _\n        &#8220;Data Source=inventory.mdb&#8221; <\/p>\n<p>Set objCatalog.ActiveConnection = objConnection\nobjCatalog.Tables.Delete &#8220;HardwareBackup&#8221;<\/p>\n<p>objConnection.Close\n<\/PRE>\n<P>You\u2019re right: there <I>isn\u2019t<\/I> much to it. We begin by creating a pair of object references. The first &#8211; objCatalog &#8211; represents an instance of the ADOX <B>Catalog<\/B> object. (ADOX stands for ActiveX Data Objects Extensions for Data Definition Language and Security &#8211; trying saying <I>that<\/I> three times fast. Or try saying it once without taking a breath.) <\/P>\n<P>ADOX, by the way, is an extension to ActiveX Data Objects (ADO) that enables you to do things like, well, delete tables.<\/P>\n<P>The second object reference &#8211; objConnection &#8211; represents an instance of the ADO <B>Connection<\/B> object; we\u2019ll use this object to open the database Inventory.mdb. That\u2019s what we do here:<\/P><PRE class=\"codeSample\">objConnection.Open _\n    &#8220;Provider= Microsoft.Jet.OLEDB.4.0; &#8221; &amp; _\n        &#8220;Data Source=inventory.mdb&#8221;\n<\/PRE>\n<P>Note that because Inventory.mdb is located in the same folder as our script we didn\u2019t have to specify the entire path.<\/P>\n<P>After we make the connection we assign the objConnection reference to the <B>ActiveConnection<\/B> property of our <B>Catalog<\/B> object; this lets the <B>Catalog<\/B> object know which database to work with. We then use the <B>Delete<\/B> method of the <B>Tables<\/B> collection to delete the table named HardwareBackup:<\/P><PRE class=\"codeSample\">objCatalog.Tables.Delete &#8220;HardwareBackup&#8221;\n<\/PRE>\n<P>That\u2019s all there is to it. We close the connection and go home, another job well done.<\/P>\n<P><B>Disclaimer<\/B>. Ok, so maybe your boss <I>won\u2019t<\/I> let you go home after you run this script. But it never hurts to ask, right?<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! Can I delete a table from a Jet database using a script?&#8212; AK Hey, AK. Of course you can delete a table from a Jet database using a script; after all, you can do anything using a script! Well, OK, maybe not DHCP server stuff. And maybe you can\u2019t change the display [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[19,146,3,5],"class_list":["post-70253","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-activex-data-objects-ado","tag-databases","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! Can I delete a table from a Jet database using a script?&#8212; AK Hey, AK. Of course you can delete a table from a Jet database using a script; after all, you can do anything using a script! Well, OK, maybe not DHCP server stuff. And maybe you can\u2019t change the display [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/70253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=70253"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/70253\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=70253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=70253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=70253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}