Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get all details about a mysql table using c#?

Tags:

c#

mysql

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

like image 401
anjan Avatar asked Apr 19 '09 10:04

anjan


People also ask

How do I see all information in MySQL?

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.

How can I get column details of a table in MySQL?

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'.

How will you view all the contents of a table?

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.


1 Answers

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.

like image 62
JAG Avatar answered Oct 08 '22 00:10

JAG