0% found this document useful (0 votes)
36 views

SQL Beginners Class One

This document provides an introduction to SQL and databases. It outlines the course, including an overview of setting up a database environment and SQL statements. It also defines common SQL concepts like data types, tables, and queries.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

SQL Beginners Class One

This document provides an introduction to SQL and databases. It outlines the course, including an overview of setting up a database environment and SQL statements. It also defines common SQL concepts like data types, tables, and queries.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

SQL Beginners

_
O
Course

M
With Modupe Afolabi-Jombo

g_
in
m
co
be
@
_
O
M
g_
in
ABOUT ME!

m
● I am an undergraduate of English Language, OAU
● I am passionate about data analysis and my favourite analytical tool is
co
SQL
be

● Over the past two years, I have been actively learning and taking
multiple SQL courses
@

● I love teaching and sharing my knowledge on SQL.


CHECK IN
❖ What is your name?

_
❖ What do you do?

O
❖ Two truth and one lie

M
❖ What are your expectations from this course?

g_
in
m
co
be
@
COURSE OUTLINE

Class One

_
O
● Download, install and set up the database environment
● Database explained

M
● Hello SQL!!!
● SQL Statement

g_
● Commonly used symbols in SQL
● SQL data types

in
● SQL Constraints
● Creating a table

m
Assignment
co
be
@
DOWNLOAD,INSTALL AND SET UP
DATABASE ENVIRONMENT

_
O
This will be properly discussed in class.

M
g_
in
m
co
be
@
INTRODUCTION
Data means information, more specifically facts, figures, measurements and

_
amounts that we gather for analysis or reference. Data is literally everywhere

O
and anything that can be recorded or tracked.

M
g_
For instance, taking a record of how many glass of water you take per day is
a form of data.

in
m
Data needs to be stored and one of the places data can be stored is a
database system. SQL is a programming language that allows you
co
communicate with database systems.
be
@
A DATABASE

_
A database is an organized collection of structured information, or data,

O
typically stored electronically in a computer system. It is usually controlled by

M
a database management system (DBMS)

g_
For example, an online telephone directory uses a database to store data of

in
people, phone numbers, and other contact details.

m
A good database allows its users to interact with the data.
co
be
@
TYPES OF DATABASE

_
Two popular types of databases:

O
● Relational Database
● Non relational Database

M
g_
in
m
co
be
@
RELATIONAL DATABASE MANAGEMENT SYSTEM
A relational database management system (RDBMS) is a programme used

_
to create, update and manage relational databases. Example of popular

O
relational database are:

M
➔ MySQL

g_
➔ Oracle Database
➔ Microsoft SQL Server

in
➔ PostgreSQL etc.

m
co
A Relational Database System contains one or more objects called
tables. The data or information for the database are stored in these
be

tables.
@
TABLES

_
Tables composes of rows and columns. Columns are referred to

O
as fields or attributes while rows are referred to as records or

M
observations

g_
in
m
co
be
@
@
be
co
m
in
g_
M
O
_
HELLO SQL!!!

_
O
SQL stands for Structured query language

M
It is a programming language that is used for database creation and

g_
manipulation. It is used for creating, accessing, manipulating, updating,
deleting and retrieving data in database.

in
m
SQL is also called ‘sequel’
co
be
@
FEATURES OF SQL

_
★ SQL efficiently retrieves large amount of data within relational

O
databases

M
★ SQL allows you to manage databases without coding knowledge

g_
★ SQL is versatile as it works with various database systems eg Oracle,
IBM, Microsoft.

in
m
co
be
@
WHAT CAN SQL DO?
❖Execute queries against database

_
O
❖Retrieve, inserting, and deleting information from a database
❖Create new database and tables

M
❖Update records in a database

g_
❖Create stored procedures or views

in
m
co
be
@
SQL STATEMENTS

_
● Data Definition Language (DDL) : It is used for data description and structuring.

O
They are also used to alter database structure such as creating new tables and their

M
attribute. Some of this statement are: CREATE, DROP, ALTER and TRUNCATE

g_
● Data Query Language (DQL): It is used to retrieve data from the database or a table
to perform further operations on it. This statement is SELECT.
● Data Manipulation Language (DML): It is used to store, modify, update and delete

in
data. Some of these statements are: INSERT, UPDATE and DELETE

