Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the privilege required to create unique/primary key constraint in Oracle?

Though it feels like asking a very basic question without much research, posting this question here after much searching in Oracle forums, AskTom, Oracle Docs & SOF. I am trying to narrow down the privilege required to create unique key constraint or primary key constraint. This is because trying to create a simple table with unique/primary key fails with insufficient privileges.

SQL> connect sys/syspass
Connected.
SQL> show user
USER is "SYS"
SQL> grant create session, create table, create any index, 
     create indextype, unlimited tablespace to tuser1;

Grant succeeded.

SQL> 
SQL> connect tuser1/tuserp1
Connected.
SQL> create table tab1 (
atomic          int unique,
symbol          varchar2(2) unique,
name            char(15)
);  2    3    4    5  
create table tab1 (
*
ERROR at line 1:
ORA-01031: insufficient privileges


SQL> create table tab2 (empno number, name varchar2(30), sal number,
constraint pk_tab2 primary key (empno));  2  
create table tab2(empno number, name varchar2(30), sal number,
*
ERROR at line 1:
ORA-01031: insufficient privileges

SQL> 

Can please help me with finding the possible missing permission in this case?

like image 370
bprasanna Avatar asked Oct 27 '25 09:10

bprasanna


1 Answers

granting resource must resolve the issue :

SQL> conn tuser1/tuserp1
Connected.
SQL> create table tab2 (empno number, name varchar2(30), sal number,
constraint pk_tab2 primary key (empno));    
create table tab2 (empno number, name varchar2(30), sal number,
*
ERROR at line 1:
ORA-01031: insufficient privileges
SQL> conn / as sysdba
Connected.
SQL> grant resource to hr;

Grant succeeded.

SQL> conn tuser1/tuserp1
Connected.
SQL> create table tab2 (empno number, name varchar2(30), sal number,
constraint pk_tab2 primary key (empno));    

Table created.
like image 79
Barbaros Özhan Avatar answered Oct 30 '25 00:10

Barbaros Özhan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!