⚡ 180+ new openings posted today

SQL in One Shot: A Beginner’s Guide

What is SQL Query Language ?

Answer : Full Form of SQL (Structured Query Language). SQL is a query language used to store, retrieve, and manipulate data in databases.

Database : Means Store Data in Structured Format (Rows & Columns).

For example, we have an Employees database. In the Employees database, we have a table that contains multiple rows and columns.

For example, an Employees table can contain 3 records:

Employee_IDEmployee_NameSalary
101Rahul10,000
102Priya20,000

We have 3 columns (Employee_ID, Employee_Name, Salary) and 2 rows (records).

What is CRUD Operation ?

Answer : CRUD stands for Create, Read, Update, and Delete. These are the 4 operations performed on data in a database.

C -> CREATE (For Example : Add a New Employees Record)

R -> READ (For Example : Retrieve the Employees Information)

U-> UPDATE (For Example : Modify Existing Information of Employees)

D -> Delete (For Example : Remove an Employee Record).

What are the different types of SQL commands / How many types of SQL commands are there, and what are they?

Answer : SQL commands are generally divided into 5 categories.

  1. DQL : (Data Query Language) – Example (SELECT).
  2. DDL : (Data Definition Language) – Example (CREATE , ALTER , DROP , TRUNCATE).
  3. DML :(Data Manipulation Language) – Example (INSERT , UPDATE , DELETE)
  4. DCL : (Data Control Language) – Example (GRANT , REVOKE)
  5. TCL : (Transaction Control Language) -Example (COMMIT, ROLLBACK , SAVEPOINT)

What is the difference between SQL and NoSQL databases ?

Answer : These are the 5 key differences between SQL and NoSQL databases.

Relational DatabaseNon Relational Database.
SQL DatabaseNoSQL Database
Data Stored in Tables (Row & Column)Data stored are either key-value pairs, document-based, graph databases
They have Predefined Schema (Fixed or Static)They have dynamic Schema
Example : PostgreSQL, MySQL, MS SQL ServerEg: MongoDB, Cassandra, Hbase

What are Data Types in SQL ?

Answer : Commonly Used Data Types in SQL

  1. int : Used to store(Whole Number) Values. Example (200 , 500 , 1000)
  2. float : Used to Specify the decimal point number. Example (10.5 , 99.99)
  3. Bool/ Boolean : used to specify Boolean values true and false.
  4. char : fixed length string that can contain numbers, letters, and special characters Example: CHAR(10)
  5. varchar : variable length string that can contain numbers, letters, and special characters. Example: VARCHAR(100)
  6. date : Used to store date. Displayed format is YYYY-MM-DD. Example: 2026-08-22
  7. datetime : Used to store both date and time. Displayed format is YYY-MM-DD HH:MM:SS Example: 2026-08-22 17:30:00

Note: Exact data types can vary between database systems.

What is a Table ?

Answer : A table is a database object used to store data in the form of rows and columns.

Employee_IDEmployee_NameSalary
101Rahul10,000
102Priya20,000

What is a row in Table ?

Answer : Row Represents a single record in a table.

What are ACID Properties ?

Answer : To Ensure the integrity of the database, there are a set of principles that ensure database transaction are processed reliably and safely.

ACID Stands for

A : Atomicity : (Either all Operations of the transactions are Completed Successfully or none of them are applied). For Example: Rahul sends ₹1,000 to Priya’s account. After the transaction, Rahul’s balance becomes ₹0 and Priya’s balance becomes ₹1,000. If the transaction fails at any point in between, the entire transaction should be rolled back, and the original balances should be restored. This is called Atomicity.

C : Consistency : (The transaction must take the database from one valid state to another valid state).

Example

Suppose Rahul has ₹1,000 and wants to send ₹500 to Priya.

Before the transaction:

AccountBalance
Rahul₹1,000
Priya₹500

After the transaction:

AccountBalance
Rahul₹500
Priya₹1,000

