Main menu
Definition

SQL injection

SQL injection is inserting malicious SQL code into queries destined for a backend database to alter, expose, or retrieve data in that database. Learn how SQL injection works, the main types, and how developers and administrators defend against it.

DTDevolutions Team·November 12, 2026·2 min read

What is SQL injection?

SQL injection (SQLi) is an attack on applications that build database queries from user input without handling that input safely. By typing specially crafted text into a form field, URL parameter, or API request, an attacker changes the meaning of the query. The database then runs commands the developer never intended, such as returning every user record or deleting a table.

How does SQL injection work?

  1. An application takes input, such as a username, and inserts it directly into a SQL statement.
  2. The attacker enters input that contains SQL syntax, for example a quote followed by a condition that is always true.
  3. The database receives the modified query and executes it.
  4. Depending on the flaw and the database account's permissions, the attacker can read data, bypass sign-in checks, modify records, or run administrative commands.

Types include in-band SQL injection (results appear in the response), blind SQL injection (the attacker infers results from behavior or timing), and out-of-band techniques that send data through another channel.

SQL injection vs. cross-site scripting

SQL injection targets the database behind an application by injecting SQL. Cross-site scripting (XSS) targets other users of a website by injecting scripts into pages. Both come from untrusted input being treated as code.

Why does SQL injection matter?

SQL injection is a long-known flaw that still appears in applications and can expose large amounts of sensitive data. The main defenses are parameterized queries (prepared statements), input validation, and secure frameworks. Limiting the privileges of the database account each application uses reduces the damage if a flaw is found.

Frequently asked questions

What is SQL injection?

SQL injection is inserting malicious SQL code into queries destined for a backend database to alter, expose, or retrieve data in that database.

How do you prevent SQL injection?

Use parameterized queries or prepared statements, validate input, avoid building SQL from strings, and give application database accounts only the permissions they need. Regular code reviews and application security testing help find injection flaws before attackers do.

Can a web application firewall stop SQL injection?

It can block many common attempts, but it is a safety net. Fixing the code with parameterized queries is the real solution.

Limit the database privileges attackers could reach

Discover privileged accounts, including SQL Server, and rotate their passwords automatically.

Explore Devolutions PAM

Related terms

Database

A database is a collection of data stored electronically.

Read now →

Zero-day attack

A zero-day attack is a cyberattack on a security vulnerability that is discovered by the attacker before the developer of the system or program.

Read now →

Penetration testing

Penetration testing is ethically attacking an organization's security posture to identify vulnerabilities.

Read now →