Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2005
    Posts
    15

    Unanswered: Does MySQL allow user defined table attributes?

    I have been using MySQL for a while now and for some reason have always been under the impression that it is good practice to use the same style of names for fields as you would for program variables (eg date_last_updated). I'm not sure where I got this idea or if it is correct. I guess it makes queries easier to write and shorter in length. Anyway, doing things this way usually means that when you use PHP to generate htlml to show the contents of a table, you end up having to add "nice" column names (such a "Date last updated") as you can't rely on the actual fields names being easily understood by people viewing the report.

    This made me wonder whether MySQL had anywhere else you could store the plain english heading names on the tables. Maybe user defined attributes or meta data or something.

    Can anyone advise?
    TIA.

  2. #2
    Join Date
    Jan 2008
    Location
    Kingdom of Sweden
    Posts
    11
    Why not use aliases in the queries?

    SELECT date_last_updated AS 'Date last updated' FROM table;

  3. #3
    Join Date
    Jan 2005
    Posts
    15
    Thank you for your suggestion.

    I think it would have been more helpful if I had put my query in context.

    I am trying to use the gridEditor in the Extjs javascript library to show my tables and would like to build JSON object literals for it which contain this sort of information.

    I think maybe using long field names may be the solution for me since I also want to know the field width and data type too, and I just discovered "SHOW COLUMNS FROM myTable" which will give me all of these.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    you have just discovered SHOW?

    have a look at the INFORMATION_SCHEMA views, they will knock your socks off
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •