SQL: Basic Clause
Database and Database
Management System
A database is an organized
collection of data. Example:
bank, library
Database Management System
(DBMS) is a computer software that is
designed to manage, store, and
manipulate data.
Examples: MySQL, PostgreSQL,
Oracle
SQL (Structured Query
Language)
SQL is a language used in
programming to interact with the
database
SQL is the standard language that is
used in relational database
management system (RDMS)
SQL
Commands
DDL
Data Definition
Language
Change the table
structure which
includes creating
tables, deleting tables,
adding columns
Example:
- CREATE
- ALTER
- DROP
- TRUNCATE
DML
Data Manipulation
Language
Create changes on the
database
Example:
- INSERT
- UPDATE
- DELETE
DCL
Data Control
Language
Grant or revoke
authority over the
database
Example:
- GRANT
- REVOKE
TCL
Transaction Control
Language
Controlling changes
that are carried out by
DML
Example:
- COMMIT
- ROLLBACK
- SAVEPOINT
DQL
Data Query Language
Query data from the
database
Example:
- SELECT
PostgreSQL
Open-source RDBMS that
emphasizes extensibility and
SQL compliance
Types of Data in PostgreSQL
• INT: whole numbers
• FLOAT: positive or negative
number
• SERIAL: pseudo-type integer
• BOOLEAN: True/False
• DATE
• CHAR(n): Character, fixed-length,
blank-padded
• VARCHAR(n): Character, variable-
length
Examples of Queries
SELECT NamaKonsumen, Alamat FROM TabelKonsumen WHERE Deposit = 50000
Create a Database and Table
CREATE DATABASE nama_database;
DROP DATABASE nama_database;
Delete a Database and Table
Create a Database and Table
CREATE TABLE nama_tabel(
column1 datatype,
column2 datatype,
column3 datatype,
…);
CREATE TABLE karyawan(
id_karyawan SERIAL,
nama VARCHAR(32),
departemen VARCHAR(16),
posisi VARCHAR(16),
…);
Follow the
ordered
column
Insert the data into the table by using INSERT INTO
INSERT INTO
nama_tabel
VALUES
(value1, value2, value3, …);
INSERT INTO
nama_tabel (column1, column2,
column3,...)
VALUES
(value1, value2, value3, …);
Example
Delete the Data
DELETE FROM
nama_tabel
WHERE
kondisi;
Deleting data from the table with
a specific condition
DELETE FROM nama_tabel
Deleting all data from the table
Row or other data that
match the condition
will be deleted
ALTER TABLE - ADD COLUMN - DROP COLUMN - ALTER COLUMN
Add columns into the table
ALTER TABLE
nama_tabel
ADD COLUMN newcolumn1 datatype,
ADD COLUMN newcolumn2 datatype,
ADD COLUMN newcolumn3 datatype
…
ALTER TABLE
nama_tabel
DROP COLUMN newcolumn1,
DROP COLUMN newcolumn2,
DROP COLUMN newcolumn3
…
Delete columns in the table
ALTER TABLE nama_tabel ALTER COLUMN column_name TYPE
datatype
Change the data type in the column
You are hired as a data analyst by a small online store named Tokopaedi which is owned by Mr.
Edi. Tokopaedi does not have a database system and it is your job to build it. Your main tasks
as a data analyst are:
1. Create a database named Tokopaedi in PostgreSQL
2. Create a table named orders with its columns (you need to determine the data type of each
column based on their input)
The column’s header is marked with green
Create the Database
Create the Table
Remember the query:
CREATE TABLE_name of table
(column1 datatype, column2
datatype, column3 datatype,…)
And then click Run
Insert the Data
Query:
INSERT INTO
orders
VALUES ('CA-
2019-152156','CG-
12520',42420,'FUR-
BO-
10001798',261.96,2,
0,41.9136,'Furniture'
,'Bookcases','Bush
Somerset
Collection
Bookcase','11/8/201
9','11/11/2019','Seco
nd Class','Claire
Gute','Consumer','U
nited
States','Henderson',
'Kentucky','South’)
And then click Run
Don’t forget to write SELECT *
FROM orders. It is a query to
present the table
And then click Run
Result
Insert Another
Data Query:
INSERT INTO orders
VALUES ('CA-2019-
152156','CG-
12520',42420,'FUR-
CH-
10000454',731.94,3,0
,219.582,'Furniture','
Chairs','Hon Deluxe
Fabric Upholstered
Stacking Chairs
Rounded
Back','11/08/2019','1
1/11/2019','Second
Class','Claire
Gute','Consumer','U
nited
States','Henderson','
Kentucky','South’)
Then click Run
Result
SELECT * FROM orders to
present the Table
Follow me!
Instagram : elyadawigatip
Twitter : @EliNoBishamon
LinkedIn : https://www.linkedin.com/in/elyada-
wigati-pramaresti-1a2387170/
Bootcamp Data Analysis
by @myskill.id

SQL Basic Clause - Portfolio.pptx

  • 1.
  • 3.
    Database and Database ManagementSystem A database is an organized collection of data. Example: bank, library Database Management System (DBMS) is a computer software that is designed to manage, store, and manipulate data. Examples: MySQL, PostgreSQL, Oracle SQL (Structured Query Language) SQL is a language used in programming to interact with the database SQL is the standard language that is used in relational database management system (RDMS)
  • 4.
    SQL Commands DDL Data Definition Language Change thetable structure which includes creating tables, deleting tables, adding columns Example: - CREATE - ALTER - DROP - TRUNCATE DML Data Manipulation Language Create changes on the database Example: - INSERT - UPDATE - DELETE DCL Data Control Language Grant or revoke authority over the database Example: - GRANT - REVOKE TCL Transaction Control Language Controlling changes that are carried out by DML Example: - COMMIT - ROLLBACK - SAVEPOINT DQL Data Query Language Query data from the database Example: - SELECT
  • 5.
    PostgreSQL Open-source RDBMS that emphasizesextensibility and SQL compliance Types of Data in PostgreSQL • INT: whole numbers • FLOAT: positive or negative number • SERIAL: pseudo-type integer • BOOLEAN: True/False • DATE • CHAR(n): Character, fixed-length, blank-padded • VARCHAR(n): Character, variable- length
  • 6.
    Examples of Queries SELECTNamaKonsumen, Alamat FROM TabelKonsumen WHERE Deposit = 50000 Create a Database and Table CREATE DATABASE nama_database; DROP DATABASE nama_database; Delete a Database and Table
  • 7.
    Create a Databaseand Table CREATE TABLE nama_tabel( column1 datatype, column2 datatype, column3 datatype, …); CREATE TABLE karyawan( id_karyawan SERIAL, nama VARCHAR(32), departemen VARCHAR(16), posisi VARCHAR(16), …); Follow the ordered column Insert the data into the table by using INSERT INTO INSERT INTO nama_tabel VALUES (value1, value2, value3, …); INSERT INTO nama_tabel (column1, column2, column3,...) VALUES (value1, value2, value3, …); Example
  • 8.
    Delete the Data DELETEFROM nama_tabel WHERE kondisi; Deleting data from the table with a specific condition DELETE FROM nama_tabel Deleting all data from the table Row or other data that match the condition will be deleted
  • 9.
    ALTER TABLE -ADD COLUMN - DROP COLUMN - ALTER COLUMN Add columns into the table ALTER TABLE nama_tabel ADD COLUMN newcolumn1 datatype, ADD COLUMN newcolumn2 datatype, ADD COLUMN newcolumn3 datatype … ALTER TABLE nama_tabel DROP COLUMN newcolumn1, DROP COLUMN newcolumn2, DROP COLUMN newcolumn3 … Delete columns in the table ALTER TABLE nama_tabel ALTER COLUMN column_name TYPE datatype Change the data type in the column
  • 11.
    You are hiredas a data analyst by a small online store named Tokopaedi which is owned by Mr. Edi. Tokopaedi does not have a database system and it is your job to build it. Your main tasks as a data analyst are: 1. Create a database named Tokopaedi in PostgreSQL 2. Create a table named orders with its columns (you need to determine the data type of each column based on their input) The column’s header is marked with green
  • 12.
  • 13.
    Create the Table Rememberthe query: CREATE TABLE_name of table (column1 datatype, column2 datatype, column3 datatype,…) And then click Run
  • 14.
    Insert the Data Query: INSERTINTO orders VALUES ('CA- 2019-152156','CG- 12520',42420,'FUR- BO- 10001798',261.96,2, 0,41.9136,'Furniture' ,'Bookcases','Bush Somerset Collection Bookcase','11/8/201 9','11/11/2019','Seco nd Class','Claire Gute','Consumer','U nited States','Henderson', 'Kentucky','South’) And then click Run
  • 15.
    Don’t forget towrite SELECT * FROM orders. It is a query to present the table And then click Run
  • 16.
  • 17.
    Insert Another Data Query: INSERTINTO orders VALUES ('CA-2019- 152156','CG- 12520',42420,'FUR- CH- 10000454',731.94,3,0 ,219.582,'Furniture',' Chairs','Hon Deluxe Fabric Upholstered Stacking Chairs Rounded Back','11/08/2019','1 1/11/2019','Second Class','Claire Gute','Consumer','U nited States','Henderson',' Kentucky','South’) Then click Run
  • 18.
    Result SELECT * FROMorders to present the Table
  • 19.
    Follow me! Instagram :elyadawigatip Twitter : @EliNoBishamon LinkedIn : https://www.linkedin.com/in/elyada- wigati-pramaresti-1a2387170/ Bootcamp Data Analysis by @myskill.id