Simple question: How can I return the field type of a MySQL table. I know about describe
or show column
but I just want to return that single parameter. e.g.:
SELECT fieldtype(mycol) FROM mytable
# should return INT or integer for example
You can get the MySQL table columns data type with the help of “information_schema. columns”. SELECT DATA_TYPE from INFORMATION_SCHEMA. COLUMNS where table_schema = 'yourDatabaseName' and table_name = 'yourTableName'.
Use the asterisk character (*) in place of a column list in a SELECT statement to instruct MySQL to return every column from the specified table.
If you want to select only specific columns, replace the * with the names of the columns, separated by commas. The following statement selects just the name_id, firstname and lastname fields from the master_name table.
You can use
SHOW FIELDS
FROM tableName where Field ='nameOfField'
This will return you result in format of
Field Type Null Key Default Extra
You can get this from the information_schema database:
select data_type
from information_schema.columns
where table_schema = 'myschema'
and table_name = 'mytable'
and column_name = 'mycol'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With