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
The first command you will need to use is the SELECT FROM MySQL statement that has the following syntax: SELECT * FROM table_name; This is a basic MySQL query which will tell the script to select all the records from the table_name table.
You can get the MySQL table columns data type with the help of “information_schema. columns”. SELECT DATA_TYPE from INFORMATION_SCHEMA. COLUMNS where table_schema = 'yourDatabaseName' and table_name = 'yourTableName'.
There are a number of ways to display the contents of a table, all from the Database Explorer window: click on the table, then either: right-click and select Display. click on the Table > Display Table menu option.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With