SlideShare a Scribd company logo
By:
Ashwini . S

 Explore basic commands and functions of SQL
 How to use SQL for data administration (to create
tables, indexes, and views)
 How to use SQL for data manipulation (to add,
modify, delete, and retrieve data)
 How to use SQL to query a database to extract useful
information
2
Objectives

 SQL functions fit into two broad categories:
 Data definition language
 SQL includes commands to:
 Create database objects, such as tables, indexes, and views
 Define access rights to those database objects
 Data manipulation language
 Includes commands to insert, update, delete, and
retrieve data within database tables
3
Introduction to SQL

 SQL is relatively easy to learn
 Basic command set has vocabulary of less than 100
words
 Nonprocedural language
 American National Standards Institute (ANSI)
prescribes a standard SQL
 Several SQL dialects exist
4
Introduction to SQL
(continued)
Introduction to SQL
(continued)
5
Introduction to SQL
(continued)
6
Introduction to SQL
(continued)
7

 Examine simple database model and database tables
that will form basis for many SQL examples
 Understand data environment
8
Data Definition
Commands
The Database Model
9

 Following two tasks must be completed:
 Create database structure
 Create tables that will hold end-user data
 First task:
 RDBMS creates physical files that will hold database
 Tends to differ substantially from one RDBMS to
another
10
Creating the Database

 Authentication
 Process through which DBMS verifies that only
registered users are able to access database
 Log on to RDBMS using user ID and password created
by database administrator
 Schema
 Group of database objects—such as tables and
indexes—that are related to each other
11
The Database Schema

 Data type selection is usually dictated by nature of
data and by intended use
 Pay close attention to expected use of attributes for
sorting and data retrieval purposes
12
Data Types
Data Types (continued)
13

 Use one line per column (attribute) definition
 Use spaces to line up attribute characteristics and
constraints
 Table and attribute names are capitalized
 NOT NULL specification
 UNIQUE specification
14
Creating Table
Structures

 Primary key attributes contain both a NOT NULL
and a UNIQUE specification
 RDBMS will automatically enforce referential
integrity for foreign keys
 Command sequence ends with semicolon
15
Creating Table
Structures (continued)

NOT NULL constraint
 Ensures that column does not accept nulls
UNIQUE constraint
 Ensures that all values in column are unique
DEFAULT constraint
 Assigns value to attribute when a new row is
added to table
CHECK constraint
 Validates data when attribute value is entered
16
SQL Constraints

When primary key is declared, DBMS
automatically creates unique index
Often need additional indexes
Using CREATE INDEX command, SQL
indexes can be created on basis of any
selected attribute
Composite index
 Index based on two or more attributes
 Often used to prevent data duplication
17
SQL Indexes

 Adding table rows
 Saving table changes
 Listing table rows
 Updating table rows
 Restoring table contents
 Deleting table rows
 Inserting table rows with a select subquery
18
Data Manipulation
Commands

 INSERT
 Used to enter data into table
 Syntax:
 INSERT INTO columnname
VALUES (value1, value2, … , valuen);
19
Adding Table Rows

When entering values, notice that:
 Row contents are entered between parentheses
 Character and date values are entered between
apostrophes
 Numerical entries are not enclosed in apostrophes
 Attribute entries are separated by commas
 A value is required for each column
Use NULL for unknown values
20
Adding Table Rows
(continued)

Changes made to table contents are not
physically saved on disk until, one of the
following occurs:
 Database is closed
 Program is closed
 COMMIT command is used
Syntax:
 COMMIT [WORK];
Will permanently save any changes made to
any table in the database
21
Saving Table Changes

 SELECT
 Used to list contents of table
 Syntax:
 SELECT columnlist
FROM tablename;
 Columnlist represents one or more attributes,
separated by commas
 Asterisk can be used as wildcard character to list all
attributes
22
Listing Table Rows

 UPDATE
 Modify data in a table
 Syntax:
 UPDATE tablename
SET columnname = expression [, columname = expression]
[WHERE conditionlist];
 If more than one attribute is to be updated in row,
separate corrections with commas
23
Updating Table Rows

 ROLLBACK
 Used to restore database to its previous condition
 Only applicable if COMMIT command has not
been used to permanently store changes in
database
 Syntax:
 ROLLBACK;
 COMMIT and ROLLBACK only work with data
