If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Default How to get Table schema information ?

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-12-09, 05:44
amitbora27 amitbora27 is offline
Registered User
 
Join Date: May 2009
Posts: 41
Default How to get Table schema information ?

How can we get the table schema information in MYSQL 5.1.34?

Like we use in ORACLE to get it as:

OCIDescribeAny() // //get the describe handle for the table to be described.

OCIAttrGet() // to get parameter handle

OCIAttrGet() ////get the number of columns in the table
Reply With Quote
  #2 (permalink)  
Old 06-12-09, 06:20
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,298
You can select that information from the INFORMATION_SCHEMA or simply run "SHOW CREATE TABLE"
Reply With Quote
  #3 (permalink)  
Old 06-12-09, 06:24
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,084
Quote:
Originally Posted by amitbora27
How can we get the table schema information in MYSQL 5.1.34?
from the INFORMATION_SCHEMA views

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 06-12-09, 06:58
amitbora27 amitbora27 is offline
Registered User
 
Join Date: May 2009
Posts: 41
Table schema information.

From INFORMATION_SCHEMA I will not get the below information.

I want all the information like colname, datatype, collength, precision, scale, IsNullable.

I think we can write the sub query as

select * from and we fetch it from output of "desc table" query.


How do I achieve this one?
Reply With Quote
  #5 (permalink)  
Old 06-12-09, 07:03
amitbora27 amitbora27 is offline
Registered User
 
Join Date: May 2009
Posts: 41
Re: Change detection in MySQL.
How do I get the Parameter information of table?
I have table like

mysql> desc account;

+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| acct_num | int(11) | NO | PRI | NULL | |
| amount | decimal(2,0) | YES | | NULL | |
+----------+--------------+------+-----+---------+-------+

I want all the information like colname, datatype, collength, precision, scale, Nullable. I tried using the

MYSQL_FIELD *fields;
unsigned int num_fields;

pResult = mysql_store_result(MySQLDB);
num_fields= mysql_num_fields(pResult);
fields = mysql_fetch_fields(pResult);
for( i = 0; i < num_fields; i++)
{
printf("Field %u is %s\n", i, fields[i].name);
}

It is giving me output like :
Field
Type
NULL
KEY
Default

row = mysql_fetch_row(pResult);
it will give me output as :
acct_num

Which I wanted to get.

But other information not gettting like datatype, precision, scale, nullable.

If I fire a query select * from account;It will gives me What I want in fields.
But it is not good if the there are 100 table which has millions of records and I want information of each table.
Is ther any other way to get only the reuqired information?
Reply With Quote
  #6 (permalink)  
Old 06-12-09, 07:29
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
You've already asked this question in this thread and you were given your answer - why waste peoples time (either mine for answering your original question or Rudy's for answering this one)?
Reply With Quote
  #7 (permalink)  
Old 06-12-09, 07:51
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,298
Quote:
Originally Posted by amitbora27
From INFORMATION_SCHEMA I will not get the below information.

I want all the information like colname, datatype, collength, precision, scale, IsNullable.
Yes you will, but you will have to read the documentation.

Here is another hint: check out the COLUMNS
Reply With Quote
  #8 (permalink)  
Old 06-12-09, 09:48
amitbora27 amitbora27 is offline
Registered User
 
Join Date: May 2009
Posts: 41
How do I fetch the output of this query?
mysql> select * from INFORMATION_SCHEMA.COLUMNS where table_name='account');

In coding I run the query using mysql_real_query() whose result is stored in

pResult = mysql_store_result(pMySQLDB);
fields = mysql_fetch_field(pResult);

But in field I get TABLE_SCHEMA, TABLE_NAME that I don't want.
I want the value of these field like "amit, "account".

Can you please tell me how do I fetch the data what I want from the query output?
Reply With Quote
  #9 (permalink)  
Old 06-12-09, 10:13
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,084
Quote:
Originally Posted by amitbora27
Can you please tell me how do I fetch the data what I want from the query output?
stop using the dreaded, evil "select star"
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #10 (permalink)  
Old 06-12-09, 10:18
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,298
Quote:
Originally Posted by amitbora27
Can you please tell me how do I fetch the data what I want from the query output?
What r937 means: by simply listing the columns you want

For details see the manual: http://dev.mysql.com/doc/refman/5.0/en/select.html

Using SELECT * for anything else than ad-hoc queries is a bad idea
Reply With Quote
  #11 (permalink)  
Old 06-16-09, 02:11
amitbora27 amitbora27 is offline
Registered User
 
Join Date: May 2009
Posts: 41
Thanks you very much. I solved my problem.
Reply With Quote
  #12 (permalink)  
Old 06-17-09, 04:54
amitbora27 amitbora27 is offline
Registered User
 
Join Date: May 2009
Posts: 41
How do I get the native data type like we get in ORACLE using

OCIAttrGet(colHandle, OCI_DTYPE_PARAM, (dvoid *) &dataType, 0,
OCI_ATTR_DATA_TYPE, m_errorHandle);

It will return &datatype value for:
VARCHAR2 - 1
NUMBER - 2
Date - 12

How do we achieve this in MYSQL 5.1?
Reply With Quote
  #13 (permalink)  
Old 06-17-09, 05:09
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 8,768
I dunno
does the MySQL manual provide any assistance?
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #14 (permalink)  
Old 06-17-09, 05:41
amitbora27 amitbora27 is offline
Registered User
 
Join Date: May 2009
Posts: 41
I saw in manual but not found any pointer. There is no any point described for native data types value.
Reply With Quote
  #15 (permalink)  
Old 06-17-09, 07:08
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 8,768
what happens if you try to run the following query
Code:
select TABLE_NAME, COLUMN_NAME, DATA_TYPE, NUMERIC_PRECISION, NUMERIC_SCALE, IS_NULLABLE from information_schema.columns;
OK so MySQL doesn't have an integer value describing the column type it returns a text/string/char.. but it does tell you what data type its using. there is no need to work through each data type to find out what internal value the SQL engine is using
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On