bg_image
header

Data Manipulation Language - DML

ChatGPT:

Data Manipulation Language (DML) is a subset of SQL (Structured Query Language) used to manage and manipulate data within a database. With DML, users can insert, query, update, and delete data — essentially everything you'd typically do with data stored in a database.

The main DML commands are:

Command Purpose
SELECT Retrieve data from a table
INSERT Add new data
UPDATE Modify existing data
DELETE Remove data
-- Insert
INSERT INTO customers (name, city) VALUES ('Müller', 'Berlin');

-- Query
SELECT * FROM customers WHERE city = 'Berlin';

-- Update
UPDATE customers SET city = 'Hamburg' WHERE name = 'Müller';

-- Delete
DELETE FROM customers WHERE name = 'Müller';

Key Points:

  • DML deals with the data inside tables, not with the structure of the tables themselves (that's handled by Data Definition Language, DDL).

  • DML operations can often be rolled back (undone), especially when transactions are supported.

In short: DML is the toolset you use to keep your database dynamic and interactive by constantly adding, reading, modifying, or deleting data.


Data Definition Language - DDL

Data Definition Language (DDL) is a part of SQL (Structured Query Language) that deals with defining and managing the structure of a database. DDL commands modify the metadata of a database, such as information about tables, schemas, indexes, and other database objects, rather than manipulating the actual data.

Key DDL Commands:

1. CREATE
Used to create new database objects like tables, schemas, views, or indexes.
Example:

CREATE TABLE Kunden (
    ID INT PRIMARY KEY,
    Name VARCHAR(50),
    Alter INT
);

2. ALTER
Used to modify the structure of existing objects, such as adding or removing columns.
Example:

ALTER TABLE Kunden ADD Email VARCHAR(100);

3. DROP
Permanently deletes a database object, such as a table.
Example:

DROP TABLE Kunden;

4. TRUNCATE
Removes all data from a table while keeping its structure intact. It is faster than DELETE as it does not generate transaction logs.
Example:

TRUNCATE TABLE Kunden;

Characteristics of DDL Commands:

  • Changes made by DDL commands are automatically permanent (implicit commit).
  • They affect the database structure, not the data itself.

DDL is essential for designing and managing a database and is typically used during the initial setup or when structural changes are required.