Primary Key finding

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vaani15
    New Member
    • Jun 2007
    • 6

    Primary Key finding

    I am looking for the query that will give me the name of the attribute that is the primary key of the table.
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    DESCRIBE will display the whole table structure and SHOW KEYS will display the keys. The syntax is

    Code:
    DESCRIBE table_name;
    Code:
    SHOW KEYS FROM table_name;

    Comment

    • vaani15
      New Member
      • Jun 2007
      • 6

      #3
      But, i want a query that take table name and return the attribute name having primary key not the any other key..

      Originally posted by mwasif
      DESCRIBE will display the whole table structure and SHOW KEYS will display the keys. The syntax is

      Code:
      DESCRIBE table_name;
      Code:
      SHOW KEYS FROM table_name;

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, vaani.

        When you DESCRIBE your table, the primary key will have a value of 'PRI' in the `Key` column.

        Comment

        • vaani15
          New Member
          • Jun 2007
          • 6

          #5
          Originally posted by pbmods
          Heya, vaani.

          When you DESCRIBE your table, the primary key will have a value of 'PRI' in the `Key` column.
          Thanks dear,
          But the query you gave is not exceptable in MySQL. Every time i am trying to execute the query, it is giving error....

          Please HELP!!!

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by vaani15
            Thanks dear,
            But the query you gave is not exceptable in MySQL. Every time i am trying to execute the query, it is giving error....

            Please HELP!!!
            Which query did you try and what error did you get?

            Comment

            • vaani15
              New Member
              • Jun 2007
              • 6

              #7
              Originally posted by r035198x
              Which query did you try and what error did you get?
              Sorry dear, Actually i am working in SQLServer..
              I am using
              Code:
               sp_helpconstraint Account
              query. It gives me the list of the constraints present in the Account table.

              I want to find the name of the column that is having primary key...
              Please Please HELP!!!

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by vaani15
                Sorry dear, Actually i am working in SQLServer..
                ..
                In that case this was in the wrong forum and so I've moved it to the SQL Server forum.

                Comment

                Working...