OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V2.2.77Enterprise Edition

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & CertificationTicket
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V2.2.77
    iconOceanBase Database
    SQL - V 2.2.77Enterprise Edition
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    About types of column constraints

    Last Updated:2023-08-18 09:26:34  Updated
    Share
    What is on this page
    About default date/time settings for date/time columns

    folded

    Share

    To ensure that the data in the table conforms to the business rules, you can define constraints at the column level.

    The constraints limit the type of values that can be stored in a column. If you attempt to enter or update a value that does not satisfy the constraint in the corresponding column, an error is returned and the operation is rolled back. Likewise, if you attempt to add a constraint that conflicts with the existing data to a column in an existing table, an error is returned and the operation is rolled back.

    Constraints can be enabled or disabled. By default, a constraint is enabled after being created.

    The types of constraints include:

    • NOT NULL constraint: enforces that the constrained column must not contain null values.

      For example, the NOT NULL constraint in the w_name column in the ware table requires that each warehouse in the column must have a name. For a column with the NOT NULL constraint, you must specify the values in the INSERT statement unless you have defined a default value for the column. For example, if you define a default value 0.99 for the c_discount column in the cust table, the default discount per user is 0.99.

    • UNIQUE constraint: enforces that the constrained column must not contain duplicate values, but it can contain multiple null values.

      For example, the UNIQUE constraint on the (w_name, w_city) column in the ware table enforces that the warehouse names in each city must be unique.

    • PRIMARY KEY constraint: The combination of the NOT NULL constraint and the UNIQUE constraint.

      For example, both the ware table and cust table have primary key columns named w_id and c_id, which do not accept NULL or duplicate values.

    • FOREIGN KEY constraint: enforces that the constrained column must only contain values from the primary key column of another table.

      For example, if a FOREIGN KEY constraint on the c_w_id column of the cust table refers to the w_id column of the ware table, the warehouses allocated to the customers must be warehouses in the ware table.

      By default, the FOREIGN KEY constraint is disabled for OceanBase tenants. You can set the foreign_key_checks variable to control whether to enable this constraint.

    Note

    OceanBase does not support adding or changing constraints with the ALTER TABLE statement. Therefore, you must define the constraints when using the CREATE TABLE statement to create a table.

    About default date/time settings for date/time columns

    We recommend that you specify a default value for a column with the NOT NULL constraint. For a date/time column, you can set the default value to the current date/time of the database.

    • Example: Specifying a default value for the date/time column of a table. You can use the SYSDATE or SYSTIMESTAMP function.
    obclient> create table t1(
        id bigint not null primary KEY
        , gmt_create datetime not null default current_timestamp 
        , gmt_modified datetime not null default current_timestamp 
    );
    Query OK, 0 rows affected (0.07 sec)
    
    obclient> insert into t1(id) values(1),(2),(3);
    Query OK, 3 rows affected (0.01 sec)
    Records: 3  Duplicates: 0  Warnings: 0
    
    obclient> select * from t1;
    +----+---------------------+---------------------+
    | id | gmt_create            | gmt_modified          |
    +----+---------------------+---------------------+
    |  1 | 2020-02-27 17:09:23 | 2020-02-27 17:09:23 |
    |  2 | 2020-02-27 17:09:23 | 2020-02-27 17:09:23 |
    |  3 | 2020-02-27 17:09:23 | 2020-02-27 17:09:23 |
    +----+---------------------+---------------------+
    3 rows in set (0.00 sec)
    

    Previous topic

    About auto-increment columns
    Last

    Next topic

    About table indexes
    Next
    What is on this page
    About default date/time settings for date/time columns