Introduction
When developing full-stack applications, understanding SQL and how to write queries is essential.
SQL (Structured Query Language) allows you to store, retrieve, and manipulate data in a relational database like SQL Server, MySQL, or PostgreSQL.
Even if you are mainly working on Angular, React, or ASP.NET Core, knowing SQL basics is critical for building functional applications.
This guide will explain SQL concepts, queries, and examples you can use in full-stack projects.
What is SQL?
SQL is a language used to communicate with relational databases.
It allows you to perform operations like:
Creating tables and databases
Inserting, updating, deleting data
Querying data
Managing relationships between tables
Common relational databases used in full-stack projects include:
SQL Server
MySQL
PostgreSQL
SQLite
Basic SQL Operations
SQL commands are usually categorized as:
DDL (Data Definition Language): Defines database structure.
DML (Data Manipulation Language): Manages data inside tables.
DCL (Data Control Language): Manages user permissions.
TCL (Transaction Control Language): Manages database transactions.
For full-stack projects, you will mostly use DDL and DML.
Step 1: Creating a Database and Tables
Create Database
CREATE DATABASE FullStackDB;
This command creates a new database named FullStackDB.
Use the Database
USE FullStackDB;
Create Table
Example: Create a Users table
CREATE TABLE Users (
Id INT PRIMARY KEY IDENTITY(1,1),
Name NVARCHAR(100) NOT NULL,
Email NVARCHAR(100) NOT NULL,
CreatedAt DATETIME DEFAULT GETDATE()
);
Id– Auto-increment primary key.NameandEmail– Text fields.CreatedAt– Timestamp for record creation.
Step 2: Inserting Data
To add data to the Users table:
INSERT INTO Users (Name, Email)
VALUES ('Rahul Sharma', '[email protected]');
INSERT INTO Users (Name, Email)
VALUES ('Priya Singh', '[email protected]');
Each row represents a user.
INSERT INTOis a DML command.
Step 3: Querying Data
Select All Data
SELECT * FROM Users;
Retrieves all columns and rows from the
Userstable.
Select Specific Columns
SELECT Name, Email FROM Users;
Retrieves only
NameandEmailcolumns.
Filter Data Using WHERE
SELECT * FROM Users
WHERE Name = 'Rahul Sharma';
Returns only the user with the specified name.
Step 4: Updating Data
UPDATE Users
SET Email = '[email protected]'
WHERE Name = 'Rahul Sharma';
UPDATEchanges existing data.WHEREensures only the intended row is updated.

Join the conversation! Your thoughts help the community grow.