Junior — Middle
Can you explain what the term DML means in the context of working with databases?
sobes.tech AI
Answer from AI
DML (Data Manipulation Language) is a part of SQL that is responsible for data modification operations in a database:
- INSERT — adding new records
- UPDATE — updating existing records
- DELETE — deleting records
- SELECT — data retrieval (sometimes considered separately)
Example in Python using the sqlite3 library:
import sqlite3
conn = sqlite3.connect('example.db')
cursor = conn.cursor()
# Adding a record
cursor.execute("INSERT INTO users (name, age) VALUES (?, ?)", ('Ivan', 30))
conn.commit()
# Updating a record
cursor.execute("UPDATE users SET age = ? WHERE name = ?", (31, 'Ivan'))
conn.commit()
# Deleting a record
cursor.execute("DELETE FROM users WHERE name = ?", ('Ivan',))
conn.commit()
conn.close()
Thus, DML is a set of commands for working with data inside tables.