The total balance remains ₹1,500 before and after the transaction. If the transaction fails to send the money to Priya’s account, then the data becomes inconsistent.

I : Isolation : (Isolation means all transactions run independently, and one transaction will not affect another transaction.) For example, two people transferring money at the same time should not cause incorrect account balances.

D : Durability : Durability ensures that once a transaction is committed, its changes are permanently saved, even if the system fails. For Example : Once a Transaction is Successfully committed, the changes should remain saved even if the database system crashes afterwards.

What is a select Statement ?

Answer : The SQL SELECT statement is used to fetch data from a database table.

Example :

We have a Employees table:

Employee_IDEmployee_NameSalary
101Anjali5000
102Priya4000
103Amit6000

if you want to select all the fields from the table, use the following syntax:

Syntax : Select * from table_name;

Select * from Employees;

Return :

Employee_IDEmployee_NameSalary
101Anjali5000
102Priya4000
103Amit6000

To retrieve only specific columns:

Syntax : Select column1, column2….. from table_name;

Here column1 , column2… are the fields of a table whose values you want to fetch.

Select Employees_Name, Salary from Employees;

Return :

Employee_NameSalary
Anjali5000
Priya4000
Amit6000

How do you create a database in SQL ?

Answer : The SQL CREATE DATABASE statement is used to create a new SQL database.

Syntax :

The basic syntax of CREATE DATABASE statement is as follows :

CREATE DATABASE databasename;

Example :

if you want to create a new database JobDB, then the CREATE DATABASE statement would be as shown below:

CREATE DATABASE JobDB;

This creates a new database named JobDB.

How to Create a Table in SQL ?

Answer : The CREATE TABLE statement is used to create a new table in a database.

Syntax

The basic syntax of CREATE TABLE statement is as follows :

CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype
);

CREATE TABLE : This is the keyword telling the database system what you want to do.

table_name : name of the table

column[1,2,3] : name of the column.

data_type : Type of data we want to store in the particular column.

Example :

CREATE TABLE Employees (
Employee_ID INT,
Employee_Name VARCHAR(100),
Salary DECIMAL(10,2)
);

Each column stores a specific type of value:

  • Employee_ID → INT
    Stores whole numbers (integers).
    Example: 101, 102, 103
  • Employee_Name → VARCHAR(100)
    Stores text/string values with a maximum length of 100 characters.
    Example: 'Anjali', 'Priya', 'Amit'
  • Salary → DECIMAL(10,2)
    Stores numbers with decimal values. Here, 10 is the maximum total number of digits and 2 is the number of digits after the decimal point.
    Example: 50000.50, 45000.75

Employees Table

Employee_IDEmployee_NameSalary
INTVARCHAR(100)DECIMAL(10,2)

What is an INSERT INTO Statement ?

Answer : The INSERT INTO statement is used to insert new records in a table. There are two ways of using INSERT INTO statement for inserting rows.

Syntax :

The basic syntax of INSERT INTO statement is as follows :

INSERT INTO table_name (column1, column2, column3, …) VALUES (value1, value2, value3, …);

if you are adding values for all the columns of the table, you do not need to specify the column names in the SQL query However, make sure the order of the values is in the same order as the columns in the table. The INSERT INTO syntax would be as follows:

INSERT INTO table_name VALUES(value1, value2, value3, …)

Example

Suppose we have an Employees table:

Employee_IDEmployee_NameSalary
INTVARCHAR(100)DECIMAL(10,2)

We can insert a new employee using:

INSERT INTO Employees (Employee_ID, Employee_Name, Salary)
VALUES (101, ‘Amit’, 50000.50);

Employee_IDEmployee_NameSalary
101Amit50000.50

How to Add Multiple Records in a Table ?

Answer : We can also insert multiple records (more than one) records into a table by using INSERT INTO Statement.

Syntax :

INSERT INTO table_name (column1, column2, column3)
VALUES
(value1, value2, value3),
(value1, value2, value3),
(value1, value2, value3);

