PLSQL: Retrieve primary key information (2024)

PLSQL: Retrieve primary key information (1)

Question: How do I determine if a table has a primary key and if it has one, how do I determine what columns are in the primary key?

Answer: You can retrieve primary key information with the following SQL statement:

SELECT cols.table_name, cols.column_name, cols.position, cons.status, cons.ownerFROM all_constraints cons, all_cons_columns colsWHERE cons.constraint_type = 'P'AND cons.constraint_name = cols.constraint_nameAND cons.owner = cols.ownerORDER BY cols.table_name, cols.position;

If you knew the table name that you were looking for, you could modify the SQL as follows:

SELECT cols.table_name, cols.column_name, cols.position, cons.status, cons.ownerFROM all_constraints cons, all_cons_columns colsWHERE cols.table_name = 'TABLE_NAME'AND cons.constraint_type = 'P'AND cons.constraint_name = cols.constraint_nameAND cons.owner = cols.ownerORDER BY cols.table_name, cols.position;

Make sure to type the table_name in uppercase, as Oracle stores all table names in uppercase.

Let's quickly explain the output from this query.

table_name
The name of the table (stored in uppercase).
column_name
The name of the column that is a part of the primary key. (also stored in uppercase)
position
The position in the primary key. A primary key can contain more than one column, so understanding the order of the columns in the primary key is very important.
status
Indicates whether the primary key is currently enabled or disabled.
owner
Indicates the schema that owns the table.
PLSQL: Retrieve primary key information (2024)
Top Articles
Tether (USDT): Meaning and Uses for Tethering Crypto Explained
How Payment History Impacts Your Credit Score | myFICO
Jail Inquiry | Polk County Sheriff's Office
Dannys U Pull - Self-Service Automotive Recycling
Spn 1816 Fmi 9
Shoe Game Lit Svg
Nyu Paralegal Program
Amtrust Bank Cd Rates
Voorraad - Foodtrailers
Driving Directions To Fedex
Chalupp's Pizza Taos Menu
Crusader Kings 3 Workshop
Www.paystubportal.com/7-11 Login
83600 Block Of 11Th Street East Palmdale Ca
C Spire Express Pay
Valentina Gonzalez Leak
What Time Chase Close Saturday
Elbasha Ganash Corporation · 2521 31st Ave, Apt B21, Astoria, NY 11106
Jackson Stevens Global
Powerball winning numbers for Saturday, Sept. 14. Check tickets for $152 million drawing
Kiddle Encyclopedia
Craigslist Mt Pleasant Sc
Faurot Field Virtual Seating Chart
Jenna Ortega’s Height, Age, Net Worth & Biography
T Mobile Rival Crossword Clue
Disputes over ESPN, Disney and DirecTV go to the heart of TV's existential problems
Www Pointclickcare Cna Login
Keyn Car Shows
1773x / >
Cable Cove Whale Watching
Ardie From Something Was Wrong Podcast
Unity Webgl Car Tag
HP PARTSURFER - spare part search portal
Parent Management Training (PMT) Worksheet | HappierTHERAPY
James Ingram | Biography, Songs, Hits, & Cause of Death
Math Minor Umn
Rock Salt Font Free by Sideshow » Font Squirrel
1-800-308-1977
Uc Santa Cruz Events
Man Stuff Idaho
Ezpawn Online Payment
Kent And Pelczar Obituaries
Craigslist Binghamton Cars And Trucks By Owner
56X40X25Cm
UWPD investigating sharing of 'sensitive' photos, video of Wisconsin volleyball team
Jane Powell, MGM musical star of 'Seven Brides for Seven Brothers,' 'Royal Wedding,' dead at 92
Kaamel Hasaun Wikipedia
Barback Salary in 2024: Comprehensive Guide | OysterLink
Who Is Nina Yankovic? Daughter of Musician Weird Al Yankovic
Poster & 1600 Autocollants créatifs | Activité facile et ludique | Poppik Stickers
Www Ventusky
Latest Posts
Article information

Author: Jerrold Considine

Last Updated:

Views: 6314

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Jerrold Considine

Birthday: 1993-11-03

Address: Suite 447 3463 Marybelle Circles, New Marlin, AL 20765

Phone: +5816749283868

Job: Sales Executive

Hobby: Air sports, Sand art, Electronics, LARPing, Baseball, Book restoration, Puzzles

Introduction: My name is Jerrold Considine, I am a combative, cheerful, encouraging, happy, enthusiastic, funny, kind person who loves writing and wants to share my knowledge and understanding with you.