Connecting Tech Pros Worldwide Help | Site Map

how to select primary key

Familiar Sight
 
Join Date: Nov 2007
Posts: 235
#1: Oct 23 '08
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's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,076
#2: Oct 23 '08

re: how to select primary key


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?
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#3: Oct 24 '08

re: how to select primary key


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...usually at the end.

-- CK
Familiar Sight
 
Join Date: Nov 2007
Posts: 235
#4: Oct 24 '08

re: how to select primary key


Quote:

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...usually at the end.

-- CK

Hi

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

thanks !
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,076
#5: Oct 24 '08

re: how to select primary key


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
Reply