is there any SQL command that can return a column name?
like if tables have 4 columns: ID, name, price, qty
i need a function/sql statement that can return those strings (column name) but i never seen this before...
so does it exist in sql?
thanks
Printable View
is there any SQL command that can return a column name?
like if tables have 4 columns: ID, name, price, qty
i need a function/sql statement that can return those strings (column name) but i never seen this before...
so does it exist in sql?
thanks
This depends on what DBMS you're using. For example, I know under Oracle, you can simply say "desc <tablename>" and it will spit out the table structure for you.
I've always been curious if MySQL had some equivilent to that...but I haven't found it.
What exactly are you trying to accomplish?
MySQL has:
describe <tablename>
which also outputs the table info.
MS SQL has quite a few options as well, you can try this
SELECT a.name
FROM syscolumns a
JOIN sysobjects b
ON a.id = b.id
WHERE b.name = '<tablename>'
AND b.type = 'U'
This will give you a list of all the columns in a table.
i'm using Access database and VB for the program