Mastering MS Access: How to Create Tables and Write Custom SQL Queries
Why I Still Use SQL in Microsoft Access
When I first started working with databases, I realized that while MS Access has a "point-and-click" interface, it is much more powerful when you write the code yourself. In my latest project, I found that using raw SQL queries is faster and more reliable than the standard query builder.
I’ve recorded a full video tutorial showing my process, but in this post, I want to break down the logic behind creating tables and the SQL syntax you need to know.
Step 1: Planning the Table Structure
Before I touch the SQL view, I always define my table relationships. For this tutorial, we are using a Sales demo Database example.
My Pro-Tip: Always use a Primary Key with the AutoNumber type. It prevents duplicate records and makes your SQL Joins much easier later on.
Here is how to create a table.
Click on Create tab
Click on Table icon
After we create a table, we will see Table1 automatically. Then, we can edit our table design.
Then, Right click on Table1 from Left Pane to add Field Name and Data Type.
Save the table with name "Demo" for example.
Then, we can add Field Name and Data Type here.
Enter the following Field Name and Data Types. Then, click on 'Save' button to save the data.
ID: AutoNumber (Primary Key)
Product_Name: Short Text
Price: Currency
Stock_Level: Number
Step 2: Writing the SQL Query
In the blog, I show how to switch from the "Design View" to the "SQL View." This is where the real magic happens.
If we want to find all products that are low on stock, we don't need to filter manually. We can use this specific SQL script I wrote:
If we want to write SQL query, Go to Create Tab, then, Click on SQL Query icon.
Example SQL query:
Why this works: The WHERE clause allows us to isolate specific data, and ORDER BY ensures the most urgent items (lowest stock) appear at the top of our report.
Step 3: Common SQL Mistakes in Access
While writing this tutorial blog, I ran into a few syntax errors that are unique to Access. Here is how I fixed them:
Table Names with Spaces: If your table is named
Product List, you must use square brackets:[Product List].Date Formatting: Access requires
#symbols around dates (e.g.,#01/01/2026#), unlike MySQL which uses quotes.
Final Thoughts
Learning to bridge the gap between a visual database and raw code is a huge step for any developer. If you have questions about the specific SQL commands I used in the video, please leave a comment below!
Comments
Post a Comment