What is the difference (if any) between a database, a user, and a schema?
In Oracle, users and schemas 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
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.
To begin to understand the difference I think we must start saying that this nomenclature was a mistake from Oracle.
I assume that if you have an ERP called TRITON you want your database to be named TRITON, or if my company it's called JENNY EXPORT I might decide my database to be called JENNYEXP or something like that, no need for any user with the same name.
In Oracle, you need to create a USER before creating the tables and weird enough this collection of TABLES is called SCHEMA.
Then you might create the actual users and grant proper permissions to work with such database as TRITON as per this example, by the way, if you connect thru SQL DEVELOPER you must NAME A CONNECTION.
I know I sound kind of frustrated but it makes more sense to me the MS SQL SERVER naming convention and I could add that I worked with Oracle earlier than SQL SERVER.
The Data base is a collection of data,where actually data stored. Its a physical Memory Component Connected to a Computer Installed with DBMS Software to manipulate the data in that Memory component,the computer installed with dbms software is called Server or Database Server.The both Server(Computer) and Database(memory component) are different but Most of times refered as Same based on situation.
USER and SCHEMA
The both words, user and schema, are interchangeable, that's why most people get confused on these words.
User is a account to connect database(Server). we can create user by using CREATE USER IDENTIFIED BY .
Actually Oracle Database contain logical and physical structure to process the data. The Schema Also Logical Structure to process the data in Database(Memory Component).
It's created automatically by Oracle when user created. It contains all objects created by the user associated to that schema.For Example if i created a user with name
santhosh then oracle creates a schema called
santhosh, Oracle stores all objects created by user
santhosh in the
We can create schema by using the
CREATE SCHEMA statement, but Oracle automatically creates a user for that schema.
We can drop the schema by using the
DROP SCHEMA <name> RESTRICT statement, but it can not delete schema contained objects, so to drop the schema, it must be empty. here the restrict word forces you to specify that schema with out objects.
If we try to drop a user containing objects in his schema we must specify
CASCADE word because Oracle does not allow you to delete a user containing objects.
DROP USER <name> CASCADE
so Oracle deletes the objects in schema and then it drops the user automatically, Objects referred to these schema objects from other schema like views and private synonyms goes to invalid state.
According to the way the terminology is sometimes used, a
USER and a
SCHEMA are somewhat similar. But there is also a major difference. A
USER can be called a
SCHEMA if the "
USER" owns any object, otherwise it will only remain a "
USER". Once the
USER owns at least one object then by virtue of all of your definitions above... the
USER can now be called a
I would add that the statements above apply to Oracle's implementation but other databases including SQL Server and PostgreSQL use schema as just a namespace, i.e. a way to group objects. For example, the Staging schema could group all object used in staging data, the Accounting schema could group all objects related to Accounting.
From my point of view some confusion regarding the terms "database", "schema" and "user" also comes from the differences between Microsoft SQL Server and Oracle.
- "Inside" Oracle the difference between schema and user/login is not to be understood without further explanation. "User" is an account to log in to the database (usually without own objects like tables or views), it can be called "schema" if it "owns" objects. But this has already been explained above.
- In MS SQL Server, the term "database" describes an object that is most comparable with "schema" in Oracle. Both are a combination of objects that are "qualified" by "database/schemaowner.object", note the "." as a separator between the ""combination"" and the actual object.
BTW: Note also the different meaning of "instance" in Microsoft SQL Server and Oracle.
I am telling you according to concepts not based on any type of database management system you are using.
Conceptually: Database : is Just a pile of data, mostly un-managed related or unrelated data.
Schema: Schema refers to formally structuring the unmanaged related/unrelated data so that it can be managed by some management system which understands the formal definition provided by the schema. Schema is basically a scheme to to provide overview. For example you have XSD which defines the schema to create XML. You have RDBMS which defines its own schemas which are based on Codd Rules which basically defines schemes to create RDBMS.
Now if you want to know more about is refer this Link.
User's use the formal language specified by the schema to access the Database