Insufficient privileges when creating a trigger for a table in another schema - sql

When I try to create a trigger in schema A for a table located in schema B, I get an ora error : insufficient privileges.
What privileges do I need?

If you are creating the trigger in your schema, you'll need the CREATE TRIGGER privilege. In order to create the trigger in somebody else's schema, you'll need the CREATE ANY TRIGGER privilege.
This resource does a very good job of explaining the requirements, and contains more information about triggers (syntax, enabling, disabling, etc).

Related

How to grant privileges on trigger and synonyms in oracle 11g

I have created a sample application to get schema of all objects and generate SQLfile, so I simply created two user, user 'SYSTEM' and 'SCOTT' , and user SYSTEM grant all privileges to access some of tables,views,function etc. to user SCOTT,
for grant privileges to user SCOTT use following oracle query
GRANT ALL ON table_name to username
But the problem is this query is not working for trigger and synonyms.
so anyone please suggest me how can I grant privileges on triggers and synonyms to user SCOTT.
But the problem is this query is not working for trigger and synonyms. so anyone please suggest me how can I grant privileges on triggers and synonyms to user SCOTT.
TRIGGER - You cannot t give grants for trigger. There is no such thing. Triggers fire automatically whenever the trigger event is done on the table on which the the trigger is created. You only need to grant privilege on the table.
SYNONYM - You just create a synonym for the schema.table and grant privilege on the table such that other users doesn't have to fully qualify the table and just use the synonym instead.

ORA-01031 after creating table (But only for a while)

I'm having some problems with oracle after creating a table. I have the proper permissions to create the table, but if I try to query immediately after creating it I get error ORA-01031 "Insufficient privileges".
However, if I wait a couple of hours then I have no problems querying it.
Any ideas what would cause this?
I think that you need give privilege for selection data from created table for user that contains it. Use follow script:
grant select on <user>.created_table to <user>;
this script must run from user with admin grant.
Also you can give several options:
grant select, update, delete, insert on <user>.created_table to <user>;

postgres table privileges do not allow user to create/select view

I am managing a database that has a number of schemas. I am having some difficulty with setting privileges and would like to request some help.
I have the schema called schemaA and a group_role db_writer
I use the following sql:
GRANT USAGE ON SCHEMA schemaA TO db_writer;
GRANT UPDATE, INSERT, SELECT, DELETE ON ALL TABLES IN SCHEMA schemaA TO db_writer;
However, the db_writer is unable to create views. They are returned with a permission denied error. Also, when I create views, she is then unable to select them...and I have to set the priviliges again for that view.
It was my understanding the views were treated as tables with respect to privileges...and if one is granted certain permissions to all tables in a schema this would apply to views also.
What am I missing? Any advice appreciated.
The problem is USAGE does not allow users to create objects within the database.
Try
GRANT USAGE, CREATE ON SCHEMA schemaA TO db_writer
Edit:
New objects will get default privileges, for the user to have those privileges for objects created in the future you can do it as:
ALTER DEFAULT PRIVILEGES IN SCHEMA schemaA GRANT UPDATE, INSERT, SELECT, DELETE ON TABLES TO db_writer;
ALTER DEFAULT PRIVILEGES IN SCHEMA schemaA GRANT SELECT ON TABLES TO db_reader;
Check this answer for more info

Insufficient Privileges when creating tables in Oracle SQL Developer

I have granted the user in my connection to create tables, triggers, procedures, and sequence using sql+ (grant create table to <my_user>); however, that still does not allow me to create a table in that schema showing the error message:
java.sql.sqlsyntaxerrorexception ora-01031 insufficient privileges
select * from session_privs; shows:
PRIVILEGE
UNLIMITED TABLESPACE
CREATE TABLE
CREATE CLUSTER
CREATE SEQUENCE
CREATE PROCEDURE
CREATE TRIGGER
CREATE TYPE
CREATE OPERATOR
CREATE INDEXTYPE
Does anybody know what I am doing wrong here? I am just setting up pl/sql developer at home, so everything is brand new. Does this have anything to do with TABLESPACE?
Run the following command from a privileged user and re-connect with your user:
GRANT RESOURCE to my_user;

How to make a GRANT persist for a table that's being dropped and re-created?

I'm on a fairly new project where we're still modifying the design of our Oracle 11g database tables. As such, we drop and re-create our tables fairly often to make sure that our table creation scripts work as expected whenever we make a change.
Our database consists of 2 schemas. One schema has some tables with INSERT triggers which cause the data to sometimes be copied into tables in our second schema. This requires us to log into the database with an admin account such as sysdba and GRANT access to the first schema to the necessary tables on the second schema, e.g.
GRANT ALL ON schema_two.SomeTable TO schema_one;
Our problem is that every time we make a change to our database design and want to drop and re-create our database tables, the access we GRANT-ed to schema_one went away when the table was dropped. Thus, this creates another annoying step wherein we must log in with an admin account to re-GRANT the access every time one of these tables is dropped and re-created.
This isn't a huge deal, but I'd love to eliminate as many steps as possible from our development and testing procedures. Is there any way to GRANT access to a table in such a way that the GRANT-ed permissions survive a table being dropped and then re-created? And if this isn't possible, then is there a better way to go about this?
So the reason why the grants get revoked is that the new table is a different object.
SQL> select object_id from user_objects
2 where object_name = 'T72'
3 /
OBJECT_ID
----------
659195
SQL> drop table t72
2 /
Table dropped.
SQL> create table t72 (id number)
2 /
Table created.
SQL> select object_id from user_objects
2 where object_name = 'T72'
3 /
OBJECT_ID
----------
659212
SQL>
The grants are on the object, not the object's name.
What I don't understand about your problem is this: you have a process which drops and re-creates the tables in schema_two. Why doesn't that process also grant grant privileges on those tables to schema_one? Why do you have an admin account do it instead? I presume you are connecting as schema_two to run the DROP and CREATE statements. Why not just add the GRANT statements to that step?
Because granting privileges on objects is as much a part of the installation as creating the tables. So you ought to have a process which does everything.
You could grant select any table, insert any table, etc to schema_one, but that seems like overkill and won't reflect what you do in production (hopefully). Why can't you issue the grant at the same time as you create the table, while logged in as schema_two? I've always done that in the creation scripts, and only ever had to use an admin account to grant third-party or system privs. I suspect I'm missing something...
What are you doing that couldn't be handled by ALTER TABLE statements?
The next best option might be to create a view that references the table that occaisionally disappears - the view won't disappear, you'd just get an error if the table doesn't exist in such a situation. IE:
CREATE VIEW table_vw AS
SELECT t.*
FROM DISAPPEARING_TABLE t
Using * notation would also mean you don't have to continually update the view to expose columns in the table.
You could have a DDL trigger or a batch job that runs every few minutes that grants privileges automatically. But that is a bit of a security hole and won't represent production.
I suggest that you might give the account which you use to create the tables the ability to run the grants as well.
Share and enjoy.