I've just created my first database with oracle database configuration assistant.

enter image description here

Basically nothing special, database was created successfully. What I don't understand is why are there so many tables already in the database? How to create empty database in oracle?

enter image description here

  • I was logged in as system user. – FrenkyB Mar 14 '20 at 8:43

Just to give you an analogy. When you install Windows OS or Linux OS, would you have expected zero files on your filesystem? The same applies for the Oracle Database. After creation of an Oracle Database, there will be tons of objects (tables,functions,procedures,indices,packages,etc..) constitute your Oracle Database. All these objects are owned by SYS,SYSTEM,.. (there are many more).

These owners and objects come into play when you utilize different features of the database. Remember Oracle Database has been developed for +40 years and there is a vast amount of features!

Now that you want to create an empty database. Let's apply the OS analogy again. You would have created a new user... /home/myuser. This is exactly what you do in an Oracle Database as well.

An Oracle Database can handle thousands of users and schemas. (schema = owner of objects, user = manipulate already created objects (DML - select,insert,update,delete)).

-- *nix (example: export TWO_TASK=localhost:1521/SERVICE_NAME)
-- Windows

sqlplus system/password

-- this user is the schema. The owner of your objects.
create user myschema identified by &password
default tablespace USERS
temporary tablespace TEMP
quota unlimited on USERS;     

-- grant privs to the schema
grant create session, resource to myschema;

-- yes, we need to take security into account.
create role myschema_ro;
create role myschema_rw;

-- lets login as myschema
sqlplus myschema/password

-- your database or schema is empty, now create all objects...
create table t (x int);

-- grant access to object
grant select on t to myschema_rw; 

-- we are done with the creation of the schema  

sqlplus system/password

-- no one is going to login as schema owner. 
-- you only unlock this account when you do schema changes
alter user myschema account lock;

-- time to create your app-user-account who is going to access 
-- the database/schema
create user myapp identified by &password;

-- grant privileges for your app-user
grant create session, myschema_rw to myapp;

-- login
sqlplus myapp/password

-- you will see your schema objects are listed
select object_name from all_objects;

-- now, if you want to avoid schema-prefixing (select * from myschema.t) there are some options
-- the first thing you do in your app
alter session set current_schema = MYSCHEMA;

-- now you can do: t is owned by myschema
select * from t;

-- you can create a trigger (log in as myschema)
create or replace trigger after_logon_trg
after logon on myschema.schema
  execute immediate 'alter session set current_schema = MYSCHEMA';

You are now ready to create an empty database ( = schema in Oracle terms) on your Oracle Database server (instance) where your objects are secured.

Just to clarify: A database is a set of files on disk with one or many schemas (apart from sys/system), an instance is a running system which is composed of the files on disk plus the in-memory structures which define a working piece of software.

Best of luck!

  • I have slightly edited your answer to provide a single source of truth (SSOT) in the answer itself - I hope you find it suitable. – Vérace Mar 15 '20 at 9:36

why are there so many tables already in the database? How to create empty database in Oracle?

That is an "empty" Oracle database!!

Oracle databases are big, complicated Beasties that have lots (and lots) of internal workings that you [almost] never have to worry about. As DBA, you need to be aware of them but not much more than that.

Any Tables, etc., that you put into this database go into other Schemas in other Tablespaces and on which you grant appropriate privileges. Then, you create Accounts to use those Tables and those Accounts will only see those Tables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.