manipulation commands that are used to add,
modify, or delete table rows
24
Restoring Table
Contents

 DELETE
 Deletes a table row
 Syntax:
 DELETE FROM tablename
[WHERE conditionlist ];
 WHERE condition is optional
 If WHERE condition is not specified, all rows from
specified table will be deleted
25
Deleting Table Rows

 INSERT
 Inserts multiple rows from another table (source)
 Uses SELECT sub query
 Query that is embedded (or nested) inside another query
 Executed first
 Syntax:
 INSERT INTO table name SELECT columnist FROM table
name;
26
Inserting Table Rows with a
Select Sub query

 Select partial table contents by placing restrictions on
rows to be included in output
 Add conditional restrictions to SELECT statement,
using WHERE clause
 Syntax:
 SELECT columnlist
FROM tablelist
[ WHERE conditionlist ] ;
27
Selecting Rows with
Conditional Restrictions
Selecting Rows with
Conditional Restrictions (continued)
28
Selecting Rows with
Conditional Restrictions (continued)
29

 Perform operations within parentheses
 Perform power operations
 Perform multiplications and divisions
 Perform additions and subtractions
30
Arithmetic Operators:
The Rule of Precedence
Arithmetic Operators:
The Rule of Precedence (continued)
31

 BETWEEN
 Used to check whether attribute value is within a
range
 IS NULL
 Used to check whether attribute value is null
 LIKE
 Used to check whether attribute value matches given
string pattern
32
Special Operators

 IN
 Used to check whether attribute value matches any
value within a value list
 EXISTS
 Used to check if subquery returns any rows
33
Special Operators
(continued)

 All changes in table structure are made by using
ALTER command
 Followed by keyword that produces specific change
 Following three options are available:
 ADD
 MODIFY
 DROP
34
Advanced Data
Definition Commands

 ALTER can be used to change data type
 Some RDBMSs (such as Oracle) do not permit
changes to data types unless column to be changed is
empty
35
Changing a Column’s
Data Type

 Use ALTER to change data characteristics
 If column to be changed already contains data,
changes in column’s characteristics are permitted if
those changes do not alter the data type
36
Changing a Column’s
Data Characteristics

 Use ALTER to add column
 Do not include the NOT NULL clause for new column
37
Adding a Column

 Use ALTER to drop column
 Some RDBMSs impose restrictions on the deletion of
an attribute
38
Dropping a Column
Advanced Data Updates
39

 SQL permits copying contents of selected table
columns so that the data need not be reentered
manually into newly created table(s)
 First create the PART table structure
 Next add rows to new PART table using PRODUCT
table rows
40
Copying Parts of Tables

 When table is copied, integrity rules do not copy, so
primary and foreign keys need to be manually
defined on new table
 User ALTER TABLE command
 Syntax:
 ALTER TABLE tablename ADD
PRIMARY KEY(fieldname);
 For foreign key, use FOREIGN KEY in place of
PRIMARY KEY
41
Adding Primary and Foreign Key
Designations

 DROP
 Deletes table from database
 Syntax:
 DROP TABLE tablename;
42
Deleting a Table from the
Database

 SQL provides useful functions that can:
 Count
 Find minimum and maximum values
 Calculate averages
 SQL allows user to limit queries to only those entries
having no duplicates or entries whose duplicates
may be grouped
43
Advanced Select
Queries
Aggregate Functions
44
Aggregate Functions
(continued)
45
Aggregate Functions
(continued)
46
Aggregate Functions
(continued)
47
Aggregate Functions
(continued)
48
Grouping Data
49
Grouping Data
(continued)
50
Grouping Data
(continued)
51

 View is virtual table based on SELECT query
 Can contain columns, computed columns, aliases, and
aggregate functions from one or more tables
 Base tables are tables on which view is based
 Create view by using CREATE VIEW command
52
Virtual Tables: Creating
a View
Virtual Tables: Creating a
View (continued)
53

 Ability to combine (join) tables on common
attributes is most important distinction between
relational database and other databases
 Join is performed when data are retrieved from more
than one table at a time
 Join is generally composed of an equality
comparison between foreign key and primary key of
related tables
54
Joining Database Tables

 Alias can be used to identify source table
 Any legal table name can be used as alias
 Add alias after table name in FROM clause
