tags:

views:

24

answers:

1

Hi,

The question is in the title is clear, I guess.

What/how is the query to check if an attribute in a table existed or not?

I am doing with SQLite.

Thanks in advance.

+1  A: 

You can interrogate the database with PRAGMA table_info(tablename);. That will return the list of column names, their type, nullable or not, and default value.

MPelletier
Hi,Yes, this could be a solution but indirectly of checking the table structure. Would it be a direct solution? Thanks in advance.
JoesyXHN
What other attributes do you mean? Like what is the primary key?
MPelletier
I meant an attribute (column name) of a table.For example: Table A has 3 columns (fields)- ID -> big int- Name -> varchar- DOB -> varcharHow can I check if the field (column) DOB is existed or not?Thanks in advance.
JoesyXHN
`PRAGMA table_info` will return the list of columns, so you can go through them to see if your DOB column is present or not. You can't exactly query SQLite to see if a field exists or not, you have to make that own function yourself in whatever language/platform you use to call SQLite.
MPelletier