开发者

How to get a list of a table's field names?

If MySQL were rationally designed, I would be able to select from a describe table operation's results.

But that doesn't seem to work. So how 开发者_高级运维can I get a list of a table's field names?


Take a look at the INFORMATION_SCHEMA COLUMNS table.

SELECT COLUMN_NAME
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE table_name = 'YourTableName'


MySql DDL: "show fields in myTableName"

Edit - as requested from comment:
DDL (Data Definition Language): In the MySql Administrator, open a Query Browser window and select your database. Then enter the command above. Results will provide:

Field (fieldname)
Type Null (allowed, yes or no)
Key Default (value)
Extra *(auto_increment, etc.)*

Executing this statement in .Net can result in a DataTable with all of these values. If you only require one of the fields, then you need to use the more explicit DDL described by @Joe Stefanelli.


Perhaps this

select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='my_table' and TABLE_SCHEMA='my_database';

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