How is oracle schema different from database or user?

4.5K    Asked by AmitSinha in SQL Server , Asked on Oct 6, 2022

I'm really confused with the terms database, user and schema. Can anyone explain how they are different from each other (if they are)?

If they are the same then, what are the similarities between them? How do we use them? And how do we create them? 

Answered by Amit raj

In Oracle schemas and users are essentially the same thing. You can consider that a user is the account you use to connect to a database, and a schema is the set of objects (tables, views, etc.) that belong to that account.


See this post on Stack Overflow: difference between a User and a Schema in Oracle? for more details and extra links. You create users with the create user statement. This also "creates" the schema (initially empty) - you cannot create a schema as such, it is tied to the user. Once the user is created, an administrator can grant privileges to the user, which will enable it to create tables, execute select queries, insert, and everything else.

The database is the thing that contains all the users you've created, and their data (and a bunch of predefined system users, tables, views, etc. that make the whole thing work). You should look at the Oracle Database Architecture documentation in the Concepts Guide (actually, that whole page is worth a read - there's a section about users and schemas higher up in that page) to get an introduction to what a database is, and what a database instance is - two important concepts. You can create a database with the create database statement, once you've installed the Oracle software stack. But using dbca (database creation assistant) is easier to get started.


Your Answer

Answer (1)

  In Oracle, the terms "schema," "database," and "user" are related but represent different concepts: 

Database: In Oracle, a database refers to the collection of data and database objects, including tables, indexes, views, stored procedures, etc., along with the underlying physical and logical structures that store and manage this data. It's the highest-level container for data storage and management.

User: A user in Oracle is an account that allows individuals or applications to connect to the database and perform operations such as querying data, modifying data, creating objects, etc. Each user has a unique username and password and is associated with a schema. Users can have different levels of privileges and permissions within the database.

Schema: A schema in Oracle is a collection of logical structures that are owned by a specific user. It includes objects such as tables, views, indexes, sequences, synonyms, procedures, functions, etc., that are created and managed by the user. The schema provides a namespace for objects and helps organize and manage them within the database.

To summarize:

  • The database is the highest-level container for data storage and management.
  • Users are accounts that connect to the database and perform operations.
  • Schemas are collections of logical structures owned by users and provide namespaces for database objects.

In many cases, a one-to-one relationship exists between users and schemas, where each user has a schema with the same name as the username. However, Oracle allows multiple users to share the same schema, and a single user can own multiple schemas. This flexibility allows for more sophisticated access control and data organization within the database.


6 Months

Interviews

Parent Categories