MSDN Documentation

Tutorials and Guides

Introduction to SQL

Welcome to this introductory tutorial on SQL (Structured Query Language). SQL is the standard language for relational database management systems. It is used to manage and manipulate data.

What is SQL?

SQL is a domain-specific language used in programming and designed for managing data held in a relational database management system (RDBMS), or for stream processing in a relational data stream management system (RDSMS).

  • Data Definition Language (DDL): Commands that define, delete and modify database objects like tables.
  • Data Manipulation Language (DML): Commands that manage data within schema objects.
  • Data Control Language (DCL): Commands that control access to data and the database.
  • Transaction Control Language (TCL): Commands that manage transactions within the database.

Why Learn SQL?

SQL is a fundamental skill for anyone working with data, including:

  • Database Administrators
  • Data Analysts
  • Data Scientists
  • Software Developers
  • Business Intelligence Professionals

Its widespread use makes it an invaluable tool for retrieving, analyzing, and manipulating information stored in databases.

Basic SQL Commands

Let's explore some of the most common SQL commands:

1. SELECT

The SELECT statement is used to query the database and retrieve data that matches criteria you specify.

Example: Fetching all records from a 'Customers' table

SELECT *
FROM Customers;

Example: Fetching specific columns

SELECT CustomerName, ContactName, Country
FROM Customers;

2. WHERE

The WHERE clause is used to filter records. It extracts only those records that fulfill a specified condition.

Example: Fetching customers from a specific country

SELECT CustomerName, City, Country
FROM Customers
WHERE Country = 'Mexico';

3. INSERT INTO

The INSERT INTO statement is used to add new records to a table.

Example: Inserting a new customer

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal', 'Tom B. Smith', 'Sinagoga 10', 'São Paulo', '05679-258', 'Brazil');

4. UPDATE

The UPDATE statement is used to modify existing records in a table.

Example: Updating a customer's city

UPDATE Customers
SET City = 'Berlin'
WHERE Country = 'Germany';

5. DELETE

The DELETE statement is used to delete existing records from a table.

Example: Deleting a customer

DELETE FROM Customers
WHERE CustomerName = 'Alfreds Futterkiste';

Next Steps

This tutorial provides a basic overview. Continue to the next section to explore more advanced concepts such as:

  • JOIN operations
  • Aggregate Functions (COUNT, SUM, AVG, etc.)
  • GROUP BY and HAVING clauses
  • Subqueries
  • Database design principles

Happy learning!