SlideShare une entreprise Scribd logo
1  sur  24
1
Harshad D. UmredkarHarshad D. Umredkar
MCA-II (Sem-II)MCA-II (Sem-II)
SQL
a.Overview
b.Uses
c.requirement
d.Design
e.Queries
f. Types of Tables
g.Table
h.Conclusion
i. Reference s
IndexIndex
3
An Overview ofAn Overview of
SQLSQL
• SQL stands forSQL stands for SStructuredtructured QQueryuery LLanguage.anguage.
• It is the most commonly used relationalIt is the most commonly used relational
database language today.database language today.
• SQL works with a variety of different fourth-SQL works with a variety of different fourth-
generation (4GL) programming languages,generation (4GL) programming languages,
such as Visual Basic.such as Visual Basic.
SQL
4
SQL is used for:SQL is used for:
• Data ManipulationData Manipulation
• Data DefinitionData Definition
• Data AdministrationData Administration
• All are expressed as an SQL statementAll are expressed as an SQL statement
or command.or command.
SQL
5
SQLSQL
RequirementsRequirements
• SQL Must be embedded in a programmingSQL Must be embedded in a programming
language, or used with a 4GL like VBlanguage, or used with a 4GL like VB
• SQL is a free form language so there is noSQL is a free form language so there is no
limit to the the number of words per line orlimit to the the number of words per line or
fixed line break.fixed line break.
• Syntax statements, words or phrases areSyntax statements, words or phrases are
always in lower case; keywords are inalways in lower case; keywords are in
uppercase.uppercase.
SQL
Not all versions are case sensitive!Not all versions are case sensitive!
6
SQL is a Relational DatabaseSQL is a Relational Database
• Represent all info in database as tablesRepresent all info in database as tables
• Keep logical representation of data independent from its physicalKeep logical representation of data independent from its physical
storage characteristicsstorage characteristics
• Use one high-level language for structuring, querying, andUse one high-level language for structuring, querying, and
changing info in the databasechanging info in the database
• Support the main relational operationsSupport the main relational operations
• Support alternate ways of looking at data in tablesSupport alternate ways of looking at data in tables
• Provide a method for differentiating between unknown values andProvide a method for differentiating between unknown values and
nulls (zero or blank)nulls (zero or blank)
• Support Mechanisms for integrity, authorization, transactions, andSupport Mechanisms for integrity, authorization, transactions, and
recoveryrecovery
A Fully Relational Database Management System must:A Fully Relational Database Management System must:
7
DesignDesign
• SQL represents all information in the
form of tables
• Supports three relational operations:
selection, projection, and join. These
are for specifying exactly what data you
want to display or use
• SQL is used for data manipulation,
definition and administration
SQL
8
Rows
describe the
Occurrence of
an Entity
Table DesignTable Design
SQ
L
Name Address
Jane Doe 123 Main Street
John Smith 456 Second Street
Mary Poe 789 Third Ave
Columns describe one
characteristic of the entity
9
Data Retrieval (Queries)Data Retrieval (Queries)
• Queries search the database, fetch info,Queries search the database, fetch info,
and display it. This is done using theand display it. This is done using the
keywordkeyword SELECT
SELECT * FROM publishersSELECT * FROM publishers
pub_id pub_name address state
0736 New Age Books 1 1st
Street MA
0987 Binnet & Hardley 2 2nd
Street DC
1120 Algodata Infosys 3 3rd
Street CA
•
TheThe
** Operator asks for every column inOperator asks for every column in
10
Data Retrieval (Queries)Data Retrieval (Queries)
• Queries can be more specific with a fewQueries can be more specific with a few
more linesmore lines
pub_id pub_name address state
0736 New Age Books 1 1st
Street MA
0987 Binnet & Hardley 2 2nd
Street DC
1120 Algodata Infosys 3 3rd
Street CA
• Only publishers in CA are displayedOnly publishers in CA are displayed
SELECT *SELECT *
from publishersfrom publishers
where state = ‘CA’where state = ‘CA’
11
Data InputData Input
• Putting data into a table is accomplishedPutting data into a table is accomplished
using the keywordusing the keyword INSERT
pub_id pub_name address state
0736 New Age Books 1 1st
Street MA
0987 Binnet & Hardley 2 2nd
Street DC
1120 Algodata Infosys 3 3rd
Street CA
• Table is updated with new informationTable is updated with new information
INSERT INTO publishersINSERT INTO publishers
VALUES (‘0010’, ‘pragmatics’, ‘4 4VALUES (‘0010’, ‘pragmatics’, ‘4 4 thth
Ln’, ‘chicago’,Ln’, ‘chicago’,
‘il’)‘il’)
pub_id pub_name address state
0010 Pragmatics 4 4th
Ln IL
0736 New Age Books 1 1st
Street MA
0987 Binnet & Hardley 2 2nd
Street DC
1120 Algodata Infosys 3 3rd
Street CA
Keyword
Variable
12
Types of TablesTypes of Tables
• User Tables:User Tables: contain information that iscontain information that is
the database management systemthe database management system
• System Tables:System Tables: contain the databasecontain the database
description, kept up to date by DBMSdescription, kept up to date by DBMS
itselfitself
There are two types of tables which make upThere are two types of tables which make up
a relational database in SQLa relational database in SQL
Relation Table
Tuple Row
Attribute Column
13
Using SQLUsing SQL
SQL statements can be embedded into a programSQL statements can be embedded into a program
(cgi or perl script, Visual Basic, MS Access)(cgi or perl script, Visual Basic, MS Access)
OROR
SQ
L
Database
SQL statements can be entered directly at theSQL statements can be entered directly at the
command prompt of the SQL software beingcommand prompt of the SQL software being
used (such as mySQL)used (such as mySQL)
14
Using SQLUsing SQL
To begin, you must first CREATE a databaseTo begin, you must first CREATE a database
using the following SQL statement:using the following SQL statement:
CREATE DATABASE database_nameCREATE DATABASE database_name
Depending on the version of SQL being usedDepending on the version of SQL being used
the following statement is needed to beginthe following statement is needed to begin
using the database:using the database:
USE database_nameUSE database_name
15
Using SQLUsing SQL
• To create a table in the current database,
use the CREATE TABLE keyword
CREATE TABLE authorsCREATE TABLE authors
(auth_id int(9) not null,(auth_id int(9) not null,
auth_name char(40) not null)auth_name char(40) not null)
auth_id auth_name
(9 digit int) (40 char string)
16
Using SQLUsing SQL
• To insert data in the current table, use
the keyword INSERT INTO
auth_id auth_name
• Then issue the statement
SELECT * FROM authors
INSERT INTO authors
values(‘000000001’, ‘John Smith’)
000000001 John Smith
17
Using SQLUsing SQL
SELECT auth_name, auth_citySELECT auth_name, auth_city
FROM publishersFROM publishers
auth_id auth_name auth_city auth_state
123456789 Jane Doe Dearborn MI
000000001 John Smith Taylor MI
auth_name auth_city
Jane Doe Dearborn
John Smith Taylor
If you only want to display the author’s
name and city from the following table:
18
Using SQLUsing SQL
DELETE from authorsDELETE from authors
WHERE auth_name=‘John Smith’WHERE auth_name=‘John Smith’
auth_id auth_name auth_city auth_state
123456789 Jane Doe Dearborn MI
000000001 John Smith Taylor MI
To delete data from a table, use
the DELETE statement:
19
Using SQLUsing SQL
UPDATE authorsUPDATE authors
SET auth_name=‘hello’SET auth_name=‘hello’
auth_id auth_name auth_city auth_state
123456789 Jane Doe Dearborn MI
000000001 John Smith Taylor MI
To Update information in a database use
the UPDATE keyword
Hello
Hello
Sets all auth_name fields to helloSets all auth_name fields to hello
20
Using SQLUsing SQL
ALTER TABLE authorsALTER TABLE authors
ADD birth_date datetime nullADD birth_date datetime null
auth_id auth_name auth_city auth_state
123456789 Jane Doe Dearborn MI
000000001 John Smith Taylor MI
To change a table in a database use
ALTER TABLE. ADD adds a characteristic.
ADD puts a new column in the table
called birth_date
birth_date
.
.
Type Initializer
21
Using SQLUsing SQL
ALTER TABLE authorsALTER TABLE authors
DROP birth_dateDROP birth_date
auth_id auth_name auth_city auth_state
123456789 Jane Doe Dearborn MI
000000001 John Smith Taylor MI
To delete a column or row, use the
keyword DROP
DROP removed the birth_date
characteristic from the table
auth_state
.
.
22
Using SQLUsing SQL
DROP DATABASE authorsDROP DATABASE authors
auth_id auth_name auth_city auth_state
123456789 Jane Doe Dearborn MI
000000001 John Smith Taylor MI
The DROP statement is also used to
delete an entire database.
DROP removed the database and
returned the memory to system
23
Conclusion
• SQL is a versatile language that can
integrate with numerous 4GL languages
and applications
• SQL simplifies data manipulation by
reducing the amount of code required.
• More reliable than creating a database
using files with linked-list implementation
24
References
• “The Practical SQL Handbook”, Third
Edition, Bowman.

