473,394 Members | 1,751 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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.
Jul 6 '07 #1
7 1428
mwasif
802 Expert 512MB
DESCRIBE will display the whole table structure and SHOW KEYS will display the keys. The syntax is

Expand|Select|Wrap|Line Numbers
  1. DESCRIBE table_name;
Expand|Select|Wrap|Line Numbers
  1. SHOW KEYS FROM table_name;
Jul 6 '07 #2
But, i want a query that take table name and return the attribute name having primary key not the any other key..

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

Expand|Select|Wrap|Line Numbers
  1. DESCRIBE table_name;
Expand|Select|Wrap|Line Numbers
  1. SHOW KEYS FROM table_name;
Jul 6 '07 #3
pbmods
5,821 Expert 4TB
Heya, vaani.

When you DESCRIBE your table, the primary key will have a value of 'PRI' in the `Key` column.
Jul 7 '07 #4
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!!!
Jul 9 '07 #5
r035198x
13,262 8TB
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?
Jul 9 '07 #6
Which query did you try and what error did you get?
Sorry dear, Actually i am working in SQLServer..
I am using
Expand|Select|Wrap|Line Numbers
  1.  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!!!
Jul 9 '07 #7
r035198x
13,262 8TB
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.
Jul 9 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Gabriel Harrison | last post by:
Hi, I have a mysql db with with autoincrementing primary keys in each table. I want to allow a user to add a record using a php webpage. Once the page is added how can I re SELECT that record...
2
by: Graham Mattingley | last post by:
If I insert a value into a table what is the best way to find the Primary Field Value.. +--------------+---------------------+------+-----+ | Field | Type | Null | Key |...
6
by: Sebastien | last post by:
Hi, I am building a products database, linking sales and production. Each part has a unique sales Stock Code and Production Number. The sales stock code is a combination of letters and numbers...
1
by: siddharth | last post by:
when i am finding a particular row in a database through a datatable.row.find(the particular text to find) it gives me table does not have primary key although it has a primary key
2
by: Hugh O | last post by:
Hi, I have a Web app using VS.Net 2003, ASP and VB. I am using RDO with a SQL Server 2000 database. The code below shows an example of a NewRow method. In the first column there is a integer...
13
by: Ron | last post by:
Hi All, Okay, I've read previous suggestions about not showing the primary key to the user of forms. If a number is to be shown (let's say, customer number) it should be generated independently...
115
by: LurfysMa | last post by:
Most of the reference books recommend autonum primary keys, but the Access help says that any unique keys will work. What are the tradeoffs? I have several tables that have unique fields. Can...
2
by: Iain Adams | last post by:
Hey I want to get some data from some tables but I want every field except the primary key field returned. Is this possible? I.e SELECT * (except primary) FROM table1, table2, table3 Any...
1
by: hirak chatterjee | last post by:
Hi, i want to find interrelations among all the primary keys in all the tables. for e.g== the output will be .....is the primary key of table............ .....is the primary key of table........
4
by: mark_aok | last post by:
Hi all, I need to determine the name of the primary key in a table, but this must be done using VBA. I was looking for something like, for each field in someRecordset.fields if...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.