Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a small and simple database using Oracle 11 g and SQL Developer?

How to create a small and simple database using Oracle 11 g and SQL Developer ? I am seeing too many errors and I cannot find any way to make a simple database. For example

create database company; 

Caused the following error:

Error starting at line 1 in command:
create database company
Error at Command Line:1 Column:0
Error report:
SQL Error: ORA-01501: CREATE DATABASE failed
ORA-01100: database already mounted
01501. 00000 -  "CREATE DATABASE failed"
*Cause:    An error occurred during create database
*Action:   See accompanying errors.

EDIT- This is completely different from MySQL and MS-SQL that I am familiar with. Not as intuitive as I was expecting.

like image 839
sweet dreams Avatar asked Aug 07 '12 21:08

sweet dreams


1 Answers

First off, what Oracle calls a "database" is generally different than what most other database products call a "database". A "database" in MySQL or SQL Server is much closer to what Oracle calls a "schema" which is the set of objects owned by a particular user. In Oracle, you would generally only have one database per server (a large server might have a handful of databases on it) where each database has many different schemas. If you are using the express edition of Oracle, you are only allowed to have 1 database per server. If you are connected to Oracle via SQL Developer, that indicates that you already have the Oracle database created.

Assuming that you really want to create a schema, not a database (using Oracle terminology), you would create the user

CREATE USER company
  IDENTIFIED BY <<password>>
  DEFAULT TABLESPACE <<tablespace to use for objects by default>>
  TEMPORARY TABLESPACE <<temporary tablespace to use>>

You would then assign the user whatever privileges you wanted

GRANT CREATE SESSION TO company;
GRANT CREATE TABLE TO company;
GRANT CREATE VIEW TO company;
...

Once that is done, you can connect to the (existing) database as COMPANY and create objects in the COMPANY schema.

like image 86
Justin Cave Avatar answered Oct 13 '22 01:10

Justin Cave