Database Languages – DDL (Data Definition Language) with Oracle Examples

Database Languages – DDL (Data Definition Language)

Comprehensive Oracle SQL examples and explanations for database structure management.

Database languages allow interaction with a DBMS. DDL (Data Definition Language) is used to define, create, modify, and delete database objects such as tables, indexes, views, and sequences.

1. What is DDL?

  • Defines database schema and structure.
  • Changes are permanent (auto-committed in Oracle).
  • Does not manipulate data (use DML for that).
  • Requires proper privileges (CREATE, ALTER, DROP).

2. Common DDL Commands

CommandPurposeOracle Example
CREATECreate a new database object
CREATE TABLE student (student_id NUMBER PRIMARY KEY, name VARCHAR2(50), course VARCHAR2(50));
ALTERModify an existing object
ALTER TABLE student ADD (email VARCHAR2(50));
DROPDelete a database object
DROP TABLE student;
TRUNCATERemove all rows, keep structure
TRUNCATE TABLE student;
RENAMERename an object
RENAME student TO student_old;

3. Oracle Examples in Detail

CREATE Table

CREATE TABLE employee (
    emp_id NUMBER PRIMARY KEY,
    emp_name VARCHAR2(50),
    dept_id NUMBER
);

ALTER Table

ALTER TABLE employee ADD (salary NUMBER(10,2));
ALTER TABLE employee MODIFY (emp_name VARCHAR2(100));

DROP Table

DROP TABLE employee;

TRUNCATE Table

TRUNCATE TABLE employee;

RENAME Table

RENAME employee TO emp_backup;

4. Key Points and Best Practices

  • DDL commands are auto-committed – changes are permanent.
  • Ensure proper privileges before executing DDL.
  • Take backups before DROP or TRUNCATE commands.
  • Use ALTER carefully to avoid data loss.

5. Summary

DDL is essential for database design, schema creation, and maintenance. Commands include CREATE, ALTER, DROP, TRUNCATE, RENAME. DDL affects the structure of database objects but not the data itself.

DDL, Data Definition Language, Oracle SQL, CREATE, ALTER, DROP, TRUNCATE, RENAME, DBMS tutorial, database structure

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন