how to select primary key

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mukeshrasm
    Contributor
    • Nov 2007
    • 254

    #1

    how to select primary key

    hi

    I want to select primary key field from my table.

    code which I tried SELECT FLIGHT_NO FROM FLIGHT. here FLIGHT_NO is primary key. but I am getting error : Invalid Column Name

    but this code works fine in Access and MySql.

    so what will be the right query ?
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    I use all three database types you mention and am aware of some pitfalls.
    Nothing is obviously wrong.
    Do you have backticks or brackets around the field name or table name?
    Can we see the exact query used in the three DBs.
    Do you have such a field in the MsSql table?

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Are you trying to find the value of the column? Or are you trying to find out what is the PRIMARY KEY of the table?

      If it's the former a simple

      select ColumnName from YourTable.

      if it's the latter,

      sp_help YourTable

      will show the PRIMARY KEY constraint...us ually at the end.

      -- CK

      Comment

      • mukeshrasm
        Contributor
        • Nov 2007
        • 254

        #4
        Originally posted by ck9663
        Are you trying to find the value of the column? Or are you trying to find out what is the PRIMARY KEY of the table?

        If it's the former a simple

        select ColumnName from YourTable.

        if it's the latter,

        sp_help YourTable

        will show the PRIMARY KEY constraint...us ually at the end.

        -- CK
        Hi

        problem was resolved. actually i was putting bracket in the field name
        which was unnecessary.

        thanks !

        Comment

        • code green
          Recognized Expert Top Contributor
          • Mar 2007
          • 1726

          #5
          Ah! The square brackets used by Access.
          Access and SQL server queries are not cross platform.
          In fact Access seems to be more similar to MySql

          Comment

          Working...