Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mySQL Table Metadata

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
Is it possible to store metadata for each field natively on mySQL?

I need to store some text properties (madatory, defaultvalue etc.) associated with mySQL fields.

Thanks,

Michael42
 
"mandatory" can be inferred from setting the "not null" property of a field.

"default value" can be inferred from the "default" property of a field.

For other metadata there is no method for storing the information in MySQL as a part of the table itself.

Want the best answers? Ask the best questions: TANSTAAFL!
 
sleipnir214,

Thanks for responding - you are correct.
1. Can you test ifor a required field from PHP? Do you have a snippet? :)
2. Also, how can you extract the default mySQL value to PHP?

This is where I am headed (I am new to PHP).

If not I'd like to handle these at the PHP level also adding some others (Title, ControlType, onLister, onForm etc.).

In short, I am playing with creating a RAD app for PHP.


Thanks again,

Michael42
 
From PHP, you can simply issue a query like:

DESCRIBE tablename

which will then return data similar to:

Code:
+-----------+------------------+------+-----+---------+----------------+
| Field     | Type             | Null | Key | Default | Extra          |
+-----------+------------------+------+-----+---------+----------------+
| id        | int(10) unsigned |      | PRI | NULL    | auto_increment |
| lastname  | varchar(10)      | YES  |     | NULL    |                |
| firstname | varchar(10)      | YES  |     | NULL    |                |
| thedate   | date             | YES  |     | NULL    |                |
| isAlive   | set('Y','N')     | YES  |     | Y       |                |
+-----------+------------------+------+-----+---------+----------------+

This data is manipulated just like any other SELECT query you might issue.

Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top