PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Logiciels d'hébergement > mailing.database.mysql > Creating my own Data dictionary
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Creating my own Data dictionary

Réponse
 
LinkBack Outils de la discussion
Vieux 22/04/2006, 02h48   #1
Matt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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

  Réponse avec citation
Vieux 22/04/2006, 03h52   #2
Gordon Burditt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Creating my own Data dictionary

>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_schema.

>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_schema.COLUMNS
where TABLE_SCHEMA='database name' and TABLE_NAME='Vehicles';

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

Gordon L. Burditt
  Réponse avec citation
Vieux 22/04/2006, 09h25   #3
Jeff North
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Creating my own Data dictionary

On Sat, 22 Apr 2006 01:48:23 GMT, in mailing.database.mysql Matt
<matsonusaNOSPAM@yahoo.com>
<sm2j429f3onm05b6em7hfv5svnmu8umfb7@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 ".$AppDatabase;
$result = mysql_query( $sql );
$ctr=1;
while ($row = mysql_fetch_row($result))
$TblArr[$ctr++] = $row[0];

mysql_free_result($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_array($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_array($res2) )
{
if( $Indices != "" ) $Indices .= "<br />";
$Indices .= $i["Column_name"]." => ".$i["Key_name"];
}

//--- now store into database as first record for this table def
$sql2 = "INSERT INTO ".$AppDatabase."_tbldefs
(TableName,OrderNbr,Indices,TblComment) VALUES
('".$TblArr[$row]."',0,\"".$Indices."\",\"".$tblComment."\")";
$res2 = mysql_query( $sql2 );
$ct = 1;
while ($i = mysql_fetch_array($result))
{
$sql2 = "INSERT INTO ".$AppDatabase."_tbldefs
(TableName,OrderNbr,FieldName,DataType,AllowNull,i sKey,DefaultValue,Extras)
VALUES ('".$TblArr[$row]."',".$ct.",\"".$i[0].
"\",\"".$i[1].
"\",\"".$i[2].
"\",\"".$i[3].
"\",\"".$i[4].
"\",\"".$i[5].
"\")";
$result2 = mysql_query( $sql2 );
$ct++;
}
}
mysql_free_result($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
---------------------------------------------------------------
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h06.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10366 seconds with 11 queries