How to pull out the name of the primary key column(s) in a table?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tom Gough
    New Member
    • Sep 2010
    • 1

    #1

    How to pull out the name of the primary key column(s) in a table?

    I have a MS SQL Server Database with about 75 tables on it, and I am trying to insert records into tables if a record with the same primary key doesn't exist, or update if they do.
    I could hard code the primary keys for every table into my vb.net code, but I'd rather not as more tables are to be added at a later date and my code needs to handle this without being changed. Is there a way to pull out the primary key column name(s) from a table using a query so I can loop through each table executing the same code?

    Thanks,
    Tom

    P.S. I am a bit of a newbie when it comes to SQL so if you have the time please be simple and clear with any responses.
  • gpl
    New Member
    • Jul 2007
    • 152

    #2
    I googled, this page looks handy http://social.msdn.mic rosoft.com/Forums/....

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      So is this...

      Happy Coding!!!

      ~~ CK

      Comment

      Working...