Docsity

Summary, Introduction to Databases and SQL Querying, Summaries of Database Management Systems (DBMS)

Toggle sidebar
bg1
Introduction to Databases, SQL,
and Querying
Databases with SQL
This document provides an introduction to databases and querying using
SQL.
Database Fundamentals
A database is a structured collection of data designed for efficient creation,
reading, updating, and deletion of information. A Database Management
System (DBMS) is the software used to interact with a database. Examples
of DBMS include MySQL, Oracle, PostgreSQL, and SQLite.
SQL, or Structured Query Language, is a language used to create, read,
update, and delete data within a database.
Querying with SQL
Querying involves retrieving specific information from a database.
Examples of queries include: "What's the most-liked post on our platform?",
"Is our number of daily users growing or shrinking?", and "Which songs are
most like the song a user just played?".
Tools like Visual Studio Code (VS Code) and SQLite can be used for
querying. The command sqlite3 FILENAME is used to open a SQLite
database. The .quit command exits the SQLite shell.
Basic SQL Syntax
The SELECT statement is fundamental for retrieving data. LIMIT and OFFSET
are used to control the number of results and starting point. The WHERE
clause filters data based on specified conditions.
Comparison operators include =, !=, and <>. NOT negates a condition. NULL
represents missing or unknown data; IS NULL and IS NOT NULL are used to
check for null values.
The LIKE operator is used for pattern matching. % represents zero or more
characters, while _ represents a single character.
AND and OR are used to combine multiple conditions. Parentheses () can be
used to group conditions.
Other comparison operators include >, <, >=, and <=. BETWEEN … AND …
specifies a range.
pf3

Partial preview of the text

Download Summary, Introduction to Databases and SQL Querying and more Summaries Database Management Systems (DBMS) in PDF only on Docsity!

Introduction to Databases, SQL,

and Querying

Databases with SQL

This document provides an introduction to databases and querying using SQL.

Database Fundamentals

A database is a structured collection of data designed for efficient creation, reading, updating, and deletion of information. A Database Management System (DBMS) is the software used to interact with a database. Examples of DBMS include MySQL, Oracle, PostgreSQL, and SQLite.

SQL, or Structured Query Language, is a language used to create, read, update, and delete data within a database.

Querying with SQL

Querying involves retrieving specific information from a database. Examples of queries include: "What's the most-liked post on our platform?", "Is our number of daily users growing or shrinking?", and "Which songs are most like the song a user just played?".

Tools like Visual Studio Code (VS Code) and SQLite can be used for querying. The command sqlite3 FILENAME is used to open a SQLite database. The .quit command exits the SQLite shell.

Basic SQL Syntax

The SELECT statement is fundamental for retrieving data. LIMIT and OFFSET are used to control the number of results and starting point. The WHERE clause filters data based on specified conditions.

Comparison operators include =, !=, and <>. NOT negates a condition. NULL represents missing or unknown data; IS NULL and IS NOT NULL are used to check for null values.

The LIKE operator is used for pattern matching. % represents zero or more characters, while _ represents a single character.

AND and OR are used to combine multiple conditions. Parentheses () can be used to group conditions.

Other comparison operators include >, <, >=, and <=. BETWEEN … AND … specifies a range.

ORDER BY sorts the results. ORDER BY … ASC sorts in ascending order (default), and ORDER BY … DESC sorts in descending order.

Aggregate functions include COUNT, AVG, MIN, MAX, and SUM. ROUND rounds a number to a specified number of decimal places. DISTINCT returns only unique values.

SQL Statement Examples

SELECT column FROM table; retrieves the specified column from the table.

SELECT COUNT(column) FROM table; counts the number of values in the specified column.

SELECT AVG(column) FROM table; calculates the average value of the specified column.

SELECT column FROM table WHERE condition; retrieves the specified column from the table, filtering by the specified condition.

SELECT column FROM table WHERE column = value; retrieves the specified column where the column equals the specified value.

SELECT column FROM table WHERE column LIKE pattern; retrieves the specified column where the column matches the specified pattern.

SELECT column FROM table WHERE condition0 AND condition1; retrieves the specified column where both condition0 and condition1 are true.

SELECT column FROM table WHERE condition0 OR condition1; retrieves the specified column where either condition0 or condition1 is true.

SELECT column FROM table WHERE condition ORDER BY column; retrieves the specified column, filtering by the condition and ordering by the specified column.

SELECT column FROM table WHERE condition ORDER BY column LIMIT number; retrieves the specified column, filtering by the condition, ordering by the specified column, and limiting the number of results.

Style Example

SELECT 'title' FROM 'longlist' WHERE 'author' = 'Fernanda Melchor'; is an example of a SQL query.

Data Examples

The following are examples of titles and authors:

The Overstory by Richard Powers Goodnight Moon by Margaret Wise Brown Frankenstein by Mary Shelley