Contenu connexe

Tendances (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)
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
 
What is SQL Server?
What is SQL Server?What is SQL Server?
What is SQL Server?
 
8. sql
8. sql8. sql
8. sql
 
Sql Basics And Advanced
Sql Basics And AdvancedSql Basics And Advanced
Sql Basics And Advanced
 
SQL
SQLSQL
SQL
 
Mysql
MysqlMysql
Mysql
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
Structured Query Language (SQL)
Structured Query Language (SQL)Structured Query Language (SQL)
Structured Query Language (SQL)
 
Basic SQL and History
 Basic SQL and History Basic SQL and History
Basic SQL and History
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
Structured query language(sql)ppt
Structured query language(sql)pptStructured query language(sql)ppt
Structured query language(sql)ppt
 
MySql:Introduction
MySql:IntroductionMySql:Introduction
MySql:Introduction
 
Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
SQL
SQLSQL
SQL
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 

Similaire à SQL

Similaire à SQL (20)

Sql
SqlSql
Sql
 
DBMS LAB FILE1 task 1 , task 2, task3 and many more.pdf
DBMS LAB FILE1 task 1 , task 2, task3 and many more.pdfDBMS LAB FILE1 task 1 , task 2, task3 and many more.pdf
DBMS LAB FILE1 task 1 , task 2, task3 and many more.pdf
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdf
 
