473,591 Members | 2,899 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Automatically detecting tables in a db


Is it possible to write a script that, when provided with a database,
it will return all the tables names?

I will go onto try and put together a script that will not only output
the table names but also output the sql code required to CREATE the
table (i.e. CREATE TABLE example (exampleid auto_increment not null
primary key integer, name text, email text);) - Is this pretty simple
to do? Are there any free scripts online that would do this? Cheers


Jul 17 '05 #1
4 1306
bi******@yahoo. co.uk wrote:

Is it possible to write a script that, when provided with a database,
it will return all the tables names?

I will go onto try and put together a script that will not only output
the table names but also output the sql code required to CREATE the
table (i.e. CREATE TABLE example (exampleid auto_increment not null
primary key integer, name text, email text);) - Is this pretty simple
to do? Are there any free scripts online that would do this? Cheers



Yes! The exact script to list the tables in a database depends
on the database you are using. For example in MySQL the script
would include:

$sql1 = "SHOW TABLES";
$res1 - mysql_query($sq l1, $db) or die(ms_err_msg( db,

Following is an example of a create table script. Edit it to
use your table column names and characteristics .
$sql2 = "DROP TABLE IF EXISTS mbr";
$res2 = mysql_query($sq l2, $db) or die(ms_err_msg( $db,
$sql3 = "CREATE TABLE mbr (
email varchar(80) NOT NULL,
uname varchar(32) NOT NULL,
password varchar(32) NOT NULL,
refemail varchar(80),
balance int(11) NOT NULL,
mtype char(1) NOT NULL,
zip varchar(11) NOT NULL,
lastvisit varchar(10),
PRIMARY KEY (email))";
$res3 = mysql_query($sq l3, $db) or die(ms_err_msg( $db,
ms_err_msg is a function that displays a caption, the mysql
error, and closes the database.


Jul 17 '05 #2
Look at

Jul 17 '05 #3
If you're using MySQL check out phpMyAdmin, as it already does what you
want to do:


Jul 17 '05 #4
On Fri, 01 Jul 2005 06:56:35 -0700, bissatch wrote:
Is it possible to write a script that, when provided with a database,
it will return all the tables names?


JDS | je*****@example .invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Alan | last post by:
Hi there, Are there Excel charting gurus here?? If so then please read on... Sorry for the cross-post but I'm not familiar with the Excel groups. I've posted to asp.general because if I have to code a solution to this it'll probably be done in ASP on a web server, unless there's a significantly better way. I'm looking for a way to create over 100 Excel *charts* programmatically.
by: ima | last post by:
I've been studying a great book on css and now that I've put together a few pages using it, I'm finding out that my book needed one more very important chapter. Introducing css in the real world. Obviously, there are a LOT of older browsers still out there that don't support css and some newer one's that still don't support it very well. Knowing that, I have prepared a second set of pages using table layouts for those browsers. It...
by: Uttam | last post by:
Hello, Could someone point me to the syntax required to detected whether a particular table (say tbl1) and a particular Query (Qry1) exists in the catalog? Thank you in advance. Cheers!
by: BlackFireNova | last post by:
I have an existing database, and I need to add another table to it. The database tracks equipment, however I have a need to track ancillary items which are purchased or added to some of the equipment separately. In the existing table there is a serial number field, which is indexed with no duplicates. In the new table there will be multiple entries which must be related to the individual piece of equipment which is entered in the...
by: Sami | last post by:
Please bear with me, and if you answer this question, please do it step by step. I am new at Access, not at all sophisticated. I am using Office XP. This will need to be read in Access for Office 2000. I am creating a database to track student athletes. I have created the following tables. The table title is to the far left, with fields under each. The common field will be the StudentID field, which is their student number assigned...
by: Deano | last post by:
In my app I have lots of forms with data presented in various ways using all kinds of controls. Is there a simple way of detecting if the user has changed any data? I would like to do this so I could set a boolean value to True and then I could use that to modify what is displayed on my reports. In my dim memory is there a dirty property for forms that would do this? Would that always work for every form? Most, if not all, of my...
by: needin4mation | last post by:
Hi, I have an asp.net 1.1 application that populates data from a database. When the user changes data, they have to hit a button to update the data. The data entry form (same form that is populated) is from several different tables. To the user, of course, this is not seen. Scenario: After the page is populated, assume a change is made to the form and the user hits update. The page then goes back, reads the database for that record...
by: Wayne Wengert | last post by:
I am using VB with a Windows NET application. I have a datagrid in which the user can add rows using the "*" row. I want to detect whenever the user has added a row. I found the following code at syncfusion.com but it is in C# and I am having a problem converting it to VB. If anyone can show the VB equivalent and/or point me to a better way to detect a row change I'd appreciate it. Wayne
by: Dean Slindee | last post by:
In my application there is a main form with a tabcontrol. On each page in the tabcontrol is a panel upon which is painted a "sub" form. The main form acts as the "application host", while the subforms are where data values contained in underlying tables are displayed, inserted, updated or deleted. I don't make the user press an "Edit" button to enable the textboxes on the subforms. Rather, the subforms and their textboxes are always...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.