Difference between database vs user vs schema
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 same then, what are the similarities between them? How do we use them? And how do we create them?
Hope this will give the basic idea: http://www.answers.com/Q/Difference_between_user_and_schema_oracle
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 userstatement. 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.
"users and schemas are essentially the same thing" -- If that's true, that the stupidest naming I've ever heard of.
Then how do you add users (as in separate logins) with different privileges without creating new schema per user? Are you supposed to use just one login credential per schema?
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.
According to the way the terminology is sometimes used, a
SCHEMAare somewhat similar. But there is also a major difference. A
USERcan be called a
SCHEMAif the "
USER" owns any object, otherwise it will only remain a "
USER". Once the
USERowns at least one object then by virtue of all of your definitions above... the
USERcan now be called a
I think what you're pointing out here is that the term 'SCHEMA' is multi-faceted. It is a namespace for database objects on one hand. Also, in Oracle (and others?) but not PostgreSQL, it is a database object namespace containing exactly the objects created by the user sharing the name of the schema. From another perspective, it is the relationships and structure of objects in a database, often ignoring both ownership and namespace.
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
santhoshthen oracle creates a schema called
santhosh, Oracle stores all objects created by user
We can create schema by using the
CREATE SCHEMAstatement, but Oracle automatically creates a user for that schema.
We can drop the schema by using the
DROP SCHEMA <name> RESTRICTstatement, 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
CASCADEword 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.
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 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.
Not sure to what you refer when you say "statements above" but schema in SQL and in Oracle is a permissions grouping. In other words it is not just a way to group like objects together, but a way to group objects which will ease the management of permissions as you can grant permissions to a schema and therefore avoid having to grant permissions to each object within the schema.
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