Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6

    Unanswered: trying to find non identity primary keys

    This ain't working

    SELECT T.TABLE_NAME,C.COLUMN_NAME
    FROM INFORMATION_SCHEMA.TABLES T
    JOIN INFORMATION_SCHEMA.COLUMNS C
    ON T.TABLE_NAME = C.TABLE_NAME
    WHERE OBJECTPROPERTY(OBJECT_ID(T.TABLE_NAME),
    'TableHasIdentity') = 0
    AND T.TABLE_TYPE = 'BASE TABLE'
    AND OBJECTPROPERTY(OBJECT_ID(C.COLUMN_NAME),'IsPrimary Key') = 1
    ORDER BY T.TABLE_NAME,C.COLUMN_NAME

    This is giving me bogus results...

    SELECT * FROM INFORMATION_SCHEMA.COLUMNS
    WHERE OBJECTPROPERTY(OBJECT_ID(COLUMN_NAME),'IsPrimaryKe y') = 1

    I have PK's all over the place. What gives? Too many cocktails with lunch?
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54

Posting Permissions

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