🏗️ DDL
CREATE, ALTER, DROP and friends: object definitions and schema changes.
| Snippet | |
|---|---|
| ☆CREATE TABLE — Create a heap table |
CREATE TABLE dept (id NUMBER, name VARCHAR2(20));
|
| ☆ALTER ADD COLUMN — Add a column to an existing table |
ALTER TABLE employees ADD hire_date DATE;
|
| ☆MODIFY COLUMN — Change a column datatype |
ALTER TABLE employees MODIFY salary NUMBER(10,2);
|
| ☆RENAME COLUMN — Rename a column |
ALTER TABLE employees RENAME COLUMN ename TO full_name;
|
| ☆DROP TABLE — Drop a table (recycle bin permitting) |
DROP TABLE dept;
|
| ☆CREATE SEQUENCE — Sequence for surrogate keys |
CREATE SEQUENCE emp_seq START WITH 1 INCREMENT BY 1;
|
| ☆CREATE SYNONYM — Alias an object owned by another schema |
CREATE SYNONYM emp_syn FOR hr.employees;
|
| ☆TRUNCATE TABLE — Fast delete of all rows (DDL, no rollback) |
TRUNCATE TABLE employees;
|
| ☆COMMENT ON COLUMN — Document a column in the dictionary |
COMMENT ON COLUMN employees.salary IS 'Monthly gross salary';
|