tags:

views:

899

answers:

4

I am connecting to a MySQL DB trough a terminal who only have a program with an ODBC connection to a MySQL DB. I can put querys in the program, but not access MySQL directly.

I there a way to query the DB to obtain the list of fields in a table other than

select * from table

??

(don't know why but the select returns a error)

+1  A: 
describe *tablename*
Sebastian Hoitz
This time don't work: error: You have an error in your SQL syntax
Eduardo Molteni
It is "describe tablename"
Eduardo Molteni
Sebastian: please correct the answer so I can mark it as answered
Eduardo Molteni
Ok, it's corrected. Sorry, I was too quick ;)
Sebastian Hoitz
+3  A: 
SELECT
  COLUMN_NAME
FROM
  INFORMATION_SCHEMA.COLUMNS
WHERE
  TABLE_NAME       = 'MyTable'
  AND TABLE_SCHEMA = 'SchemaName'  /* added upon Bill Karwin's comment (thanks) */

More info on INFORMATION_SCHEMA is in the docs.

Tomalak
Yes, but you should also restrict the query to the desired schema.
Bill Karwin
True. I'll add that.
Tomalak
+1  A: 

This works on most databases:

select * from table where 1=0

You get no data in the result set but you do get the column metadata.

Chris Nava
You are right, because the error that I mention in the question was in a invalid character in a field.
Eduardo Molteni
A: 

This:

SHOW COLUMNS FROM Tablename

lists the fields in a table and their properties (data type, whether null values are allowed, whether the field is a primary key, the default value if one has been set, etc.)

Waggers