Suppose we have an Employees table and want to insert 3 records into the table:

INSERT INTO Employees (Employee_ID, Employee_Name, Salary)
VALUES
(101, ‘Anjali’, 50000.50),
(102, ‘Priya’, 45000.75),
(103, ‘Amit’, 55000.00);

Employee_IDEmployee_NameSalary
101Anjali50000.50
102Priya45000.75
103Amit55000.00

What is the DROP DATABASE Statement in SQL ?

Answer: The SQL DROP DATABASE Statement is used to drop or delete an existing SQL database. Dropping of the database will drop all database objects(tables, views etc). The user should have admin privileges for deleting a database. The DROP Statement cannot be rollback.

Syntax

The Basic syntax of DROP DATABASE statement is as follows :

DROP DATABASE database_name;

Suppose we have a database named Employees:

DROP DATABASE Employees;

This will permanently delete the Employees database, including all the tables and data stored inside it.

Note: Be careful when using DROP DATABASE because the database and its contents are removed.

What is the WHERE Clause ?

Answer : The WHERE Clause is used to filter records. It is used to extract only those records that fulfill a specified conditions.

Syntax

SELECT column_name FROM table_name WHERE conditions;

Example

Suppose we have an Employees table:

Employee_IDEmployee_NameSalary
101Anjali50000
102Priya45000
103Amit55000

If we want to find employees whose salary is greater than 50000:

SELECT *
FROM Employees
WHERE Salary > 50000;

Operators Used with the WHERE Clause

1. Comparison Operators

OperatorMeaningExample
=Equal toSalary = 50000
<> or !=Not equal toSalary <> 50000
>Greater thanSalary > 50000
<Less thanSalary < 50000
>=Greater than or equal toSalary >= 50000
<=Less than or equal toSalary <= 50000

2. Logical Operators

OperatorMeaningExample
ANDBoth conditions must be trueSalary > 40000 AND Salary < 60000
ORAt least one condition must be trueSalary > 50000 OR Employee_ID = 101
NOTReverses a conditionNOT Salary > 50000

3. Other Common Operators

OperatorPurposeExample
BETWEENChecks a rangeSalary BETWEEN 40000 AND 60000
INMatches multiple valuesEmployee_ID IN (101, 102)
LIKESearches for a patternEmployee_Name LIKE 'R%'
IS NULLChecks for NULL valuesSalary IS NULL
IS NOT NULLChecks for non-NULL valuesSalary IS NOT NULL

To fetch the record of the employee whose name is “Priya”:

SELECT *
FROM Employees
WHERE Employee_Name = ‘Priya’;

What is the UPDATE Statement in SQL ?

Answer : The SQL UPDATE statement is used to modify the existing records in a table. We can update single columns as well as multiple columns using UPDATE statement as per our requirement. We can use the WHERE clause with the UPDATE query to update the selected rows, otherwise all the rows would be affected.

Syntax

If you want to update a single record :

UPDATE table_name
SET column_name = value
WHERE condition;

We can update multiple columns in a single UPDATE statement by separating each column with a comma.

UPDATE table_name
SET column1 = value1,
column2 = value2
WHERE condition;

You can combine N number of conditions using the AND or the OR operators.

Example

Suppose we have an Employees table:

Employee_IDEmployee_NameSalary
101Anjali50000
102Priya45000
103Amit55000

If we want to update Priya’s salary to 5000

UPDATE Employees
SET Salary = 5000
WHERE Employee_Name = ‘Priya’;

After Update

Employee_IDEmployee_NameSalary
101Anjali50000
102Priya5000
103Amit55000

If we want to update Priya’s name and salary:

UPDATE Employees
SET Employee_Name = ‘Priyanka’,
Salary = 60000
WHERE Employee_ID = 102;

After Update

Employee_IDEmployee_NameSalary
101Anjali50000
102Priyanka60000
103Amit55000

What is the DELETE Statement in SQL ?

