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

06-12-09, 05:44
|
|
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
|
|

06-12-09, 06:20
|
|
Registered User
|
|
Join Date: Nov 2003
Posts: 2,298
|
|
You can select that information from the INFORMATION_SCHEMA or simply run "SHOW CREATE TABLE"
|
|

06-12-09, 06:24
|
|
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

|
|

06-12-09, 06:58
|
|
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?
|
|

06-12-09, 07:03
|
|
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?
|
|

06-12-09, 07:29
|
|
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)?
|
|

06-12-09, 07:51
|
|
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
|
|

06-12-09, 09:48
|
|
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?
|
|

06-12-09, 10:13
|
|
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"
|
|

06-12-09, 10:18
|
|
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
|
|

06-16-09, 02:11
|
|
Registered User
|
|
Join Date: May 2009
Posts: 41
|
|
Thanks you very much. I solved my problem.
|
|

06-17-09, 04:54
|
|
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?
|
|

06-17-09, 05:09
|
|
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
|
|

06-17-09, 05:41
|
|
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.
|
|

06-17-09, 07:08
|
|
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
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|