55
Joining Tables with an
Alias

 SQL commands can be divided into two overall
categories:
 Data definition language commands
 Data manipulation language commands
 The ANSI standard data types are supported by all
RDBMS vendors in different ways
 Basic data definition commands allow you to create
tables, indexes, and views
56
Summary

DML commands allow you to add, modify,
and delete rows from tables
The basic DML commands are SELECT,
INSERT, UPDATE, DELETE, COMMIT, and
ROLLBACK
INSERT command is used to add new rows
to tables
SELECT statement is main data retrieval
command in SQL
57
Summary (continued)

 Many SQL constraints can be used with columns
 The column list represents one or more column
names separated by commas
 WHERE clause can be used with SELECT, UPDATE,
and DELETE statements to restrict rows affected by
the DDL command
58
Summary (continued)

 Aggregate functions
 Special functions that perform arithmetic
computations over a set of rows
 ORDER BY clause
 Used to sort output of SELECT statement
 Can sort by one or more columns and use either an
ascending or descending order
 Join output of multiple tables with SELECT
statement
59
Summary (continued)

 Natural join uses join condition to match only rows
with equal values in specified columns
 Right outer join and left outer join used to select
rows that have no matching values in other related
table
60
Summary (continued)

More Related Content

Similar to Introduction to Structured Query Language (SQL).ppt (20)

Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
Dhani Ahmad
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
SakkaravarthiS1
 
Introduction to database and sql fir beginers
Introduction to database and sql fir beginersIntroduction to database and sql fir beginers
Introduction to database and sql fir beginers
reshmi30
 
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptxMy lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
EliasPetros
 
Complete SQL Tutorial In Hindi By Rishabh Mishra (Basic to Advance).pdf
Complete SQL Tutorial In Hindi By Rishabh Mishra (Basic to Advance).pdfComplete SQL Tutorial In Hindi By Rishabh Mishra (Basic to Advance).pdf
Complete SQL Tutorial In Hindi By Rishabh Mishra (Basic to Advance).pdf
PreetiKushwah6
 
Lab
LabLab
Lab
neelam_rawat
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
HudaRaghibKadhim
 
Database Overview
Database OverviewDatabase Overview
Database Overview
Livares Technologies Pvt Ltd
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2
Raj vardhan
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
PavithSingh
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
jainendraKUMAR55
 
Sql commands
Sql commandsSql commands
Sql commands
Pooja Dixit
 
SQL DDL
SQL DDLSQL DDL
SQL DDL
Vikas Gupta
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
EliasPetros
 
Sql basic things
Sql basic thingsSql basic things
Sql basic things
Nishil Jain
 
Lesson 2_Working_with_Tables_and_SQL_Commands.pptx
Lesson 2_Working_with_Tables_and_SQL_Commands.pptxLesson 2_Working_with_Tables_and_SQL_Commands.pptx
Lesson 2_Working_with_Tables_and_SQL_Commands.pptx
quantumlearnai
 
chapter 8 SQL.ppt
chapter 8 SQL.pptchapter 8 SQL.ppt
chapter 8 SQL.ppt
YitbarekMurche
 
SQL
SQLSQL
SQL
Shyam Khant
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
Abrar ali
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
Sheethal Aji Mani
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
Dhani Ahmad
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
SakkaravarthiS1
 
Introduction to database and sql fir beginers
Introduction to database and sql fir beginersIntroduction to database and sql fir beginers
Introduction to database and sql fir beginers
reshmi30
 
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptxMy lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
EliasPetros
 
Complete SQL Tutorial In Hindi By Rishabh Mishra (Basic to Advance).pdf
Complete SQL Tutorial In Hindi By Rishabh Mishra (Basic to Advance).pdfComplete SQL Tutorial In Hindi By Rishabh Mishra (Basic to Advance).pdf
Complete SQL Tutorial In Hindi By Rishabh Mishra (Basic to Advance).pdf
PreetiKushwah6
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2
Raj vardhan
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
PavithSingh
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
jainendraKUMAR55
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
EliasPetros
 
Sql basic things
Sql basic thingsSql basic things
Sql basic things
Nishil Jain
 
