create schema in oracle ?

June 5, 2013 — Leave a comment

to be honest, I never was aware of this. there is a create schema command in oracle which can be used to populate a schema in a singe transaction:

create user u identified by u;
create user a identified by a;
grant create session, create table, create view to u;
alter user u quota 1m on users;
connect u/u
create schema authorization u
   create table t1 
      (a number, b varchar2(10))
   create view v1
      as select * from t1 where a = 1
   grant select on v1 to a;

this can be very handy if you want a script ( which creates some tables and views ) to be atomic. if there is an error in your create schema script like:

create schema authorization u
   create table t1
      (a number, b varchar2(10))
   create view v1
      as select **** from t1 where a = 1
   grant select on v1 to a;

… nothing will be created at all. you may fix the script and start over again ( without dropping anything as you would need to do it if you use single create commands ).

this is documented here.

Advertisements

No Comments

Be the first to start the conversation!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s