Shivani Kumari
Last Updated: May 13, 2022


SQL Injection is a technique to use malicious code in SQL statements via webpage input.SQL injection occurs when you ask the user to enter the input like name, id but they enter a SQL statement that will manipulate your database.

It is one of the most common web hacking techniques and contaminates the database’s data.


  • An application that stores customer records where any customer can access and view his and her records by entering his unique and customer ID 
  • The customer enters the following in the input field 13452245 or 1=1.
  • As 1=1 holds true for all the records. Hence all the customer details are accessed irrespective of ID details which can be modified in the same way.

Consider the example given below:

No matter if the password is right or wrong. The backend code will change because 1=1 always returns true. So when we execute the query, it can easily access and modify the private information which is not meant to display to users.

Injection Types

There are three main types of Injection.

Error-based: Error-based injections are exploited by triggering errors in the database when invalid inputs are passed. In this method, attackers use error messages to return the entire query results or retrieve information on restructuring the query for further exploitation.

Union-based: Union-based SQL injection allows an attacker to extract information from the database by extending the results returned by the original query. Attackers can use the Union operator if the original or new queries have the same structure.

Blind-Based: Blind SQL injection is one of the most advanced types of Injection. These queries are performed carefully because they can overload a server through heavy automation.

Impact of  Injection

  • The hacker can get all the user details in the database, such as user details, credit card information, and social security numbers.
  • He can also get access to protected areas like the administrator portal.
  • It can also be possible to delete user data from the database.
  • All the online shopping applications, bank transactions use back-end database servers. If the hacker can exploit SQL injection, the entire server is compromised.

Prevention of Injection Attacks

  • We should use user authentication to validate input by predefined length and the type of Input.
  • Restricting the user to access private data by not providing the grant permission
  • We should use views to display data to users in reading mode only to preserve the data in the actual table.
  • A strong level of authentication is used for every change in the database.

Frequently Asked Questions

  1. What is SQL Injection?
    SQL injection is a strategy by which an attacker processes malicious SQL queries on the database by manipulating the input to the webpages. This database may contain sensitive business information, private customer details, or user lists. A successful SQL injection can result in the deletion of entire databases, unauthorized use of sensitive data, and unintended granting of administrative rights to a database.
  2. What is the root cause of SQL injection?
    The three root causes of SQL injection are combining data and code in the dynamic SQL statements, error revelation, and insufficient input validation.
  3. What are the preventions for injection attacks?
    We can prevent injection attacks by avoiding user-provided input directly into SQL statements. All database queries should be written as prepared statements with parameterized queries. It means that all SQL code for the query will be defined in advance, so the database can distinguish between user inputs and code and treat any malicious SQL query as data, not malicious code. Input validation or sanitation attempts to control user input the system receives.
  4. What is Blind SQL Injection?
    Blind SQL Injection is a method of SQL injection in which an attacker asks for true and false questions to the database. Attackers create more specific questions to the database to extract more information based on the error messages. 

Key Takeaways

We learned about Injection and its types in the database and management systems. We also learned injection can affect our database by retrieving sensitive and crucial data. There are different methods to prevent those attacks using user authentication and grant permission.

Visit here to learn more about different topics related to database and management systems. Ninjas don’t stop here check out the Top 100 SQL Problems to master frequently asked questions in big companies and land your dream job. Also, try  CodeStudio to practice a wide range of DSA questions asked in lots of interviews.

Was this article helpful ?
1 upvote


No comments yet

Be the first to share what you think