LECTURE NOTES.pdf
LECTURE NOTES.pdfLECTURE NOTES.pdf
LECTURE NOTES.pdf
 
LECTURE NOTES.pdf
LECTURE NOTES.pdfLECTURE NOTES.pdf
LECTURE NOTES.pdf
 
chapter 8 SQL.ppt
chapter 8 SQL.pptchapter 8 SQL.ppt
chapter 8 SQL.ppt
 
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
 
05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx
 
IR SQLite Session #1
IR SQLite Session #1IR SQLite Session #1
IR SQLite Session #1
 
Oracle SQL Part1
Oracle SQL Part1Oracle SQL Part1
Oracle SQL Part1
 
ORACLE PL SQL
ORACLE PL SQLORACLE PL SQL
ORACLE PL SQL
 
Introduction to sq lite
Introduction to sq liteIntroduction to sq lite
Introduction to sq lite
 
lovely
lovelylovely
lovely
 
SQL SERVER Training in Pune Slides
SQL SERVER Training in Pune SlidesSQL SERVER Training in Pune Slides
SQL SERVER Training in Pune Slides
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 
Sql basics
Sql  basicsSql  basics
Sql basics
 
Rdbms day3
Rdbms day3Rdbms day3
Rdbms day3
 
Sql Server 2000
Sql Server 2000Sql Server 2000
Sql Server 2000
 
Reviewing SQL Concepts
Reviewing SQL ConceptsReviewing SQL Concepts
Reviewing SQL Concepts
 
Module 3
Module 3Module 3
Module 3
 

Dernier

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxruthvilladarez
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEaurabinda banchhor
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxJanEmmanBrigoli
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxElton John Embodo
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxRosabel UA
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 

Dernier (20)

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSE
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptx
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 

