CREATE TABLE adds a new, fully-defined table to the current Oracle schema, allocating storage and registering metadata.
CREATE TABLE defines a new table and its columns, data types, defaults, and constraints inside the current schema. Once executed, Oracle allocates storage and registers the table in the data dictionary.
The statement starts with CREATE TABLE table_name (column definitions) followed by optional clauses such as constraints, tablespace, storage, and AS SELECT.Only the table owner or a user with CREATE ANY TABLE can execute it.
Select the smallest type that fits: NUMBER for numeric values, VARCHAR2 for variable strings, DATE/TIMESTAMP for temporal data, and CLOB/BLOB for large objects. Proper types lower storage and speed queries.
Inline constraints follow the column (customer_id NUMBER PRIMARY KEY). Out-of-line constraints appear after all columns (CONSTRAINT pk_customer PRIMARY KEY (customer_id)).Name constraints for easy debugging.
Yes. Append AS SELECT ... to populate the new table with query results.Oracle copies column names and types from the SELECT list unless you rename columns.
CREATE TABLE Orders (
id NUMBER GENERATED BY DEFAULT AS IDENTITY,
customer_id NUMBER NOT NULL,
order_date DATE DEFAULT SYSDATE,
total_amount NUMBER(10,2) CHECK (total_amount >= 0),
CONSTRAINT pk_orders PRIMARY KEY (id),
CONSTRAINT fk_orders_customer FOREIGN KEY (customer_id)
REFERENCES Customers(id)
)
TABLESPACE users;
Name constraints, always add primary keys, set NOT NULL on required columns, and document tables with COMMENT ON TABLE/COLUMN right after creation.Version-control all DDL scripts.
Query ALL_TABLES for its presence, DESCRIBE to inspect columns, and run SELECT COUNT(*) to confirm row counts when using AS SELECT.
Creating tables without primary keys makes joins error-prone; always declare one. Forgetting NOT NULL on essential columns allows bad data; add NOT NULL for mandatory fields.
Use ALTER TABLE to evolve structure and GRANT privileges so other users can query the new table.
.
From Oracle 12c onward, add GENERATED BY DEFAULT AS IDENTITY to the numeric column. Pre-12c versions require a sequence and trigger.
Yes. Use CREATE GLOBAL TEMPORARY TABLE ... ON COMMIT DELETE ROWS | PRESERVE ROWS to store session-specific data.
Use CREATE TABLE new_table AS SELECT * FROM old_table WHERE 1=0. The WHERE clause returns no rows, so only the definition is copied.