Lesson 2_Working_with_Tables_and_SQL_Commands.pptx
Lesson 2_Working_with_Tables_and_SQL_Commands.pptxLesson 2_Working_with_Tables_and_SQL_Commands.pptx
Lesson 2_Working_with_Tables_and_SQL_Commands.pptx
quantumlearnai
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
Abrar ali
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
Sheethal Aji Mani
 

More from Ashwini Rao (11)

digitalcartography in gis-200627114438 (1).pdf
digitalcartography in gis-200627114438 (1).pdfdigitalcartography in gis-200627114438 (1).pdf
digitalcartography in gis-200627114438 (1).pdf
Ashwini Rao
 
3-1_geo Spatial analysis_spatial_modeling.pptx
3-1_geo Spatial analysis_spatial_modeling.pptx3-1_geo Spatial analysis_spatial_modeling.pptx
3-1_geo Spatial analysis_spatial_modeling.pptx
Ashwini Rao
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
Ashwini Rao
 
documents.pub_erdas-imagine-58b93d882adab.pptx
documents.pub_erdas-imagine-58b93d882adab.pptxdocuments.pub_erdas-imagine-58b93d882adab.pptx
documents.pub_erdas-imagine-58b93d882adab.pptx
Ashwini Rao
 
health and hygiene [Autosaved].pptx
health and hygiene [Autosaved].pptxhealth and hygiene [Autosaved].pptx
health and hygiene [Autosaved].pptx
Ashwini Rao
 
lec-gps (2).ppt
lec-gps (2).pptlec-gps (2).ppt
lec-gps (2).ppt
Ashwini Rao
 
lecture10.ppt
lecture10.pptlecture10.ppt
lecture10.ppt
Ashwini Rao
 
CS1Lesson15-Inheritance.pptx
CS1Lesson15-Inheritance.pptxCS1Lesson15-Inheritance.pptx
CS1Lesson15-Inheritance.pptx
Ashwini Rao
 
Intro_GIS.ppt
Intro_GIS.pptIntro_GIS.ppt
Intro_GIS.ppt
Ashwini Rao
 
GPS-1.ppt
GPS-1.pptGPS-1.ppt
GPS-1.ppt
Ashwini Rao
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
Ashwini Rao
 
digitalcartography in gis-200627114438 (1).pdf
digitalcartography in gis-200627114438 (1).pdfdigitalcartography in gis-200627114438 (1).pdf
digitalcartography in gis-200627114438 (1).pdf
Ashwini Rao
 
3-1_geo Spatial analysis_spatial_modeling.pptx
3-1_geo Spatial analysis_spatial_modeling.pptx3-1_geo Spatial analysis_spatial_modeling.pptx
3-1_geo Spatial analysis_spatial_modeling.pptx
Ashwini Rao
 
documents.pub_erdas-imagine-58b93d882adab.pptx
documents.pub_erdas-imagine-58b93d882adab.pptxdocuments.pub_erdas-imagine-58b93d882adab.pptx
documents.pub_erdas-imagine-58b93d882adab.pptx
Ashwini Rao
 
health and hygiene [Autosaved].pptx
health and hygiene [Autosaved].pptxhealth and hygiene [Autosaved].pptx
health and hygiene [Autosaved].pptx
Ashwini Rao
 
CS1Lesson15-Inheritance.pptx
CS1Lesson15-Inheritance.pptxCS1Lesson15-Inheritance.pptx
CS1Lesson15-Inheritance.pptx
Ashwini Rao
 
Ad

Recently uploaded (20)

TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
National Information Standards Organization (NISO)
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptxRai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Ad

