MySQL — Syntax
SQL Statements
-- SELECT statement
SELECT * FROM users;
-- INSERT statement
INSERT INTO users (name, email) VALUES ('John', 'john@example.com');
-- UPDATE statement
UPDATE users SET name = 'Jane' WHERE id = 1;
-- DELETE statement
DELETE FROM users WHERE id = 1;
Syntax Rules
-- Statements end with semicolon
SELECT * FROM users;
-- Case insensitive
SELECT * FROM USERS;
select * from users;
-- Comments
-- Single line comment
/* Multi-line
comment */
Basic Syntax
-- CREATE DATABASE
CREATE DATABASE mydb;
-- CREATE TABLE
CREATE TABLE users (
id INT PRIMARY KEY,
name VARCHAR(100)
);
-- DROP TABLE
DROP TABLE users;
-- ALTER TABLE
ALTER TABLE users ADD email VARCHAR(100);
Clauses
-- SELECT with clauses
SELECT column1, column2
FROM table_name
WHERE condition
GROUP BY column
HAVING condition
ORDER BY column
LIMIT number;
Mini Practice
Write MySQL code that:
- Creates a database
- Creates a table
- Inserts data
- Queries with clauses
Up Next
Next: Learn about MySQL Data Types.
Related Topics
Frequently Asked Questions about Syntax
What is Syntax in MySQL?
Syntax is a fundamental concept in MySQL. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Syntax?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Syntax.
Why is Syntax important in MySQL?
Syntax is essential for MySQL development. Understanding this concept will help you write better code and solve real-world problems more effectively.