Meet OceanBase DataPilot, the enterprise data agent for natural-language analytics and app creation.

Explore ->

Meet OceanBase DataPilot, the enterprise data agent for natural-language analytics and app creation. Explore ->

What Is A Sql Database Schema?

Jarek ShawJarek Shaw
Updated on 2026-11-19

Fundamentals of SQL Database Schema Definition and Design

What Is a Database Schema?

A database schema defines how data is organized within a database. It specifies the tables in a database, their columns and data types, the relationships between tables, and the constraints that govern how data is stored and managed.

A schema describes the structure and rules of a database rather than the actual data stored in its tables. It provides the foundation for organizing and managing data in relational database systems.

How Schema Is Used in Different Databases

The meaning of a database schema varies slightly across database management systems.

In PostgreSQL, a schema is a namespace within a database that organizes database objects such as tables, views, and functions. A single PostgreSQL database can contain multiple schemas, allowing objects to be grouped and managed separately.

In MySQL, the terms schema and database are generally used interchangeably. Both refer to a collection of database objects, including tables, views, and other related objects.

Understanding these differences is important when working with different database systems. A clear understanding of database schemas also helps developers and database administrators make better decisions about database design, access control, and ongoing maintenance.

Why Is Good Database Schema Design Important?

A well-designed database schema can improve SQL query performance, reduce unnecessary data redundancy, and lower long-term system maintenance costs.

Whether an application uses a relational database such as MySQL or PostgreSQL, or certain NoSQL database systems, a well-structured and extensible schema provides a solid foundation for building efficient and reliable applications.

Good schema design also makes it easier to maintain data consistency, manage relationships between database objects, and accommodate changing application requirements as a system grows.

Schema Features in OceanBase Database


oceanbase database

Understanding Schema in Different Compatibility Modes

OceanBase supports both MySQL and Oracle compatibility modes. The concept of a schema differs between these two modes, so understanding how each mode handles database objects is important for database design and administration.

Schema in Oracle Mode

In Oracle mode, a schema is a collection of database objects owned by a particular user. These objects may include tables, views, indexes, and other database resources.

When a user is created, a default schema is also associated with that user. The schema name is the same as the username.

Users can also access and use objects belonging to other schemas, provided they have the necessary privileges. When referencing an object without explicitly specifying its schema, the system automatically uses the user's default schema name.

This approach allows database objects to be organized by ownership and access permissions.

Schema in MySQL Mode

In MySQL mode, a database is a collection of database objects used for namespace organization and access control.

In this mode, schema and database are synonymous. SQL statements can use the SCHEMA keyword as an alternative to DATABASE.

For example, CREATE SCHEMA can be used instead of CREATE DATABASE. Similarly, database management operations can use the corresponding ALTER DATABASE and DROP DATABASE syntax.

These differences are particularly important when migrating applications or database objects between MySQL and Oracle environments.

Schema Objects and Metadata Queries

Schema Objects

Schema objects are database objects that belong to a particular schema. Depending on the compatibility mode, these objects may include tables, views, triggers, synonyms, and other database resources.

Understanding how schema objects are organized helps database administrators manage object ownership, dependencies, and access permissions.

Querying Metadata Through information_schema

OceanBase provides the information_schema system database, which contains views for retrieving metadata about databases and their objects.

For example, the information_schema.SCHEMATA view provides information about databases and schemas, including database names, default character sets, default collations, and encryption-related attributes.

These metadata views allow developers and administrators to inspect database structures and retrieve information without directly accessing internal system tables.

Access Permissions and Tenant Isolation

In MySQL mode, ordinary tenants have read-only access to all tables in the information_schema database by default through the SELECT privilege on information_schema.*.

However, this access is subject to tenant isolation and the user's visibility scope. An ordinary tenant can only view database objects and metadata belonging to its own tenant and permitted access scope.

OceanBase maintains strict isolation between tenants. Metadata queries through information_schema cannot be used to access database objects belonging to other tenants.

This separation allows administrators to inspect database metadata while maintaining appropriate access boundaries.

Schema History Management and Recycling

OceanBase provides a Schema History recycling mechanism to manage historical versions of database object definitions.

Schema Version Management

Whenever a database object is created or its definition is modified, OceanBase generates a corresponding schema version and retains previous versions.

This version management mechanism allows the system to maintain historical schema information as database structures evolve.

Automatic Schema History Recycling

Over time, retaining too many historical schema versions can increase the size of internal system tables. To prevent excessive metadata accumulation, OceanBase provides an automatic Schema History recycling mechanism.

The system periodically initiates cleanup tasks to remove expired schema history records that meet the recycling conditions.

These records may be stored in system tables such as __all_table_history, __all_column_history, and __all_ddl_operation.

By automatically cleaning up eligible historical records, OceanBase helps control system table growth and maintain efficient metadata management.

Compatibility with Information Views and SQL Syntax

OceanBase provides compatibility with MySQL information schema views and SQL syntax, making database administration and application migration more straightforward.

Information Schema View Compatibility


oceanbase database


OceanBase supports MySQL-compatible information_schema views, including TABLES, COLUMNS, SCHEMATA, and SCHEMA_PRIVILEGES.

This compatibility allows third-party database management and monitoring tools to retrieve metadata through familiar interfaces.

When querying information_schema.columns to retrieve column definitions, it is recommended to specify table_schema (the database name). This helps the query make use of indexes and improves retrieval efficiency.

DDL and SQL Syntax Compatibility

OceanBase supports MySQL-compatible SQL syntax, including Data Definition Language (DDL), Data Manipulation Language (DML), and Data Control Language (DCL).

This compatibility reduces the need to rewrite existing SQL statements when migrating applications from MySQL environments, helping organizations simplify database migration and reduce associated development costs.

Schema Migration and Import Support

When migrating from heterogeneous database systems, such as Oracle Database to OceanBase Database in Oracle mode, schema migration is an important part of the process.

OceanBase provides a set of tools to help organizations export, convert, and import database schemas while minimizing manual adjustments.

Schema Export

OceanBase recommends using DBCat to export the schema from the source database, including the definitions of its database objects.

During the export process, DBCat automatically handles SQL syntax conversion to make the exported schema compatible with OceanBase Database.

Schema Import

After the schema has been exported and converted, OceanBase recommends using OBLOADER, its official data loading tool, to import the schema into OceanBase Database.

Together, these tools help streamline schema migration from heterogeneous database systems and simplify the transition of existing database structures to OceanBase.


oceanbase database

Announce

The "Blog," "Q&A," and other sections of this website provide a platform for technology enthusiasts to share and exchange ideas. Any content or information posted by users does not reflect or represent the views, positions, or policies of this website. This website assumes no responsibility for any errors in its content or information, or for any loss or damage arising therefrom.

Respect for intellectual property rights is one of the fundamental principles of this website. If you discover any infringement of your or other third party's legitimate intellectual property rights on this website while using it, please submit the infringing materials and preliminary evidence to the following email address: oceanbase_compliance@oceanbase.com. This website will review and process the materials as soon as possible after receiving them.

OceanBase, the Unified Distributed Database for the AI era

Product

OceanBase Enterprise

RPO=0 Disaster Resilience

Predictable Performance at Scale

High Oracle & MySQL Compatibility

30%+ TCO Reduction

Learn More

OceanBase Cloud

Available across 7 Public Clouds

Enable Cross-cloud Active-active Architecture

Multi-model, One engine for TP / AP / AI

Learn More
The Multi-Cloud DR Playbook: Architecture Patterns for Cross-Cloud Database Resilience

KEEP READING

Start Building on OceanBase, the Unified Distributed Database

Try Open Source