Professional Web Applications Themes

Select Primary Key - Coldfusion Database Access

Hi Is there any way to select Primary key from table . If you do not know your primary key. I mean can we make any condition or check in which select statement will only select the primary key. Thanks Jon...

  1. #1

    Default Select Primary Key

    Hi

    Is there any way to select Primary key from table . If you do not know your
    primary key. I mean can we make any condition or check in which select
    statement will only select the primary key.

    Thanks
    Jon

    akcreative Guest

  2. #2

    Default Re: Select Primary Key

    In some databases you can find out the primary key by querying the system tables, assuming you have permission to do so. The specifics are db dependent.
    Dan Bracuk Guest

  3. #3

    Default Re: Select Primary Key

    Hi

    I can see many System tables in my database. Can you please give me an example. That will help me alot. Thanks, Jon
    akcreative Guest

  4. #4

    Default Re: Select Primary Key

    On a philosophical note, it seems to me that if you don't know enough about
    your data model / database / schema to know what your keys are, then you
    probably shouldn't be doing any queries until you do. Kind of like hunting in a
    cave without a flashlight.

    Phil

    paross1 Guest

  5. #5

    Default Re: Select Primary Key

    Thanks alot for your help.

    I am using SQL server. Actually I am trying to create a CFC that will check
    the database dependency. I know my databse well. But I am trying to create a
    tree relationship of database programically

    Thanks Jon

    akcreative Guest

  6. #6

    Default Re: Select Primary Key

    You may want to take a look at SQL Server Books online (BOL) and research
    Catalog Functions.

    For example:

    SQLPrimaryKeys uses the catalog stored procedure sp_pkeys to report primary
    key participants from a table. Though a table may have a column or columns that
    can serve as unique row identifiers, tables created without a PRIMARY KEY
    constraint return an empty result set to SQLPrimaryKeys. The ODBC function
    SQLSpecialColumns reports row identifier candidates for tables without primary
    keys.

    Phil



    paross1 Guest

  7. #7

    Default Re: Select Primary Key

    hi

    did not have any clue how can i use SQLPrimaryKeys

    thanks
    akcreative Guest

  8. #8

    Default Re: Select Primary Key

    I take it that you don't have access to BooksOnLine? It is free to download
    from Microsoft, and you would be well advised to do so.

    You could look at your sysconstraints table, but then you get into table IDs
    and column IDs and status flags, etc. Not much help without a roadmap.

    Phil

    paross1 Guest

  9. #9

    Default Re: Select Primary Key

    Paross1 is right. Books Online and a little of sweat. Anyway, a little help
    this time :

    SELECT kcu.table_name,kcu.column_name
    FROMinformation_schema.TABLE_CONSTRAINTS
    tc,information_schema.KEY_COLUMN_USAGE kcu
    WHERE tc.constraint_type='PRIMARY KEY' AND
    tc.CONSTRAINT_NAME=kcu.CONSTRAINT_NAME

    Regards

    Sojovi Guest

Similar Threads

  1. Primary Scratch & Windows Primary Paging file?
    By Tommy Oberst in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 14
    Last Post: April 15th, 10:26 PM
  2. Replies: 0
    Last Post: September 19th, 02:19 AM
  3. Replies: 0
    Last Post: September 11th, 11:26 AM
  4. Replies: 0
    Last Post: September 11th, 12:19 AM
  5. Replies: 0
    Last Post: April 15th, 01:22 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139