Answer: The SQL DELETE statement is used to delete existing records from a table. We can use the WHERE clause with a DELETE query to delete the selected rows, otherwise all the records would be deleted.

Syntax

DELETE FROM table_name
WHERE condition;

You can combine N number of conditions using the AND or the OR operator.

Example

Suppose we have an Employees table:

Employee_IDEmployee_NameSalary
101Anjali50000
102Priya45000
103Amit55000

If we want to delete Priya’s record:

DELETE FROM Employees
WHERE Employee_ID = 102;

After DELETE

Employee_IDEmployee_NameSalary
101Anjali50000
103Amit55000

DELETE Example without WHERE CLAUSE (Delete All Records)

Important: If you use DELETE without a WHERE clause, all records in the table will be deleted, but the table structure will remain.

To delete all records from a table, use the DELETE statement without a WHERE clause.

DELETE FROM Employees;

After DELETE

Employee_IDEmployee_NameSalary

What is the TRUNCATE Statement in SQL ?

Answer : The SQL TRUNCATE statement is used to remove all records from a table. It performs the same function as a DELETE statement without a WHERE Clause. if you want to truncate a table, the TRUNCATE TABLE statement cannot be rolled back.

Syntax

TRUNCATE TABLE table_name;

Suppose we have an Employees table:

Employee_IDEmployee_NameSalary
101Anjali50000
102Priya45000
103Amit55000

To remove all records:

TRUNCATE TABLE Employees;

After TRUNCATE

Employee_IDEmployee_NameSalary

The Employees table still exists, but all its records have been removed.

DELETE vs TRUNCATE

DELETETRUNCATE
Can delete specific rows using WHERERemoves all rows
WHERE can be usedWHERE cannot be used
Generally logs row-level deletionsGenerally performs a more bulk-oriented removal
Table structure remainsTable structure remains

What is the ALTER Statement in SQL ?

Answer : The SQL ALTER statement is used to add, delete, or modify columns in an existing table. The ALTER TABLE statement is also used to add and drop various constraints on an existing table.

Using ALTER, we can:

  • Add a new column
  • Modify a column
  • Rename a column
  • Drop a column

1. Add a Column

Suppose we have an Employees table:

Employee_IDEmployee_NameSalary
INTVARCHAR(100)DECIMAL(10,2)

To add a Department column:

ALTER TABLE Employees
ADD Department VARCHAR(30);

After adding the column:

Employee_IDEmployee_NameSalaryDepartment
INTVARCHAR(100)DECIMAL(10,2)VARCHAR(30)

2. Drop a Column

To remove the Salary column:

ALTER TABLE Employees
DROP COLUMN Salary;

3. Rename a Column

The syntax varies by database. For example, in PostgreSQL/MySQL:

ALTER TABLE Employees
RENAME COLUMN Employee_Name TO Name;

If we want to change the Salary column from INT to DECIMAL(10,2):

ALTER TABLE Employees
MODIFY Salary DECIMAL(10,2);

Important Points :

When we add a column using ALTER TABLE statement then it automatically adds those columns to the end of the table and updates values for each records in that column with NULL.

When we delete a column from a table, column and all the data it contains are deleted.

You cannot delete a column that has a CHECK constraint. You must first delete the constraint.

You cannot delete the column that has PRIMARY KEY or FOREIGN KEY constraint or other dependencies.

What is the RENAME Statement in SQL ?

Answer : The RENAME statement is used to change the name of an existing database object, such as a table or column.

Rename a Table

Syntax:

RENAME TABLE old_table_name TO new_table_name;

Suppose we have a table named Employees and want to rename it to Employee_Type:

RENAME TABLE Employees TO Employee_Type;

Now the table name is Employee_Type instead of Employees.

Rename a Column

For databases that support it through ALTER TABLE:

ALTER TABLE Employees
RENAME COLUMN Employee_Name TO Name;

Note: It will not change the existing data; it only changes the name of the existing database.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top