We’ll cover how to write and run SQL queries in VSCode – SELECT, INSERT, UPDATE, and DELETE against a MySQL database.
What SQL queries do
SQL (Structured Query Language) is how you talk to your database. You use it to fetch data, add new rows, update existing ones, or delete records.
Setting up your workspace in VSCode
Make sure the MySQL extension is installed and you are connected to your server (see the installation tutorial). Open a new SQL file and you are ready to go.
Writing your first query
Start with SELECT, which retrieves data from a table. If you have a customers table in my_database:
USE my_database;
SELECT * FROM customers;
USE picks the database. SELECT * fetches every column from every row in customers.
Selecting specific columns
You often only need certain columns:
SELECT name, email FROM customers;
That returns just name and email.
The WHERE clause
Filter rows with WHERE. To find a customer by name:
SELECT * FROM customers WHERE name = 'Alice Smith';
That returns only rows where name is ‘Alice Smith’.
Inserting data
Add a new row with INSERT INTO:
INSERT INTO customers (name, email, join_date) VALUES ('Bob Johnson', 'bob.johnson@example.com', '2024-01-01');
That adds Bob Johnson with his email and join date.
Updating existing data
Change a row with UPDATE:
UPDATE customers SET email = 'new.bob.johnson@example.com' WHERE name = 'Bob Johnson';
That updates Bob’s email. Always include a WHERE clause unless you mean to change every row.
Deleting data
Remove a row with DELETE:
DELETE FROM customers WHERE name = 'Bob Johnson';
That removes Bob’s record permanently.
Executing queries in VSCode
- Write your query in a SQL file.
- Right-click and select ‘Run MySQL Query’.
- Results appear in the output panel at the bottom.
Best practices for writing SQL queries
- Clarity over cleverness: write queries someone else (or future you) can read.
- Consistent formatting: capitalise SQL keywords and indent nested clauses.
- Comment your SQL: a short comment on a complex query saves time later.
Try combining AND and OR in WHERE clauses, and experiment with JOIN when you have more than one table. The more you write, the more natural it gets.

