Statements
MySQL statements are the actionable commands that interact with the database. They enable data creation, modification, and control within the database system. Common types of MySQL statements include Data Definition Language (DDL), Data Manipulation Language (DML), and Data Control Language (DCL).
Common Uses of MySQL Statements
- CREATE Statement: Creates new tables or databases.
- INSERT Statement: Adds new data to tables.
- UPDATE Statement: Modifies existing data.
- DELETE Statement: Removes data from tables.
- DROP Statement: Deletes tables or databases.
Examples
- CREATE Statement Example
CREATE TABLE customers (id INT, name VARCHAR(50));Explanation: Creates a
customerstable withidandnamecolumns. - INSERT Statement Example
INSERT INTO customers (id, name) VALUES (1, 'John Doe');Explanation: Adds a new record to the
customerstable. - UPDATE Statement Example
UPDATE customers SET name = 'Jane Doe' WHERE id = 1;Explanation: Updates the
nameof the customer withid1. - DELETE Statement Example
DELETE FROM customers WHERE id = 1;Explanation: Deletes the record where
idis 1. - DROP Statement Example
DROP TABLE customers;Explanation: Deletes the
customerstable.