MSSQL Help

Tim Golden tim.golden at viacom-outdoor.co.uk
Tue Mar 23 03:39:14 EST 2004


>I would like to use Python (2.3.3 on Windows 2000 
>"Professional") to access
>a MSSQL Server and list all of the available databases, as well as the
>tables in each database and columns in each table for an 
>automated test tool
>I am designing.  I have used the MSSQL module many times in 
>the past for
>Inserting, Updating, and Selecting data from various 
>databases, but have
>never mined for metadata like this before.  Is it possible 
>and, if so, how?

The simple answer is: query the data dictionary, either via the
INFORMATION_SCHEMA schema:

  SELECT * FROM INFORMATION_SCHEMA.TABLES

  or

  SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'blah'

or via the (lower level) sys... views (sysobjects etc.). You can find the
info in the SQL Server help. Then just use the Python module as you would to
query any other table.

If you need more concrete examples, let me know. I have a set of modules
which do this kind of thing. But really, it's quite straightforward.

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________




More information about the Python-list mailing list