tags:

views:

266

answers:

3

Hi! I want to retrieve these info for a mysql table using c#

1) Complete column definitions including name, size and data type, and extra info like null/not null, unsigned,auto increament, default values, if data type is enum, the accepted values

2) All constraints - Primary/Foreign/Check/Unique

3) All indexes

I can get column related basic info using "describe table_name" query against the database.

but how to fetch all these info?

regards, Anjan

A: 

I think Describe table_name does that. Not sure though.

danish
A: 

You could use the information schema tables.

Mladen Mihajlovic
+1  A: 

Hi,

just throw queries against INFORMATION_SCHEMA...

For example, to get column definitions:

SELECT   TABLE_NAME
       , COLUMN_NAME
       , DATA_TYPE
       , CHARACTER_MAXIMUM_LENGTH
       , CHARACTER_OCTET_LENGTH 
       , NUMERIC_PRECISION 
       , NUMERIC_SCALE AS SCALE
       , COLUMN_DEFAULT
       , IS_NULLABLE
FROM INFORMATION_SCHEMA.COLUMNS

Take a look at the information schema tables to get additional info.

Hope it helps.

JAG
Didn't even realize that i haven't selected this as Correct answer as i used this info and applied it. Sorry :)
anjan