在 Oracle 中,您可以使用以下语法创建带有字段注释的表:

CREATE TABLE table_name
(
    column1 datatype [DEFAULT expr] [column_constraint],
    column2 datatype [DEFAULT expr] [column_constraint],
    ...
)
TABLESPACE tablespace_name
COMMENT ON COLUMN table_name.column1
    IS 'column1_comment';
COMMENT ON COLUMN table_name.column2
    IS 'column2_comment';
...
COMMENT ON TABLE table_name
    IS 'table_comment';

在上面的示例中,table_name 是要创建的表的名称,column1column2 等是表的列名称,datatype 是列的数据类型,DEFAULT expr 是可选的列默认值表达式,column_constraint 是可选的列约束。

TABLESPACE tablespace_name 是可选的表空间名称,用于指定表存储在特定的表空间中。

COMMENT ON COLUMN table_name.column1 IS 'column1_comment' 用于为 column1 列添加注释。

COMMENT ON TABLE table_name IS 'table_comment' 用于为整个表添加注释。

请注意,注释必须使用单引号括起来。

以下是一个示例:

CREATE TABLE employees
(
    employee_id   NUMBER(10) PRIMARY KEY,
    first_name    VARCHAR2(50),
    last_name     VARCHAR2(50),
    hire_date     DATE,
    salary        NUMBER(10,2)
)
TABLESPACE users
COMMENT ON COLUMN employees.employee_id
    IS 'Unique identifier for each employee';
COMMENT ON COLUMN employees.first_name
    IS 'First name of the employee';
COMMENT ON COLUMN employees.last_name
    IS 'Last name of the employee';
COMMENT ON COLUMN employees.hire_date
    IS 'Date when the employee was hired';
COMMENT ON COLUMN employees.salary
    IS 'Salary of the employee';
COMMENT ON TABLE employees
    IS 'Table to store employee information';

以上示例创建了一个名为 employees 的表,其中包含了 employee_idfirst_namelast_namehire_datesalary 五个列。每个列都有相应的注释,而整个表也有一个注释。

Oracle 创建表带字段注释 - 详细指南

原文地址: https://www.cveoy.top/t/topic/palq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录