views:

25

answers:

3

Is it possible to recieve only the structure of the table even if its emtpy and put the field names in an array. if so wich sql command makes that possible.

thanks Matthy

A: 

In Oracle and MySQL, this SQL query will give you the details of the table, including columns and column types:

describe table_name

This may or may not work in other databases.

Aaron
+2  A: 

If you are using MySQL 5.0 or later, you can get the field names from the INFORMATION_SCHEMA.COLUMNS table.

Something like

SELECT COLUMN_NAME
FROM COLUMNS
WHERE TABLE_NAME = <table_name>

Here is a link to a list of tables in the INFORMATION_SCHEMA database.

danben
+1, The `FROM` clause could be written as `FROM INFORMATION_SCHEMA.COLUMNS` and note that <table_name> is a string, for example 'Table1'.
Mark Byers
hmmm cant get it to work :/ can someone give a good example if lets just say my table name is 'vraag'?
matthy
A: 

thanks for the link the awnser is for example table 'vraag'

SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'vraag'
matthy