m
● Data Control Language (DCL): It deals with the rights, permissions and other control
co
of the database system. Some of these statements are GRANT and REVOKE.
● Transaction Control Language (TCL): is used to manage transactions in the
be

database. These are used to manage the changes made by DML statements. E.g
COMMIT, ROLLBACK,SAFEPOINT etc.
@
WHO CAN USE SQL?

_
Anyone can use SQL, as long as the person knows the commands. Database

O
programmers, website owners and application developers also use SQL to work on

M
their huge databases.

g_
in
m
co
be
@
COMMONLY USED SYMBOLS IN SQL

_
Some of the commonly used symbols in SQL are:

O
● Semicolon ; - This is used to end SQL statements or queries. It is always added to complete the
query.

M
● Open and close parentheses () - These have several uses. They are used to enclose data types,
conditions and sometimes names of columns. They are used in subqueries and also arithmetic

g_
equations.
● Comma , - It is used as a list separator such as in a series of columns or multiple field names.

in
● Inverted comma ‘ ‘ - This is used usually to enclose ‘strings’ of data types or conditions.
● Astericks * - The asterisk indicates “all” data, columns, or tables.

m
● Underscore _ - This is used in column or table name to identify them properly. It is also used as
an identifier.
co
be
@
SQL DATA TYPES

_
In SQL, every column is expected to have a name and a data type

O
M
A data type is an attribute that specifies the type of data a column can hold.

g_
The data type is a guideline for SQL to understand what type of data is expected inside of
each column, and it also identifies how SQL will interact with the stored data.

in
m
Data types in SQL are organized in the following categories:
co
be
@
EXTRACT NUMERIC

_
O
Bit : It is used to store binary digits like 0 or 1. The number of bits per value

M
is specified in size. It can be from 1 to 64 Eg 01010101…(up to 64). The
default size is 1

g_
in
Tiny int: it is used to store values between 0&255

m
Small Int: It can store values between -32768 and +32767
co
be

INT: It stores values between (-2147483648) to (+2147483647)


@
Decimal (size,d): An exact fixed size. The total number of digit is specified
in size. The number of digit after the decimal is specified in the d eg (3,1).

_
Note: the d can only be 0 or 1.

O
M
g_
in
m
co
be
@
APPROXIMATE NUMERIC

_
Float: This data type accommodates decimal numbers

O
M
STRINGS

g_
Char: Fixed width character string. Used to store characters up to 125.

in
Varchar: variable width character string. It can be used to store characters up to

256
m
co
Text: Holds a string with a maximum length of 65,535 bytes (21,844 characters)
be
@
DATE AND TIME

_
Date: Format (YYYY-MM-DD)

O
Time: Format (hh:mm:ss)

M
Timestamp: System time

g_
in
m
co
be
@
SQL CONSTRAINTS
They are used to specify rules for data in a table

_
O
These can be used when creating a table or a table can be altered to include these

M
constraints after they’ve been created.

g_
Constraints are used to limit the type of data that can go into a table. This ensures the

in
accuracy and reliability of the data in the table. If there is any violation between the
constraint and the data action, the action is aborted.

m
co
be
@
COMMON SQL CONSTRAINTS

_
● NOT NULL: Ensures that a column cannot have a NULL value

O
M
● UNIQUE: Ensures that all values in a column are different

g_
● PRIMARY KEY: A combination of a NOT NULL and UNIQUE. Uniquely identifies each
row in a table.

in
m
● FOREIGN KEY: Uniquely identifies a row/record in another table
co
● CHECK: Ensures that all values in a column satisfies a specific condition
be
@
CREATING A TABLE
The CREATE TABLE statement is used to create a new table in a database.

_
O
Syntax

M
CREATE TABLE table_name (

g_
column1 datatype,
column2 datatype,

in
column3 datatype,

); m
co
Example
Create Table Customer (
be

Customer_ID int(8) Primary Key,


First_Name VARCHAR(255) Not Null,
@

Last_Name VARCHAR(255) Not Null,


Customer_Email VARCHAR(255) Not
Null Unique,

_
Date_Of_Birth Date,

O
Address VARCHAR(255) Not Null,

M
Phone_Number Int(11) Not Null,
Gender Varchar(15)

g_
);

in
m
co
be
@

You might also like