DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Retrieve Primary Key in DB2

  1. #1
    Frost Guest

    Retrieve Primary Key in DB2


    Hi Again….

    How do I determine the Primary Key of a DB2 Table? In SQL Server I can use
    ADOX Like So.

    Dim catDB As ADOX.Catalog
    Dim tblDB As ADOX.Table
    Dim colDB As ADOX.Column
    Dim idxDB As ADOX.Index
    Dim i As Long

    Set catDB = New ADOX.Catalog
    catDB.ActiveConnection = dbConnection

    'Need Way to get Primary key
    For Each idxDB In catDB.Tables(TableName).Indexs
    If idxDB.PrimaryKey then
    sIDX= idxDB.Name
    End If
    Next


    DB2 does not set the Property ‘PrimaryKey’. Is there any other way to retrieve
    the Key in a Table?

    Thanks in Advance….


  2. #2
    manju Guest

    Re: Retrieve Primary Key in DB2



    Hi,
    in SYSCAT.COLUMNS view u will find column KEYSEQ ,that tells about the primary
    key,infact position in the primary key .

    -Manju

    "Frost" <stevef@pedco.com> wrote:
    >
    >Hi Again….
    >
    >How do I determine the Primary Key of a DB2 Table? In SQL Server I can

    use
    >ADOX Like So.
    >
    > Dim catDB As ADOX.Catalog
    > Dim tblDB As ADOX.Table
    > Dim colDB As ADOX.Column
    > Dim idxDB As ADOX.Index
    > Dim i As Long
    >
    > Set catDB = New ADOX.Catalog
    > catDB.ActiveConnection = dbConnection
    >
    >'Need Way to get Primary key
    > For Each idxDB In catDB.Tables(TableName).Indexs
    >If idxDB.PrimaryKey then
    >sIDX= idxDB.Name
    > End If
    > Next
    >
    >
    >DB2 does not set the Property ‘PrimaryKey’. Is there any other way to retrieve
    >the Key in a Table?
    >
    >Thanks in Advance….
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center