SQL

  • 1. 1 Harshad D. UmredkarHarshad D. Umredkar MCA-II (Sem-II)MCA-II (Sem-II) SQL
  • 2. a.Overview b.Uses c.requirement d.Design e.Queries f. Types of Tables g.Table h.Conclusion i. Reference s IndexIndex
  • 3. 3 An Overview ofAn Overview of SQLSQL • SQL stands forSQL stands for SStructuredtructured QQueryuery LLanguage.anguage. • It is the most commonly used relationalIt is the most commonly used relational database language today.database language today. • SQL works with a variety of different fourth-SQL works with a variety of different fourth- generation (4GL) programming languages,generation (4GL) programming languages, such as Visual Basic.such as Visual Basic. SQL
  • 4. 4 SQL is used for:SQL is used for: • Data ManipulationData Manipulation • Data DefinitionData Definition • Data AdministrationData Administration • All are expressed as an SQL statementAll are expressed as an SQL statement or command.or command. SQL
  • 5. 5 SQLSQL RequirementsRequirements • SQL Must be embedded in a programmingSQL Must be embedded in a programming language, or used with a 4GL like VBlanguage, or used with a 4GL like VB • SQL is a free form language so there is noSQL is a free form language so there is no limit to the the number of words per line orlimit to the the number of words per line or fixed line break.fixed line break. • Syntax statements, words or phrases areSyntax statements, words or phrases are always in lower case; keywords are inalways in lower case; keywords are in uppercase.uppercase. SQL Not all versions are case sensitive!Not all versions are case sensitive!
  • 6. 6 SQL is a Relational DatabaseSQL is a Relational Database • Represent all info in database as tablesRepresent all info in database as tables • Keep logical representation of data independent from its physicalKeep logical representation of data independent from its physical storage characteristicsstorage characteristics • Use one high-level language for structuring, querying, andUse one high-level language for structuring, querying, and changing info in the databasechanging info in the database • Support the main relational operationsSupport the main relational operations • Support alternate ways of looking at data in tablesSupport alternate ways of looking at data in tables • Provide a method for differentiating between unknown values andProvide a method for differentiating between unknown values and nulls (zero or blank)nulls (zero or blank) • Support Mechanisms for integrity, authorization, transactions, andSupport Mechanisms for integrity, authorization, transactions, and recoveryrecovery A Fully Relational Database Management System must:A Fully Relational Database Management System must:
  • 7. 7 DesignDesign • SQL represents all information in the form of tables • Supports three relational operations: selection, projection, and join. These are for specifying exactly what data you want to display or use • SQL is used for data manipulation, definition and administration SQL
  • 8. 8 Rows describe the Occurrence of an Entity Table DesignTable Design SQ L Name Address Jane Doe 123 Main Street John Smith 456 Second Street Mary Poe 789 Third Ave Columns describe one characteristic of the entity
  • 9. 9 Data Retrieval (Queries)Data Retrieval (Queries) • Queries search the database, fetch info,Queries search the database, fetch info, and display it. This is done using theand display it. This is done using the keywordkeyword SELECT SELECT * FROM publishersSELECT * FROM publishers pub_id pub_name address state 0736 New Age Books 1 1st Street MA 0987 Binnet & Hardley 2 2nd Street DC 1120 Algodata Infosys 3 3rd Street CA • TheThe ** Operator asks for every column inOperator asks for every column in
  • 10. 10 Data Retrieval (Queries)Data Retrieval (Queries) • Queries can be more specific with a fewQueries can be more specific with a few more linesmore lines pub_id pub_name address state 0736 New Age Books 1 1st Street MA 0987 Binnet & Hardley 2 2nd Street DC 1120 Algodata Infosys 3 3rd Street CA • Only publishers in CA are displayedOnly publishers in CA are displayed SELECT *SELECT * from publishersfrom publishers where state = ‘CA’where state = ‘CA’
  • 11. 11 Data InputData Input • Putting data into a table is accomplishedPutting data into a table is accomplished using the keywordusing the keyword INSERT pub_id pub_name address state 0736 New Age Books 1 1st Street MA 0987 Binnet & Hardley 2 2nd Street DC 1120 Algodata Infosys 3 3rd Street CA • Table is updated with new informationTable is updated with new information INSERT INTO publishersINSERT INTO publishers VALUES (‘0010’, ‘pragmatics’, ‘4 4VALUES (‘0010’, ‘pragmatics’, ‘4 4 thth Ln’, ‘chicago’,Ln’, ‘chicago’, ‘il’)‘il’) pub_id pub_name address state 0010 Pragmatics 4 4th Ln IL 0736 New Age Books 1 1st Street MA 0987 Binnet & Hardley 2 2nd Street DC 1120 Algodata Infosys 3 3rd Street CA Keyword Variable
  • 12. 12 Types of TablesTypes of Tables • User Tables:User Tables: contain information that iscontain information that is the database management systemthe database management system • System Tables:System Tables: contain the databasecontain the database description, kept up to date by DBMSdescription, kept up to date by DBMS itselfitself There are two types of tables which make upThere are two types of tables which make up a relational database in SQLa relational database in SQL Relation Table Tuple Row Attribute Column
  • 13. 13 Using SQLUsing SQL SQL statements can be embedded into a programSQL statements can be embedded into a program (cgi or perl script, Visual Basic, MS Access)(cgi or perl script, Visual Basic, MS Access) OROR SQ L Database SQL statements can be entered directly at theSQL statements can be entered directly at the command prompt of the SQL software beingcommand prompt of the SQL software being used (such as mySQL)used (such as mySQL)
  • 14. 14 Using SQLUsing SQL To begin, you must first CREATE a databaseTo begin, you must first CREATE a database using the following SQL statement:using the following SQL statement: CREATE DATABASE database_nameCREATE DATABASE database_name Depending on the version of SQL being usedDepending on the version of SQL being used the following statement is needed to beginthe following statement is needed to begin using the database:using the database: USE database_nameUSE database_name
  • 15. 15 Using SQLUsing SQL • To create a table in the current database, use the CREATE TABLE keyword CREATE TABLE authorsCREATE TABLE authors (auth_id int(9) not null,(auth_id int(9) not null, auth_name char(40) not null)auth_name char(40) not null) auth_id auth_name (9 digit int) (40 char string)
  • 16. 16 Using SQLUsing SQL • To insert data in the current table, use the keyword INSERT INTO auth_id auth_name • Then issue the statement SELECT * FROM authors INSERT INTO authors values(‘000000001’, ‘John Smith’) 000000001 John Smith
  • 17. 17 Using SQLUsing SQL SELECT auth_name, auth_citySELECT auth_name, auth_city FROM publishersFROM publishers auth_id auth_name auth_city auth_state 123456789 Jane Doe Dearborn MI 000000001 John Smith Taylor MI auth_name auth_city Jane Doe Dearborn John Smith Taylor If you only want to display the author’s name and city from the following table:
  • 18. 18 Using SQLUsing SQL DELETE from authorsDELETE from authors WHERE auth_name=‘John Smith’WHERE auth_name=‘John Smith’ auth_id auth_name auth_city auth_state 123456789 Jane Doe Dearborn MI 000000001 John Smith Taylor MI To delete data from a table, use the DELETE statement:
  • 19. 19 Using SQLUsing SQL UPDATE authorsUPDATE authors SET auth_name=‘hello’SET auth_name=‘hello’ auth_id auth_name auth_city auth_state 123456789 Jane Doe Dearborn MI 000000001 John Smith Taylor MI To Update information in a database use the UPDATE keyword Hello Hello Sets all auth_name fields to helloSets all auth_name fields to hello
  • 20. 20 Using SQLUsing SQL ALTER TABLE authorsALTER TABLE authors ADD birth_date datetime nullADD birth_date datetime null auth_id auth_name auth_city auth_state 123456789 Jane Doe Dearborn MI 000000001 John Smith Taylor MI To change a table in a database use ALTER TABLE. ADD adds a characteristic. ADD puts a new column in the table called birth_date birth_date . . Type Initializer
  • 21. 21 Using SQLUsing SQL ALTER TABLE authorsALTER TABLE authors DROP birth_dateDROP birth_date auth_id auth_name auth_city auth_state 123456789 Jane Doe Dearborn MI 000000001 John Smith Taylor MI To delete a column or row, use the keyword DROP DROP removed the birth_date characteristic from the table auth_state . .
  • 22. 22 Using SQLUsing SQL DROP DATABASE authorsDROP DATABASE authors auth_id auth_name auth_city auth_state 123456789 Jane Doe Dearborn MI 000000001 John Smith Taylor MI The DROP statement is also used to delete an entire database. DROP removed the database and returned the memory to system
  • 23. 23 Conclusion • SQL is a versatile language that can integrate with numerous 4GL languages and applications • SQL simplifies data manipulation by reducing the amount of code required. • More reliable than creating a database using files with linked-list implementation
  • 24. 24 References • “The Practical SQL Handbook”, Third Edition, Bowman.

