Answers for "write PRIMARY KEY ON ORACLE"

SQL
6

identify primary key in oracle table

-- Primary key in a table
SELECT * FROM ALL_CONSTRAINTS 		-- or DBA_CONSTRAINTS or UESR_CONSTRAINTS
WHERE TABLE_NAME= 'table_name' AND CONSTRAINT_TYPE = 'P';
-- With columns names:
SELECT c.OWNER, c.TABLE_NAME, c.CONSTRAINT_NAME, c.CONSTRAINT_TYPE, 
	col.COLUMN_NAME
FROM ALL_CONSTRAINTS c
JOIN ALL_CONS_COLUMNS col ON c.TABLE_NAME = col.TABLE_NAME 
    AND c.CONSTRAINT_NAME = col.CONSTRAINT_NAME
WHERE c.TABLE_NAME= 'table_name' AND c.CONSTRAINT_TYPE = 'P'
ORDER BY c.TABLE_NAME, c.CONSTRAINT_NAME, col.COLUMN_NAME;
Posted by: Guest on July-03-2021
0

oracle create table primary key

CREATE TABLE table_name
(
  column1 datatype null/not null,
  column2 datatype null/not null,
  ...
  CONSTRAINT constraint_name PRIMARY KEY (column1, column2, ... column_n)
);
Posted by: Guest on June-15-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language