+ Reply to Thread
Results 1 to 2 of 2

Thread: Using ODBC to determine column uniqueness & check constraints

  1. #1
    Newbie Tronman is an unknown quantity at this point
    Join Date
    May 2007
    Posts
    10

    Question Using ODBC to determine column uniqueness & check constraints

    Hey folks, at the moment I really don't think this is possible but decided to throw it on here to see if there were any ideas.

    Essentially, I would like a way to grab any 1) arbitrary table (that I have permissions to) in DBMS that I have an ODBC connection too; 2) A column in that table and determine 3) If there are repeated values in that column. and possibly even 4) find check constraints defined in the DDL for that column.

    What I *don't* want to do is check for column uniqueness by doing a query for the column and check manually if there are repeated values by either
    1) looping through to check for duplicates ( O(n^2) time )
    2) Sorting the column and comparing adjacent values ( like O (n^2 log n) I think)

    What I would like an consistent, generic, ODBC-ish (referring to the C API that is) way to extract the meta data for the column to determine if it was declared as Unique in the DDL (I know there could also be unique columns not declared in the DDL as well) which would tell me in constant O(1) time if it's unique regardless of the DBMS I'm using (that is, in ODBC and not though DBMS-specific data dictionary queries). I would also like more meta data (e.g. check constraints) that may have been DDL'd into the column/table, but I'd also be happy for uniqueness. (It did occur to me that I could check FK's to see what they refer to, which would be a candidate key)

    I know about the INFORMATION_SCHEMA views in the ANSI Standard, but there are significant DBMS's that do not support (e.g. Oracle) so it's no good.

    Again, I figure this is a dream, but who knows! Thanks!

  2. #2
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,689
    Blog Entries
    57

    Re: Using ODBC to determine column uniqueness & check constraints

    Using sorts in your queries can help if you only have a few columns to check for uniqueness. Alternately, something like "SELECT COUNT(*) AS COUNTER, COLUMN1, COLUMN2 FROM TABLE GROUP BY COLUMN1, COLUMN2 ORDER BY COUNT(*) DESC" can help out, for a DB that supports that type of query.
    CodeCall Blog | CodeCall Wiki | Shareware
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. ODBC API - Special Table and Column Names
    By Tronman in forum Database & Database Programming
    Replies: 0
    Last Post: 07-30-2007, 12:52 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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