Introduction to Structured Query Language (SQL).ppt

  • 2.   Explore basic commands and functions of SQL  How to use SQL for data administration (to create tables, indexes, and views)  How to use SQL for data manipulation (to add, modify, delete, and retrieve data)  How to use SQL to query a database to extract useful information 2 Objectives
  • 3.   SQL functions fit into two broad categories:  Data definition language  SQL includes commands to:  Create database objects, such as tables, indexes, and views  Define access rights to those database objects  Data manipulation language  Includes commands to insert, update, delete, and retrieve data within database tables 3 Introduction to SQL
  • 4.   SQL is relatively easy to learn  Basic command set has vocabulary of less than 100 words  Nonprocedural language  American National Standards Institute (ANSI) prescribes a standard SQL  Several SQL dialects exist 4 Introduction to SQL (continued)
  • 8.   Examine simple database model and database tables that will form basis for many SQL examples  Understand data environment 8 Data Definition Commands
  • 10.   Following two tasks must be completed:  Create database structure  Create tables that will hold end-user data  First task:  RDBMS creates physical files that will hold database  Tends to differ substantially from one RDBMS to another 10 Creating the Database
  • 11.   Authentication  Process through which DBMS verifies that only registered users are able to access database  Log on to RDBMS using user ID and password created by database administrator  Schema  Group of database objects—such as tables and indexes—that are related to each other 11 The Database Schema
  • 12.   Data type selection is usually dictated by nature of data and by intended use  Pay close attention to expected use of attributes for sorting and data retrieval purposes 12 Data Types
  • 14.   Use one line per column (attribute) definition  Use spaces to line up attribute characteristics and constraints  Table and attribute names are capitalized  NOT NULL specification  UNIQUE specification 14 Creating Table Structures
  • 15.   Primary key attributes contain both a NOT NULL and a UNIQUE specification  RDBMS will automatically enforce referential integrity for foreign keys  Command sequence ends with semicolon 15 Creating Table Structures (continued)
  • 16.  NOT NULL constraint  Ensures that column does not accept nulls UNIQUE constraint  Ensures that all values in column are unique DEFAULT constraint  Assigns value to attribute when a new row is added to table CHECK constraint  Validates data when attribute value is entered 16 SQL Constraints
  • 17.  When primary key is declared, DBMS automatically creates unique index Often need additional indexes Using CREATE INDEX command, SQL indexes can be created on basis of any selected attribute Composite index  Index based on two or more attributes  Often used to prevent data duplication 17 SQL Indexes
  • 18.   Adding table rows  Saving table changes  Listing table rows  Updating table rows  Restoring table contents  Deleting table rows  Inserting table rows with a select subquery 18 Data Manipulation Commands
  • 19.   INSERT  Used to enter data into table  Syntax:  INSERT INTO columnname VALUES (value1, value2, … , valuen); 19 Adding Table Rows
  • 20.  When entering values, notice that:  Row contents are entered between parentheses  Character and date values are entered between apostrophes  Numerical entries are not enclosed in apostrophes  Attribute entries are separated by commas  A value is required for each column Use NULL for unknown values 20 Adding Table Rows (continued)
  • 21.  Changes made to table contents are not physically saved on disk until, one of the following occurs:  Database is closed  Program is closed  COMMIT command is used Syntax:  COMMIT [WORK]; Will permanently save any changes made to any table in the database 21 Saving Table Changes
  • 22.   SELECT  Used to list contents of table  Syntax:  SELECT columnlist FROM tablename;  Columnlist represents one or more attributes, separated by commas  Asterisk can be used as wildcard character to list all attributes 22 Listing Table Rows
  • 23.   UPDATE  Modify data in a table  Syntax:  UPDATE tablename SET columnname = expression [, columname = expression] [WHERE conditionlist];  If more than one attribute is to be updated in row, separate corrections with commas 23 Updating Table Rows
  • 24.   ROLLBACK  Used to restore database to its previous condition  Only applicable if COMMIT command has not been used to permanently store changes in database  Syntax:  ROLLBACK;  COMMIT and ROLLBACK only work with data manipulation commands that are used to add, modify, or delete table rows 24 Restoring Table Contents
  • 25.   DELETE  Deletes a table row  Syntax:  DELETE FROM tablename [WHERE conditionlist ];  WHERE condition is optional  If WHERE condition is not specified, all rows from specified table will be deleted 25 Deleting Table Rows
  • 26.   INSERT  Inserts multiple rows from another table (source)  Uses SELECT sub query  Query that is embedded (or nested) inside another query  Executed first  Syntax:  INSERT INTO table name SELECT columnist FROM table name; 26 Inserting Table Rows with a Select Sub query
  • 27.   Select partial table contents by placing restrictions on rows to be included in output  Add conditional restrictions to SELECT statement, using WHERE clause  Syntax:  SELECT columnlist FROM tablelist [ WHERE conditionlist ] ; 27 Selecting Rows with Conditional Restrictions
  • 28. Selecting Rows with Conditional Restrictions (continued) 28
  • 29. Selecting Rows with Conditional Restrictions (continued) 29
  • 30.   Perform operations within parentheses  Perform power operations  Perform multiplications and divisions  Perform additions and subtractions 30 Arithmetic Operators: The Rule of Precedence
  • 31. Arithmetic Operators: The Rule of Precedence (continued) 31
  • 32.   BETWEEN  Used to check whether attribute value is within a range  IS NULL  Used to check whether attribute value is null  LIKE  Used to check whether attribute value matches given string pattern 32 Special Operators
  • 33.   IN  Used to check whether attribute value matches any value within a value list  EXISTS  Used to check if subquery returns any rows 33 Special Operators (continued)
  • 34.   All changes in table structure are made by using ALTER command  Followed by keyword that produces specific change  Following three options are available:  ADD  MODIFY  DROP 34 Advanced Data Definition Commands
  • 35.   ALTER can be used to change data type  Some RDBMSs (such as Oracle) do not permit changes to data types unless column to be changed is empty 35 Changing a Column’s Data Type
  • 36.   Use ALTER to change data characteristics  If column to be changed already contains data, changes in column’s characteristics are permitted if those changes do not alter the data type 36 Changing a Column’s Data Characteristics
  • 37.   Use ALTER to add column  Do not include the NOT NULL clause for new column 37 Adding a Column
  • 38.   Use ALTER to drop column  Some RDBMSs impose restrictions on the deletion of an attribute 38 Dropping a Column
  • 40.   SQL permits copying contents of selected table columns so that the data need not be reentered manually into newly created table(s)  First create the PART table structure  Next add rows to new PART table using PRODUCT table rows 40 Copying Parts of Tables
  • 41.   When table is copied, integrity rules do not copy, so primary and foreign keys need to be manually defined on new table  User ALTER TABLE command  Syntax:  ALTER TABLE tablename ADD PRIMARY KEY(fieldname);  For foreign key, use FOREIGN KEY in place of PRIMARY KEY 41 Adding Primary and Foreign Key Designations
  • 42.   DROP  Deletes table from database  Syntax:  DROP TABLE tablename; 42 Deleting a Table from the Database
  • 43.   SQL provides useful functions that can:  Count  Find minimum and maximum values  Calculate averages  SQL allows user to limit queries to only those entries having no duplicates or entries whose duplicates may be grouped 43 Advanced Select Queries
  • 52.   View is virtual table based on SELECT query  Can contain columns, computed columns, aliases, and aggregate functions from one or more tables  Base tables are tables on which view is based  Create view by using CREATE VIEW command 52 Virtual Tables: Creating a View
  • 53. Virtual Tables: Creating a View (continued) 53
  • 54.   Ability to combine (join) tables on common attributes is most important distinction between relational database and other databases  Join is performed when data are retrieved from more than one table at a time  Join is generally composed of an equality comparison between foreign key and primary key of related tables 54 Joining Database Tables
  • 55.   Alias can be used to identify source table  Any legal table name can be used as alias  Add alias after table name in FROM clause 55 Joining Tables with an Alias
  • 56.   SQL commands can be divided into two overall categories:  Data definition language commands  Data manipulation language commands  The ANSI standard data types are supported by all RDBMS vendors in different ways  Basic data definition commands allow you to create tables, indexes, and views 56 Summary
  • 57.  DML commands allow you to add, modify, and delete rows from tables The basic DML commands are SELECT, INSERT, UPDATE, DELETE, COMMIT, and ROLLBACK INSERT command is used to add new rows to tables SELECT statement is main data retrieval command in SQL 57 Summary (continued)
  • 58.   Many SQL constraints can be used with columns  The column list represents one or more column names separated by commas  WHERE clause can be used with SELECT, UPDATE, and DELETE statements to restrict rows affected by the DDL command 58 Summary (continued)
  • 59.   Aggregate functions  Special functions that perform arithmetic computations over a set of rows  ORDER BY clause  Used to sort output of SELECT statement  Can sort by one or more columns and use either an ascending or descending order  Join output of multiple tables with SELECT statement 59 Summary (continued)
  • 60.   Natural join uses join condition to match only rows with equal values in specified columns  Right outer join and left outer join used to select rows that have no matching values in other related table 60 Summary (continued)