简体   繁体   中英

Oracle: Does database comes under user or user comes under database?

I have used MY SQL and Oracle as well, But I have a big confusion. That in oracle does users comes under database or database comes under user. As I have create a new user in oracle using sql command. and then i have created tables but i have not created any database, so where does that new tables goes ?

I guess tables are associated with users in oracle, like whoever has created table is the owner of the table and no other user can access the table hence there is no need to distinguish them by creating database first and then creating tables under them.

But in MYSQL(using PhpMyAdmin), First we have to create a database, then inside that database we have to create tables.

But In oracle we have to simply login with valid user with granted privileges and we can start creating table without creating database. but in which database these tables goes?

If we have consider java JDBC connection of MySQL

Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/mydb","USERNAME","PASSWORD");

here we have specified mydb as database name, But we have consider JDBC connection of Oracle 11g xpress edition:

Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","USERNAME","PWD");

there is no database name mention it contains only ip,port,sid,username and password but still we are able to access table name.

So my question is what is wrong with oracle ? why we don't have to specify database name, does there is no need of creating database in oracle, default database concept is there and its enough?

And as we can see jdbc connection syntax there is not database name mentioned, so i should assume that tables can be just distinguish based on which user has created it, not on under which database it is. if above query is solved... show me some light to how to see number of available database under current user using SQL command, command for changing database in oracle.

Currently I'm using Oracle 11g express edition

Oracle can be a bit confusing in this regard. The documentation is pretty good at explaining the concepts.

In short. A database is a collection of a bunch of physical files that represent the database. As with other systems, it is convenient to think of the database as the unit of back-up and recovery.

You don't ask about an instance. This is essentially a server and the server can run only one database. Often, database and instance are interchangeable, although "database" refers to the data and "instance' refers to the connectivity.

The database itself contains schemas, which contain objects such as tables and views and stored procedures. Schemas might "look like" databases in other systems, because they have a name and contain tables. Schemas are typically named after users, because each user has its own namespace. Users are often granted privileges specific to a given the namespace.

That is, schemas/namespaces are a unit of security , but not of backup / restore .

So, a database contains users. Users represent schemas that contain tables. And users can have roles and rights within and across schemas on the same database.

And, to further confuse things, users can be shared among multiple databases, but that is another matter.

Q: So my question is, What is wrong with Oracle? Why we don't have to specify database name, does there is no need of creating database in oracle, default database concept is there and its enough?"

A: In terms of thinking about the MySQL concepts of "user" and "database", in converting those concepts into Oracle...

In Oracle, those are the same thing . They are one in the same.

In MySQL, you can qualify the reference to a table name with the name of a database:

SELECT * FROM mydatabasename.mytablename ;

In Oracle, we can qualify a table name with the "owner" of the table:

SELECT * FROM mytableowner.mytablename ;

When we reference a tablename without qualifying it in MySQL, it's interpreted to be a reference to a table in the "current database".

In Oracle, an unqualified table reference is interpreted as a reference to a table that is "owned" by the current user. (If an object of that name is not owned by the current user, then Oracle looks for an object of that name under the special PUBLIC owner.)


To add to the confusion... the Oracle term "database" has a much different meaning than it does in MySQL... an Oracle database is not the same thing as a MySQL database.


In Oracle, to see the tables owned by the current user, you can query the USER_TABLES view.

To see the tables that the current user has privileges on, including those owned by other users, query the ALL_TABLES view. This view also returns an OWNER column that shows the user that owns the table.

If the current user has SELECT_CATALOG_ROLE privilege, you can query DBA_TABLES to see all tables owned by all users, whether you have privileges on those tables or not. This view also includes the OWNER column.

(The naming convention of USER_ , ALL_ and DBA_ applies to all of the dictionary views, not just _TABLES .

I would say in Oracle user comes under database.

Database is usually created during Oracle Database software installation. Obviously you can create it later (if you for example installed only software) or add another.

When you login to the db you use:

sqlplus username/password@SID

SID identifies the database instance (database name + instance number). For example, if your dbname is "mydatabase" and instance number is "1" then SID is "mydatabase1".

So when you later create new table it belongs to your user, and the user belongs to the database. Later you can select this table like this:

select * from username.your_table_name;

When you connect using JDBC connection you give SID too:

jdbc:oracle:thin:@[HOST][:PORT]:[SID]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM