Results 1 to 12 of 12

Thread: list database and related table in Teradata

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,932

    list database and related table in Teradata

    I need a code in VB6 to list all database and related table is possible?
    I prefere adodb or other to have the result.
    Tks.

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: list database and related table in Teradata

    If you are looking for something that lists the database names and the tables for each database. Yes. If that is what you want, I'll send an example.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,932

    Re: list database and related table in Teradata

    Quote Originally Posted by SamOscarBrown View Post
    If you are looking for something that lists the database names and the tables for each database. Yes. If that is what you want, I'll send an example.
    Exactlly that!
    Send me, now or post in the forum.
    Tks

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: list database and related table in Teradata

    Here is how to find the tables names:
    Code:
    Private Sub Command1_Click()
    Dim tbl As New ADOX.Table
    Dim cat As New ADOX.Catalog
    Dim adoConn As New ADODB.Connection
    Dim strConString$
        strConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\myDB.mdb;"
        adoConn.Open strConString
        
        Set cat.ActiveConnection = adoConn
        For Each tbl In cat.Tables
            'exclude system tables
            If InStr(1, LCase(tbl.Name), "msys") = 0 Then
                List1.AddItem tbl.Name
            End If
        Next tbl
        
        adoConn.Close
        Set adoConn = Nothing
        Set cat = Nothing
        Set tbl = Nothing
    End Sub
    Field names examples follows in a bit

  5. #5
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: list database and related table in Teradata

    And you can use this example to find the field names of each table (run it as many times as you have tables---could put in a loop)

    Code:
    Private Sub Command2_Click() 'Get table field names
    List2.Clear
     Dim rs As New Recordset
        Set cnn = New ADODB.Connection
          With cnn
           .Provider = "Microsoft.Jet.OLEDB.4.0"
           .ConnectionString = "User ID=Admin;password=;" & " Data Source=" & App.Path & "\myDB.mdb;"
           .CursorLocation = adUseClient
           .Open
          End With
        Set cmd = New ADODB.Command
        Set cmd.ActiveConnection = cnn
        cmd.CommandText = "select * from test"
        Set rs = cmd.Execute
        For X = 0 To rs.Fields.Count - 1
           List2.AddItem (rs.Fields(X).Name)
        Next X
    End Sub

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: list database and related table in Teradata

    I didn't close all in second example when completed....but you should...:-)

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,932

    Re: list database and related table in Teradata

    Quote Originally Posted by SamOscarBrown View Post
    I didn't close all in second example when completed....but you should...:-)
    Hummmmm....
    but i need code for Teradata not for Access mdb.

  8. #8
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: list database and related table in Teradata

    Lo siento.....mea culpa....sorry.....I don't know of Teradata.....what have you found on Google/Bing?

  9. #9
    gibra
    Guest

    Re: list database and related table in Teradata

    Quote Originally Posted by luca90 View Post
    Hummmmm....
    but i need code for Teradata not for Access mdb.
    The sample code posted by SamOscarBrown is right, because it's 'indipendent' from database you use.
    The only thing you have to change is the ConnectionString and the Provider parameters.

    For more info about Teradata database see here:
    http://www.connectionstrings.com/teradata

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,932

    Re: list database and related table in Teradata

    Quote Originally Posted by SamOscarBrown View Post
    Here is how to find the tables names:
    Code:
    Private Sub Command1_Click()
    Dim tbl As New ADOX.Table
    Dim cat As New ADOX.Catalog
    Dim adoConn As New ADODB.Connection
    Dim strConString$
        strConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\myDB.mdb;"
        adoConn.Open strConString
        
        Set cat.ActiveConnection = adoConn
        For Each tbl In cat.Tables
            'exclude system tables
            If InStr(1, LCase(tbl.Name), "msys") = 0 Then
                List1.AddItem tbl.Name
            End If
        Next tbl
        
        adoConn.Close
        Set adoConn = Nothing
        Set cat = Nothing
        Set tbl = Nothing
    End Sub
    Field names examples follows in a bit
    Tested and it work fine.
    But this code list tha all tables... i need to list also the database into the Teradata server.....(!)

  11. #11
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: list database and related table in Teradata

    If you know (and you should, but I do not) the extension used for a teradata database (like it is .mdb for some versions of MS Access), you can do a IF FILEEXISTS check on the server. Plenty of examples of how to use fileexists on this forum and on GOOGLE.

  12. #12
    gibra
    Guest

    Re: list database and related table in Teradata

    Quote Originally Posted by luca90 View Post
    Tested and it work fine.
    But this code list tha all tables... i need to list also the database into the Teradata server.....(!)
    This is depend by how database are stored.
    Teradata is probably different from SQL Server, Oracle, and so on...
    Therefore, you have to get this information on Teradata web site and/or related forum, support, ...
    just search
    http://forums.teradata.com/forum/dat...ts-in-teradata



    Also, you can read the database schema (not only tables) without ADOX but with ADODB only:
    ADO OpenSchema Method
    http://www.w3schools.com/ado/met_conn_openschema.asp
    Last edited by gibra; Jan 19th, 2013 at 04:25 AM.

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