Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Understanding SQL Statement Categories: DDL, DML, DQL, and DCL

Tech 1

Data Definition Language (DDL)

DDL encompasses commands used to define and modify database schema structures. These operations affect the organization and properties of database objects rather than the data itself. Key commands include:

  • CREATE: Establishes new database objects
  • ALTER: Modifies existing object structures
  • DROP: Removes database objects permanently

Example syntax for table creation:

CREATE TABLE users (
    user_id INT PRIMARY KEY,
    username VARCHAR(50),
    email VARCHAR(100),
    created_at TIMESTAMP
);

Structure modification examples:

-- Add new column
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;

-- Rename column
ALTER TABLE users CHANGE email user_email VARCHAR(120);

-- Remove column
ALTER TABLE users DROP COLUMN last_login;

-- Remove entire table
DROP TABLE users;

Data Manipulation Language (DML)

DML focuses on managing data within existing database structures. Unlike DDL which modifies schema definitions, DML operates exclusively on stored data values. Primary operations include:

  • INSERT: Adds new records to tables
  • UPDATE: Modifies existing record values
  • DELETE: Removes records from tables

Data manipulation examples:

-- Insert multiple records
INSERT INTO products (name, price, category) 
VALUES ('Laptop', 999.99, 'Electronics'),
       ('Mouse', 25.50, 'Accessories');

-- Update specific records
UPDATE inventory 
SET quantity = quantity - 10 
WHERE product_id = 123;

-- Delete matching records
DELETE FROM orders 
WHERE order_date < '2023-01-01';

Data Query Language (DQL)

DQL consists of commands designed for retrieving information from databases. The primary operation is data selection based on specified criteria.

Core query structure:

SELECT column_list 
FROM table_name 
WHERE conditions;

Query example:

SELECT employee_name, department, salary 
FROM staff 
WHERE salary > 50000 
ORDER BY salary DESC;

Data Control Language (DCL)

DCL manages access permissions and security settings for database users. These commands control who can perform specific actions within the database system.

Permission management commands:

  • GRANT: Assigns specific privileges to users
  • REVOKE: Removes previously assigned privileges

Access control examples:

-- Grant read access
GRANT SELECT ON customers TO analyst_role;

-- Grant full table access
GRANT ALL PRIVILEGES ON sales_data TO manager_user;

-- Remove update permission
REVOKE UPDATE ON inventory FROM warehouse_team;

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.