DDL (Data Definition Language)
It is used to define the structure of the database schema, including creating, altering, and dropping schema objects like tables, views, indexes, and users.
CREATE
Creates a new database object.
Syntax
CREATE [schema_name.]object_type [object_name] ([object_definition]);
Example
CREATE TABLE Customers (
CustomerID NUMBER PRIMARY KEY,
CustomerName VARCHAR2(50) NOT NULL,
Email VARCHAR2(100) UNIQUE,
Phone VARCHAR2(20)
);
ALTER
Modifies the structure of an existing database object.
Syntax
ALTER [schema_name.]object_type [object_name] [alter_definition];
Example
ALTER TABLE Customers ADD Age NUMBER;
ALTER TABLE Orders MODIFY COLUMN OrderDate DATE FORMAT 'YYYY-MM-DD';
DROP
Removes a database object from the schema.
Syntax
DROP [schema_name.]object_type [object_name];
Example
DROP TABLE Orders;
TRUNCATE
Removes all rows from a table, but preserves the table structure. This is a faster alternative to DROP and then CREATE, but cannot be rolled back.
Syntax
TRUNCATE TABLE [schema_name.]table_name;
Example
TRUNCATE TABLE Orders;
COMMENT
Adds a comment to a database object to provide descriptive information
Syntax
COMMENT ON [schema_name.]object_type [object_name] IS 'comment_text';
Example
COMMENT ON TABLE Customers IS 'Stores customer information';
RENAME
Renames a database object.
Syntax
RENAME [schema_name.]object_type [old_name] TO [new_name];
Example
RENAME TABLE Users TO Application_Users;
Last updated
Was this helpful?