SQL (Structured Query Language) is a programming language which is used to manage data stored in relational databases like MySQL, MS Access, SQL Server, Oracle, Sybase, Informix, Postgres etc.
SQL stands for Structured Query Language. SQL was developed in the 1970s by IBM Computer Scientists.
"SQL is not a database management system, but it is a query language which is used to store and retrieve the data from a database or in simple words SQL is a language that communicates with databases."
SQL Examples
Consider we have following CUSTOMERS table which stores customer's ID, Name, Age, Salary, City and Country −
ID |
Name |
Age |
Salary |
City |
Country |
1 |
Ramesh |
32 |
2000.00 |
Maryland |
USA |
2 |
Mukesh |
40 |
5000.00 |
New York |
USA |
3 |
Sumit |
45 |
4500.00 |
Muscat |
Oman |
4 |
Kaushik |
25 |
2500.00 |
Kolkata |
India |
5 |
Hardik |
29 |
3500.00 |
Bhopal |
India |
6 |
Komal |
38 |
3500.00 |
Saharanpur |
India |
7 |
Ayush |
25 |
3500.00 |
Delhi |
India |
SQL makes it easy to manipulate this data using simple DML (Data Manipulation Language) Statements. For example, if we want to list down all the customers from USA then following will be the SQL query.
SELECT * FROM CUSTOMERS WHERE country = 'USA';
This will produce the following result:
ID |
Name |
Age |
Salary |
City |
Country |
1 |
Ramesh |
32 |
2000.00 |
Maryland |
USA |
2 |
Mukesh |
40 |
5000.00 |
New York |
USA |
SQL Basic Commands
We have a list of standard SQL commands to interact with relational databases. These commands are CREATE, SELECT, INSERT, UPDATE, DELETE, DROP and TRUNCATE and can be classified into the following groups based on their nature −
Data Definition Language (DDL)
A Data Definition Language (DDL) is a computer language which is used to create and modify the structure of database objects which include tables, views, schemas, and indexes etc.
Command |
Description |
CREATE |
Creates a new table, a view of a
table, or other object in the database. |
ALTER |
Modifies an existing database
object, such as a table. |
DROP |
Deletes an entire table, a view of
a table or other objects in the database. |
TRUNCATE |
Truncates the entire table in a
go. |
Data Manipulation Language (DML)
A Data Manipulation Language (DML) is a computer programming language which is used for adding, deleting, and modifying data in a database.
Command |
Description |
SELECT |
Retrieves certain records from one
or more tables. |
INSERT |
Creates a record. |
UPDATE |
Modifies records. |
DELETE |
Deletes records. |
Data Control Language (DCL)
Data Control Language (DCL) is a computer programming language which is used to control the access to data stored in a database.
Command |
Description |
GRANT |
Gives a privilege to user |
REVOKE |
Takes back privileges granted from
user. |
Why to Learn SQL?
SQL (Structured Query Language) is a MUST for the students and working professionals to become a great Software Engineer specially when they are working in Software Development Domain. SQL is the most common language used almost in every application software including banking, finance, education, security etc. to store and manipulate data.
SQL is the standard language for any Relational Database System. All the Relational Data Base Management Systems (RDBMS) like MySQL, MS Access, Oracle, Sybase, Informix, Postgres and SQL Server use SQL as their standard database language.
Also, software industry is using different dialects of SQL, such as −
- MS SQL Server using T-SQL,
- Oracle using PL/SQL,
- MS Access version of SQL is called JET SQL (native format) etc.
SQL Applications
SQL is one of the most widely used Query Language over the databases. SQL provides following functionality to the database programmers −
- Execute different database queries against a database.
- Define the data in a database and manipulate that data.
- Create data in a relational database management system.
- Access data from the relational database management system.
- Create and drop databases and tables.
- Create and maintain database users.
- Create view, stored procedure, functions in a database.
- Set permissions on tables, procedures and views.
Prerequisites to Learn SQL
Though we have tried our best to present the SQL concepts in a simple and easy way, still before you start learning SQL concepts given in this tutorial, it is assumed that you are already aware about some basic concepts of computer science, what is a database, especially the basics of RDBMS and associated concepts.
This tutorial will give you enough understanding on the various concepts of SQL along with suitable examples so that you can start your Software Development journey immediately after finishing this tutorial.
SQL Online Quizzes
This SQL tutorial helps you prepare for technical interviews and certification exams. We have provided various quizzes and assignments to check your learning level. Given quizzes have multiple choice type of questions and their answers with short explanation.
Following is a sample quiz, try to attempt any of the given answers:
Q 1 - The SQL programming language was developed by which of the following:
B - Microsoft in 1980s
C - IBM in 1970s
D - None of the Above
Frequently Asked Questions about SQL
There are some very Frequently Asked Questions(FAQ) about SQL, this section tries to answer them briefly.
What are SQL skills?
SQL skills help software programmers and data experts maintain, create and retrieve information from relational databases like MySQL, Oracle, MS SQL Server etc., which store data into columns and rows. It also allows them to access, update, manipulate, insert and modify data in efficient way.
A relational database stores information in tabular form, with rows and columns representing different data attributes and the various relationships between the data values.
What are the 5 different types of SQL?
There are 5 main types of commands. DDL (Data Definition Language) commands, DML (Data Manipulation Language) commands, and DCL (Data Control Language) commands, Transaction Control Language(TCL) commands and Data Query Language(DQL) commands.
How long should it take to learn SQL?
SQL is very easy to learn. You can learn SQL in as little as two to three weeks. However, it can take months of practice before you feel comfortable using it. Determining how long it takes to learn SQL also depends on how you plan to use it. Following this SQL tutorial will give you enough confidence to work on any software development related to database.
What are the benefits of using SQL over Excel?
SQL queries are also more flexible and powerful than Excel formulas and SQL is fast which can handle large amount of data. Unlike Excel, SQL can handle well over one million fields of data with ease.
How do I start learning SQL?
Here are the summarized list of tips which you can follow to start learning SQL.
- First and the most important is to make your mind to learn SQL.
- Install MySQL or MariaDB database on your computer system.
- Follow our tutorial step by step starting from very begining.
- Read more articles, watch online courses or buy a book on SQL to enhance your knowledge in SQL.
- Try to develop a small software using PHP or Python which makes use of database.
What are the 4 basic commands in SQL?
Following are four basic SQL Operations or SQL Statements.
- SELECT statement selects data from database tables.
- UPDATE statement updates existing data into database tables.
- INSERT statement inserts new data into database tables.
- DELETE statement deletes existing data from database tables.
What are data types in SQL?
Following are following three SQL data types.
- String Data types.
- Numeric Data types.
- Date and time Data types.