What SQL is
SQL (Structured Query Language) is the standard language for working with relational databases. Data in them is stored in tables with rows and columns, much like in Excel, only more powerful and with precise relationships between tables. With SQL you “ask” the database for data and change it.
SQL was created at IBM in the 1970s and is still one of the most widely used languages in IT.
Basic SQL commands
- SELECT: retrieve data, for example all orders from the last month.
- INSERT: add a new record, for example a new order.
- UPDATE: change an existing record, for example a price.
- DELETE: remove a record.
- CREATE / ALTER: create or change a table.
Sample query: SELECT meno, email FROM zakaznici WHERE mesto = 'Malacky'; returns the names and email addresses of customers from Malacky.
Where SQL is used
Almost everywhere data is stored. When you open a category in an online shop, the server sends an SQL query to the database and builds the page from the result. WordPress also stores posts, settings and WooCommerce orders in a database and works with them through SQL. On the backend, SQL is usually called from a programming language such as PHP.
Analysts use SQL too, for sales overviews, customer behaviour and data for reports.
Database systems that use SQL
- MySQL: the most common database for websites and WordPress.
- MariaDB: an open-source fork of MySQL, now standard on many hosting plans.
- PostgreSQL: a powerful database for more demanding applications.
- Microsoft SQL Server, Oracle: in enterprise systems.
- SQLite: a small database in a single file, used for example in mobile apps.
The core of the language is the same everywhere; only the advanced features differ.
SQL injection, the best-known threat
If a website doesn't check what people type into forms, an attacker can insert their own SQL command into a field and read or delete data from the database. The protection is properly written parameterised queries and an up-to-date system and plugins.
Databases and bespoke applications
A slow website is often held back by an unoptimised database. I can clean it up and speed it up as part of website speed optimisation, and design the database for a new system when building web applications.