Lesson Overview
Up to this point, the course focused on retrieving and manipulating data using SELECT, functions, joins, subqueries, set operators, and DML. In this final lesson, students move to a new level: designing table structures and controlling database access.
What is DDL?
DDL is used to define and modify the structure of database objects such as tables. With DDL, we can create a table, change its columns, rename it, or remove it completely.
Main DDL Commands
CREATE- create a new objectALTER- modify an existing objectDROP- remove an object permanently
Common Datatypes
CHAR(25)VARCHAR2(25)NUMBER(5,2)DATETIMESTAMP
Naming Rules
- Object names should not be more than 30 characters.
- Names may contain letters, numbers, underscore
_, dollar sign$, and hash#. - Names must start with a letter.
- Names should not be Oracle reserved keywords.
Constraint Types
Primary Key
Uniquely identifies each row in a table and cannot be null.
Unique
Prevents duplicate values in a column or group of columns.
Not Null
Forces the column to always contain a value.
Check
Validates a condition such as salary greater than 3000.
Foreign Key
Links data between tables and enforces referential integrity.
DDL Examples
Create a departments table with a primary key and a required department name.
Create an employees table with PK, CHECK, DEFAULT, and FK constraints.
Additional DDL Practice
What is DCL?
DCL is used to control access to database objects and users. It answers questions like: who can log in, who can read a table, and who can insert, update, or delete data.
System Privileges
These privileges control what a user can do in the database system itself, such as creating a session or creating tables.
Object Privileges
These privileges control what a user can do on a specific object such as a table: SELECT, INSERT, UPDATE, DELETE, ALTER, and more.
DCL Syntax
DCL Examples
DDL vs DCL
DDL
- Used to define or modify database structure
- Examples: CREATE, ALTER, DROP
- Focuses on tables and schema objects
DCL
- Used to control user access and permissions
- Examples: GRANT, REVOKE
- Focuses on security and privileges
Questions
Tasks
Task 1 - Build Two Related Tables
Create two tables:
- departments_test with department ID and department name
- employees_test with employee ID, employee name, salary, hire date, and department ID
Apply the correct constraints including primary key, not null, check, and foreign key.
Task 2 - Modify Structure
Add a new column, modify its datatype, rename it, then drop it.
Task 3 - Security Task
Create a user, grant create session, grant select and insert on one table, then revoke insert only.
Task 4 - Data Validation
Create a table with a salary check constraint and test inserting both valid and invalid salaries.
Challenge Task - Final Practice
Design a mini HR schema from scratch that includes:
- Departments table
- Employees table
- Constraints between them
- A separate user with limited privileges
Course Closing
Congratulations. By reaching this final lesson, students have completed a strong Oracle SQL foundation. Throughout the course, they learned:
- Basic SELECT statements and filtering
- Functions for characters, numbers, and dates
- Joins and relationships between tables
- Subqueries and set operators
- DML operations for changing data
- DDL for creating and managing table structures
- DCL for controlling user access and privileges
Oracle SQL is not only about writing queries. It is about understanding data, designing structure, enforcing rules, and managing access professionally. This course has prepared students for the next level: PL/SQL, Oracle APEX, and real database projects.