473,574 Members | 18,302 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating my own Data dictionary

Stop me if you've heard this one...

I want to create a "data dictionary" table of all my user tables in a
certain database. The data dictionary (my version) will contain
columns such as "TableName" , "ColumnName ", "DataType", "DataLength ",
etc, etc. I know this information is available in the MySQL engine
tables, I just don't know where to look for it. I'm using 5.0.

Any hints? For example, how do I obtain a list of all the ColumnNames
and data types in a table I created named "Vehicles"?

Thanks!!
Matt

Apr 22 '06 #1
2 4630
>I want to create a "data dictionary" table of all my user tables in a
certain database. The data dictionary (my version) will contain
columns such as "TableName" , "ColumnName ", "DataType", "DataLength ",
etc, etc. I know this information is available in the MySQL engine
tables, I just don't know where to look for it. I'm using 5.0.
You might be able to do this by creating a view on information_sch ema.
Any hints? For example, how do I obtain a list of all the ColumnNames
and data types in a table I created named "Vehicles"?


select COLUMN_NAME from information_sch ema.COLUMNS
where TABLE_SCHEMA='d atabase name' and TABLE_NAME='Veh icles';

You can also use "describe Vehicles;" in current and older versions of
MySQL, but the format isn't the same.

Gordon L. Burditt
Apr 22 '06 #2
On Sat, 22 Apr 2006 01:48:23 GMT, in mailing.databas e.mysql Matt
<ma************ *@yahoo.com>
<sm************ *************** *****@4ax.com> wrote:
| Stop me if you've heard this one...
|
| I want to create a "data dictionary" table of all my user tables in a
| certain database. The data dictionary (my version) will contain
| columns such as "TableName" , "ColumnName ", "DataType", "DataLength ",
| etc, etc. I know this information is available in the MySQL engine
| tables, I just don't know where to look for it. I'm using 5.0.
|
| Any hints? For example, how do I obtain a list of all the ColumnNames
| and data types in a table I created named "Vehicles"?
|
| Thanks!!
| Matt


I'm using 4.0.19 so there might be better ways for 5.0 version.
Also, I'm a complete novice at php so the code might be better
optimised.
----------------------------------------------------------------
$AppDatabase = "xxxxxxx"; //--- your database
$TblArr = array();

//--- get table names from AppDatabase db
$sql = "SHOW TABLES FROM ".$AppDatab ase;
$result = mysql_query( $sql );
$ctr=1;
while ($row = mysql_fetch_row ($result))
$TblArr[$ctr++] = $row[0];

mysql_free_resu lt($result);

//--- create the table to hold the definitions
$sql = "CREATE TABLE ".$AppDatabase. "_tbldefs (
`id` int(10) unsigned NOT NULL auto_increment,
`TableName` varchar(255) default '',
`OrderNbr` int(10) unsigned default '0',
`FieldName` varchar(255) default '',
`DataType` varchar(255) default '',
`AllowNull` varchar(255) default '',
`isKey` varchar(255) default '',
`DefaultValue` varchar(255) default '',
`Extras` varchar(255) default '',
`FieldComments` varchar(255) default '',
`Indices` text,
`TblComment` varchar(255) default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM";
$result = mysql_query( $sql );

//--- build tblDefs info
for ( $row = 1; $row < sizeof($TblArr) ; $row++ )
{
$sql = "show columns from ".$AppDatabase. ".".$TblArr[$row];
$result = mysql_query( $sql );

//--- get the table comment
$sql2 = "SHOW table STATUS FROM ".$AppDatabase. " like
'".$TblArr[$row]."'";
$res2 = mysql_query( $sql2 );
$i = mysql_fetch_arr ay($res2);
$tblComment = $i["Comment"];

//--- get the indices for the table
$sql2 = "SHOW INDEX FROM ".$AppDatabase. ".".$TblArr[$row];
$res2 = mysql_query( $sql2 );
$Indices = "";
while($i = mysql_fetch_arr ay($res2) )
{
if( $Indices != "" ) $Indices .= "<br />";
$Indices .= $i["Column_nam e"]." => ".$i["Key_name"];
}

//--- now store into database as first record for this table def
$sql2 = "INSERT INTO ".$AppDatabase. "_tbldefs
(TableName,Orde rNbr,Indices,Tb lComment) VALUES
('".$TblArr[$row]."',0,\"".$Indi ces."\",\"".$tb lComment."\")";
$res2 = mysql_query( $sql2 );
$ct = 1;
while ($i = mysql_fetch_arr ay($result))
{
$sql2 = "INSERT INTO ".$AppDatabase. "_tbldefs
(TableName,Orde rNbr,FieldName, DataType,AllowN ull,isKey,Defau ltValue,Extras)
VALUES ('".$TblArr[$row]."',".$ct.",\"" .$i[0].
"\",\"".$i[1].
"\",\"".$i[2].
"\",\"".$i[3].
"\",\"".$i[4].
"\",\"".$i[5].
"\")";
$result2 = mysql_query( $sql2 );
$ct++;
}
}
mysql_free_resu lt($result);
----------------------------------------------------
HTH
---------------------------------------------------------------
I often wish that email had never been invented, but there’s
just no way I can get rid of it. So, day after day, several times
a day, I dutifully delete 99% of the emails I receive, and when
I’m not able to get at my email for a few days, I’ll leave the
machine at home running to pick it up every 10 minutes so I don’t
overflow some capacity somewhere, and just the other day I caught
myself wondering who will clean out my Inbox after I’m dead.

Charles Petzold. October 20, 2005
---------------------------------------------------------------
Apr 22 '06 #3

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

Similar topics

2
4427
by: ben moretti | last post by:
hi i'm learning python, and one area i'd use it for is data management in scientific computing. in the case i've tried i want to reformat a data file from a normalised list to a matrix with some sorted columns. to do this at the moment i am using perl, which is very easy to do, and i want to see if python is as easy. so, the data i am...
4
2770
by: Edvard Majakari | last post by:
Hi, I was wondering what would be the most elegant way for creating a Python class wrapper for a command line utility, which takes three types of arguments: 1. options with values (--foo=bar) 2. boolean options (--squibble) 3. data lines (MUNGE:x:y:z:frob)
2
1565
by: Greg Lindstrom | last post by:
Hello- I have created a class, FixedLengthRecord.py, that allows me to manipulate fixed length records in the routines I write. I recently converted it to read record layouts from an SQL server (it used to read config files) and I am thinking of making another change to make my code cleaner . The heart of the class is a dictionary named...
4
1991
by: Livin | last post by:
I need to dynamically create dictionary names using strings input at the time of creation. These will then be placed into a "Parent" dictionary. I'm new to python, and programming, so please bear with me. here's my initial thought but I don't think it will work... item='Kitchen Ceiling Lights' devDictName = item.replace(' ','+')...
6
5144
by: MikeSwann | last post by:
Dear All, I am trying to decide on to create a collection object for a project that I am working on. I am fairly new to OOP so this may be on the basic side. I have looked on the groups, but can't seem to find the answer I am looking for - just more questions! I want an object to hold Case details, one of the properties of this Case...
7
5495
by: Dale | last post by:
I have a design question. I am creating a custom collection of products. The unique key for the products is productId which is an integer. By default, IndexOf(object obj), when obj is an int, would return the value of obj because it returns the index of the item at position obj. Thoughts I had were to let the default method perform the...
0
1117
by: Greg Corradini | last post by:
Hello All, I'm attempting to create multiple dictionaries at once, each with unique variable names. The number of dictionaries i need to create depends on the length of a list, which was returned from a previous function. The pseudo code for this problem would be: returnedlist = count = 0 for i in returnedlist: if count <...
3
2205
by: JamesB | last post by:
I have a config screen in my app that updates a dictionary<key,value>. I want to store a copy of this before going into the config screen so if the user wants to cancel all their changes I can simply set the working copies to be the backup. So, in my code, before the config screen is shown, I do this: Dictionary<string, myClassTempDic =...
19
8593
by: Dr Mephesto | last post by:
Hi! I would like to create a pretty big list of lists; a list 3,000,000 long, each entry containing 5 empty lists. My application will append data each of the 5 sublists, so they will be of varying lengths (so no arrays!). Does anyone know the most efficient way to do this? I have tried: list = ,,,,] for _ in xrange(3000000)]
0
7817
marktang
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...
0
8081
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
tracyyun
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...
0
6482
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5635
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5322
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...
0
3759
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...
1
2254
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1359
muto222
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.