Results 1 to 9 of 9

Thread: [RESOLVED] [2005] Database tables where I don't know table names

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Resolved [RESOLVED] [2005] Database tables where I don't know table names

    Hi,
    I am trying to figure out how, when I've connected to a database, I can collect all of the tables from that database, and put them into a TreeView, or ListView, or ListBox, or whatever I choose.
    Ideally, I'd like to be able to list the table, and then list all fields within it, and then the field properties (i.e. string, numeric, length, etc. etc. etc.)
    Can anybody point me in the right direction?
    Thanks.

  2. #2
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005] Database tables where I don't know table names

    what type of database are you using? I know in SQL Server you can get the Table names by running this SQL
    Code:
    SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
    As for access or other db's I am not exactly sure.

    EDIT: This SQL will return you all the table, column name and datatype for all tables in the database but once again, this is for SQL server
    Code:
    SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS
    OR for information of a specific table
    Code:
    SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'YOUR_TABLE_NAME'
    Last edited by bmahler; Jul 2nd, 2007 at 11:12 AM.
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  3. #3
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005] Database tables where I don't know table names

    Well, also for access you can get the table list like so
    Code:
    SELECT  Name FROM MSysObjects WHERE (Left([Name],1)<>"~") AND (Left([Name],4) <> "MSys") AND ([Type] In (1, 4, 6)) ORDER BY Name
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Re: [2005] Database tables where I don't know table names

    Thanks for your reply.
    I'm using an Informix database, and I'm presuming that tables aren't identified as being TABLE_NAME - unless I'm doing something wrong - which is possible, I guess

  5. #5
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2005] Database tables where I don't know table names

    Information_Schema is unique to SQL Server only. The metadata for Informix is stored differently.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Re: [2005] Database tables where I don't know table names

    OK - thanks. I'll have to post something on an Informix forum - they must have come across this problem, surely?

  7. #7
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2005] Database tables where I don't know table names

    There is a method. I think you look in the catalog somewhere I just don't use Informix so I can't say where you would look.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  8. #8
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: [2005] Database tables where I don't know table names

    Try "select * from systables". That works on our Informix database.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Re: [2005] Database tables where I don't know table names

    Ahh - thanks guys.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width