Introduction To SQL
Introduction To SQL
Kindergarten of SQL
Summary of Last Class
Database - a collection of data typically stored in tables
Types of Database - Relational, NoSQL, Hierarchical, Cloud Database etc
Advantages of Database
1. More Storage e.g Big data
2. Many people can use it at once
3. Can be secured with encryption etc
SQL means Structured Query Language
SQL Flavours -
SQL Commands
SQL Nomenclature; Columns - Field, Row - Record, RDBMS
Data types
CONNECT TO SERVER
OBJECT EXPLORER OVERVIEW
RESTORE DATABASE
... LET'S EXPLORE THE RESTORED SAMPLE DATABASE
Database Diagram
Tables
Normalization
Normalization rules divide larger tables into smaller tables and link them using
relationships. The purpose of Normalisation in SQL is to eliminate redundant
(repetitive) data and ensure data is stored logically.
SQL SYNTAX
SELECT & FROM STATEMENT
* , TOP, DISTINCT
COMMENT
--
/* & */
MULTIPLE DATABASE
e.g KCC.dbo.Customeers
SELECT + FROM
SELECT statement is used to retrieve data from a database table or tables.
The basic syntax of the SELECT statement in MSSQL is as follows:
SELECT *
FROM table_name;
NOTE: DISTINCT function is used to remove duplicate rows from the result set of a SELECT query. It returns only
unquie values
SUMMARIZATION DATA
ALIASING - AS clause
FILTERING
WHERE clause
TEXT - LIKE & NOT LIKE, WILDCARDS ( %, _ )
MULTIPLE CRITERIA
OR, AND, BETWEEN, IN
NULL VALUES
IS NULL & IS NOT NULL
ALIASING
The AS keyword is used to provide an alias or alternative name for a column or a
table in the SELECT statement. You can also alias by adding a space
SELECT column_name
FROM table_name AS alias_name;
FILTERING DATA
WHERE CLAUSE
The WHERE clause is used in the SELECT, UPDATE, and DELETE statements
to filter rows based on specified conditions. It allows you to retrieve, update,
or delete only those rows that meet the given criteria.
SELECT product_name
FROM products
WHERE category = 'Electronics' AND stock_quantity > 50;
COMPARISON OPERATORS
FILTERING TEXT
LIKE , NOT LIKE & WILDCARDS
Teaser - How would you write the wild card of a name that ends with 'e', has 't' as
the 3rd character, starts with 'A'
SQL SYNTAX
GROUPING - GROUP BY
Misspelling
Incorrect Capitalization
Keyword error
SAVING YOUR SCRIPT