Structured Query Language (SQL)

"SQL, a powerful language for databases, lets you ask questions of your data and unlock hidden insights, no matter your technical background. With just a few basic SQL commands, you can transform raw data into meaningful information to guide decisions and fuel your projects."- Gemini 2024

DDL vs DML in SQL

In SQL (Structured Query Language), DDL and DML are two essential categories of commands used to interact with databases. DDL defines the structure of a database, and DML is used to manipulate its content.

Let's break down their differences:

DDL (Data Definition Language)
DML (Data Manipulation Language)
Key Differences between DDL and DML
Feature DDL DML
Purpose Defines database structure Manipulates data within the database
Operations Create, alter, drop database objects Insert, update, delete, retrieve data
Impact on data Modifies the schema, may not affect existing data Modifies existing data in tables
Use case Database design and creation phases Day-to-day interaction with data
Typical use during Database design and creation CRUD (Create, Read, Update, Delete) operations
WHERE clause usage Less common, for specific table modifications Frequently used to filter data for retrieval or modification
Introducing SQL

SQL (Structured Query Language) reigns supreme as the undisputed king of relational databases. It provides a universal language for interacting with these structured data stores, allowing you to retrieve, manipulate, and analyze information with ease. While the core functionalities remain consistent across SQL dialects, there are variations for specific needs. Popular examples include:

With SQL we can extract data from relational databases and turn the data into information for decision making in business, and exploration in scientific research.

These examples of SQL queries are based on the database structure provided online by Programiz.
-- Selecting all fields in all records in a table
select * from Orders;

-- Selecting some fields from all records in a table
select first_name, age from Customers;

-- Selecting a subset of records
select item from Orders where customer_id = 3;
select shipping_id from Shippings where status == "Pending";

-- Sorting the output
select * from Customers order by "last_name";

-- Getting distinct (unique) values in a field
select distinct "item" from Orders;

-- Selecting based on different conditions
select age from Customers where country == "USA";
select age from Customers where country != "USA";
select age from Customers where country in ("UK", "UAE");

select item from Orders where amount > 500;
select item from Orders where amount between 300 and 400;

-- Selecting based on multiple conditions with boolean expressions
select customer_id from Customers where country == "USA" and age > 30;
select customer_id from Customers where country == "USA" or age < 25;
select customer_id from Customers where country == "USA" and not age < 25;
    

Some content on this page partially generated with the help of Gemini, a large language model from Google AI. Learn more about Gemini.