Notes de l'éditeur

  1. Frequently, presenters must deliver material of a technical nature to an audience unfamiliar with the topic or vocabulary. The material may be complex or heavy with detail. To present technical material effectively, use the following guidelines from Dale Carnegie Training®.   Consider the amount of time available and prepare to organize your material. Narrow your topic. Divide your presentation into clear segments. Follow a logical progression. Maintain your focus throughout. Close the presentation with a summary, repetition of the key steps, or a logical conclusion.   Keep your audience in mind at all times. For example, be sure data is clear and information is relevant. Keep the level of detail and vocabulary appropriate for the audience. Use visuals to support key points or steps. Keep alert to the needs of your listeners, and you will have a more receptive audience.
  2. In your opening, establish the relevancy of the topic to the audience. Give a brief preview of the presentation and establish value for the listeners. Take into account your audience’s interest and expertise in the topic when choosing your vocabulary, examples, and illustrations. Focus on the importance of the topic to your audience, and you will have more attentive listeners.
  3. If you have several points, steps, or key ideas use multiple slides. Determine if your audience is to understand a new idea, learn a process, or receive greater depth to a familiar concept. Back up each point with adequate explanation. As appropriate, supplement your presentation with technical support data in hard copy or on disc, e-mail, or the Internet. Develop each point adequately to communicate with your audience.
  4. In your opening, establish the relevancy of the topic to the audience. Give a brief preview of the presentation and establish value for the listeners. Take into account your audience’s interest and expertise in the topic when choosing your vocabulary, examples, and illustrations. Focus on the importance of the topic to your audience, and you will have more attentive listeners.
  5. If you have several points, steps, or key ideas use multiple slides. Determine if your audience is to understand a new idea, learn a process, or receive greater depth to a familiar concept. Back up each point with adequate explanation. As appropriate, supplement your presentation with technical support data in hard copy or on disc, e-mail, or the Internet. Develop each point adequately to communicate with your audience.
  6. If you have several points, steps, or key ideas use multiple slides. Determine if your audience is to understand a new idea, learn a process, or receive greater depth to a familiar concept. Back up each point with adequate explanation. As appropriate, supplement your presentation with technical support data in hard copy or on disc, e-mail, or the Internet. Develop each point adequately to communicate with your audience.
  7. If you have several points, steps, or key ideas use multiple slides. Determine if your audience is to understand a new idea, learn a process, or receive greater depth to a familiar concept. Back up each point with adequate explanation. As appropriate, supplement your presentation with technical support data in hard copy or on disc, e-mail, or the Internet. Develop each point adequately to communicate with your audience.
  8. If you have several points, steps, or key ideas use multiple slides. Determine if your audience is to understand a new idea, learn a process, or receive greater depth to a familiar concept. Back up each point with adequate explanation. As appropriate, supplement your presentation with technical support data in hard copy or on disc, e-mail, or the Internet. Develop each point adequately to communicate with your audience.
  9. If you have several points, steps, or key ideas use multiple slides. Determine if your audience is to understand a new idea, learn a process, or receive greater depth to a familiar concept. Back up each point with adequate explanation. As appropriate, supplement your presentation with technical support data in hard copy or on disc, e-mail, or the Internet. Develop each point adequately to communicate with your audience.
  10. If you have several points, steps, or key ideas use multiple slides. Determine if your audience is to understand a new idea, learn a process, or receive greater depth to a familiar concept. Back up each point with adequate explanation. As appropriate, supplement your presentation with technical support data in hard copy or on disc, e-mail, or the Internet. Develop each point adequately to communicate with your audience.
  11. If you have several points, steps, or key ideas use multiple slides. Determine if your audience is to understand a new idea, learn a process, or receive greater depth to a familiar concept. Back up each point with adequate explanation. As appropriate, supplement your presentation with technical support data in hard copy or on disc, e-mail, or the Internet. Develop each point adequately to communicate with your audience.
  12. If you have several points, steps, or key ideas use multiple slides. Determine if your audience is to understand a new idea, learn a process, or receive greater depth to a familiar concept. Back up each point with adequate explanation. As appropriate, supplement your presentation with technical support data in hard copy or on disc, e-mail, or the Internet. Develop each point adequately to communicate with your audience.
  13. If you have several points, steps, or key ideas use multiple slides. Determine if your audience is to understand a new idea, learn a process, or receive greater depth to a familiar concept. Back up each point with adequate explanation. As appropriate, supplement your presentation with technical support data in hard copy or on disc, e-mail, or the Internet. Develop each point adequately to communicate with your audience.
  14. Determine the best close for your audience and your presentation. Close with a summary; offer options; recommend a strategy; suggest a plan; set a goal. Keep your focus throughout your presentation, and you will more likely achieve your purpose.