Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create table on another schema

Situation is that user1 gives permision to user2:

GRANT CREATE ANY TABLE, SELECT ANY TABLE TO user2;

And after logging on user2, I'm trying to create table:

CREATE TABLE user1.test(id NUMBER PRIMARY KEY);

the result is ORA-01031 - insufficient privileges I can create table on own schema and select tables from other schemas. I thought that CREATE ANY TABLE solves the problem, but it looks other way. Ah, and both users have unlimited tablespace. What else should I guarantee?

like image 967
Fuv Avatar asked Mar 03 '13 18:03

Fuv


People also ask

How will you create a table from one schema to another schema in Oracle?

right click on table >> Table>>COPY>> select the schema where you want to copy.

How do I create a table from another table in SQL Developer?

Answer: To do this, the SQL CREATE TABLE syntax is: CREATE TABLE new_table AS (SELECT * FROM old_table WHERE 1=2); For example: CREATE TABLE suppliers AS (SELECT * FROM companies WHERE 1=2);


2 Answers

Perhaps you need to also grant CREATE ANY INDEX? You are creating an index when you add the primary key. You can quickly test this by omitting the PK constraint.

like image 197
DCookie Avatar answered Oct 14 '22 09:10

DCookie


"create any table" is too powerful a privilege to be granting to non-DBA's. A better approach would be to create a "create table" procedure in the target schema that accepts sanitised components of the required DDL, and grant execute privilege on that to the required users.

A suitable interface would be something like ...

create procedure
  create_table(
    table_name varchar2,
    columns    varchar2,
    etc        varchar2)

... so that you can ...

begin
  user1.create_table(
    table_name => 'TEST',
    columns    => 'id NUMBER PRIMARY KEY',
    etc        => '');
end;

... and have the procedure construct and execute the DDL for you.

like image 23
David Aldridge Avatar answered Oct 14 '22 09:10

David Aldridge