Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. retreiving metadata information of s database

retreiving metadata information of s database

Scheduled Pinned Locked Moved Database
databasehelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    padvit
    wrote on last edited by
    #1

    I need to retrieve the primary key column name for the given table. The data given is: Table name The data to be extracted is: primary key column name Can anyone help me out in this

    C 1 Reply Last reply
    0
    • P padvit

      I need to retrieve the primary key column name for the given table. The data given is: Table name The data to be extracted is: primary key column name Can anyone help me out in this

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      You don't specify which database product you are using so I shall assume it is SQL Server 2000.

      SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS ccu
      INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc
      ON tc.CONSTRAINT_NAME = ccu.CONSTRAINT_NAME
      WHERE CONSTRAINT_TYPE='PRIMARY KEY'
      AND tc.TABLE_NAME = 'MyTable'

      This assumes also that there is only one schema (dbo) or that there are no tables with the same name in different schemas. Does this help?


      Do you want to know more? WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums

      P 1 Reply Last reply
      0
      • C Colin Angus Mackay

        You don't specify which database product you are using so I shall assume it is SQL Server 2000.

        SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS ccu
        INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc
        ON tc.CONSTRAINT_NAME = ccu.CONSTRAINT_NAME
        WHERE CONSTRAINT_TYPE='PRIMARY KEY'
        AND tc.TABLE_NAME = 'MyTable'

        This assumes also that there is only one schema (dbo) or that there are no tables with the same name in different schemas. Does this help?


        Do you want to know more? WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums

        P Offline
        P Offline
        padvit
        wrote on last edited by
        #3

        Hi there Thank you very much. Iam using Sybase I have found the solution this command dont work in sybase, it was done in different way.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups