1-- NOTE: this is for SQL-Oracle specifically 2 3-- syntax: 4SELECT cols.table_name, cols.column_name, cols.position, cons.status, cons.owner 5FROM all_constraints cons, all_cons_columns cols 6WHERE cols.table_name = '<table-name>' -- Replace <table-name> with your table-name 7AND cons.constraint_type = 'P' 8AND cons.constraint_name = cols.constraint_name 9AND cons.owner = cols.owner 10 11 12-- example: 13SELECT cols.table_name, cols.column_name, cols.position, cons.status, cons.owner 14FROM all_constraints cons, all_cons_columns cols 15WHERE cols.table_name = 'CUSTOMERS' 16AND cons.constraint_type = 'P' 17AND cons.constraint_name = cols.constraint_name 18AND cons.owner = cols.owner
1A primary key is a field in a table which uniquely identifies each row/record in a database table. Primary keys must contain unique values. A primary key column cannot have NULL values. 2 3A table can have only one primary key, which may consist of single or multiple fields. When multiple fields are used as a primary key, they are called a composite key. 4 5If a table has a primary key defined on any field(s), then you cannot have two records having the same value of that field(s).
1The PRIMARY KEY constraint uniquely identifies each record in a table. 2Primary keys must contain UNIQUE values, and cannot contain NULL values. 3A table can have only ONE primary key; and in the table, this primary key can consist of single or multiple columns (fields). 4