473,231 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

How to get database metadata information (i.e. existing tables and columns in tables)

Hi,

Is it possible to retrieve details about the database, specifically a
list of the tables in the database; and then to retrieve the columns
and their types for the tables?

Is this dependant on the database?

Thanks
Chris

Aug 22 '06 #1
5 3263
Chris Brat wrote:
Is it possible to retrieve details about the database, specifically a
list of the tables in the database; and then to retrieve the columns
and their types for the tables?
Yes.
Is this dependant on the database?
Yes.

Real databases usually store meta-data (list of tables, list of columns,
list of indexes aso...) in system tables which can be queried in the same
manner as common tables or view. Just read your database handbook...

HTH
Mathias

Aug 22 '06 #2
Hello Chris,
Is it possible to retrieve details about the database, specifically a
list of the tables in the database; and then to retrieve the columns
and their types for the tables?

Is this dependant on the database?
Yes and Yes. However some toolkits like SQLObject
(http://www.sqlobject.org/) and SQLAlchemy (http://www.sqlalchemy.org/)
can do this work for you (IIRC).

HTH,
Miki
http://pythonwise.blogspot.com/

Aug 22 '06 #3
Thanks for the great feedback.

Chris.
Chris Brat wrote:
Hi,

Is it possible to retrieve details about the database, specifically a
list of the tables in the database; and then to retrieve the columns
and their types for the tables?

Is this dependant on the database?

Thanks
Chris
Aug 22 '06 #4
Chris Brat wrote:
Hi,

Is it possible to retrieve details about the database, specifically a
list of the tables in the database; and then to retrieve the columns
and their types for the tables?

Is this dependant on the database?
As far as locating the field names goes, this should work with most
DBAPI modules:

http://aspn.activestate.com/ASPN/Coo...n/Recipe/81189

thought hat doesn't help wiht getting the table names ...

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Aug 22 '06 #5
If you want to know the names of the fields on a recordset, you can use
cursor.description.
For example, lets say you have a connection to a MySQL database:

con = MySQLdb.connect('localhost','root','','mydb')
cur = con.cursor()
cur.execute('select * from customers')
result = cur.fetchall()

fields = [i[0] for i in cur.description]
....
Description gives a list with information about your recordset, being
the first item the name of the field.

Hope this helps...
Luis

Chris Brat wrote:
Hi,

Is it possible to retrieve details about the database, specifically a
list of the tables in the database; and then to retrieve the columns
and their types for the tables?

Is this dependant on the database?

Thanks
Chris
Aug 22 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: valexena | last post by:
In which table is Oracle database audit information stored? -- Posted via http://dbforums.com
0
by: Michael | last post by:
I apologize if this might be a beginner question, which is clear to the experts. But I could not find a clear answer yet. I have extracted a schema / user with the exp utility. I want to import...
2
by: Mario T. Lanza | last post by:
Greetings, I've been working on a 3-column layout where the center column is of a fixed width (230px wide). The center column must always be 230px and the columns on the right/left (always the...
2
by: tranky | last post by:
Hi.... .....i'd like to know if there's a way to write in a textbox the schema of a database. numbers of tables, tables name, numbers of fields, fields name and other information like fields...
34
by: Karam Chand | last post by:
Hello I have been working with Access and MySQL for pretty long time. Very simple and able to perform their jobs. I dont need to start a flame anymore :) I have to work with PGSQL for my...
2
by: sloan | last post by:
Back in ADO days, it was fairly easy to get the meta data (tablenames, columnnames , etc) .. with all that schema stuff. I have a Access database, that I'd like to get the list of tableNames in...
1
by: Karthik | last post by:
Hi, I have been using GDI+ and Windows Media SDK to get the metadata information for image and audio files respectively. Just incase if someone is not clear as to what I mean by metadata...
2
by: dollyvishal | last post by:
How to get constraint information for MS Access tables using Query?
2
Thekid
by: Thekid | last post by:
I've been working on a project lately that is written in python and I want to incorporate mysql into it. The python code is basically a report writing system in which every report will have it's own...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.