Designing a schema in Oracle groups tables, views, and other objects under a logical namespace owned by a database user.
Schemas isolate tables and other objects, prevent name clashes, and let you control privileges at a granular level. Each schema belongs to a database user, so creating a user is the first step in schema design.
Oracle creates a schema automatically when you issue CREATE USER
. The user name becomes the schema name.Grant the required privileges, then create tables, views, and other objects under that schema.
1 Create user ecommerce
.
2 Grant CONNECT
and RESOURCE
roles.
3 Switch to the schema and create tables like Customers
, Orders
, and Products
.
Prefix the object with schema name: SELECT * FROM ecommerce.Customers;
.To avoid prefixes, set your current schema with ALTER SESSION SET CURRENT_SCHEMA = ecommerce;
.
Keep related objects together, use meaningful user/schema names, and grant the least privileges needed. Add constraints and indexes early, and document relationships with comments.
Use ALTER TABLE ... RENAME TO
along with ALTER SESSION SET CURRENT_SCHEMA
, or export/import with Data Pump if many objects.
Yes—use DROP USER ecommerce CASCADE;
.Always back up data first, confirm dependencies, and revoke user sessions before dropping.
.
Yes. Creating a user automatically creates a schema with the same name.
No. You must create a new user, move objects, and drop the old schema.
Query ALL_OBJECTS
or use SQL*Plus DESC
command on each table.