SlideShare uma empresa Scribd logo
1 de 31
ISYS6508
Database System
Week 5
SQL: Data Definition
Database System A Practical Approach to Design, Implemetation, and Management
Connolly, T., & Begg, C.
Chapter 7
Learning Objective
At the end of this semester, the student should
be able to:
• Construct SQL that suit the problem
INTRODUCTION TO SQL
Objectives to SQL
Ideally, a database language should allow a
user to :
• Create the database and relation structures;
• Perform basic data management task such as
insertion, modification, deletion from data
relation;
• Perform both simple and complex queries.
Component of SQL
SQL is an example of transform-oriented
language. As a language, the ISO SQL standard
has 2 major component :
• A Data Definition Language (DDL) for
defining the database structure and
controlling access to the data;
• A Data Manipulation Language (DML) for
retrieving and updating data.
Why SQL Relatively Easy ?
• It is a nonprocedural language
• SQL is essentially free-format
• The commands structure is consists of
standard English word
• SQL can be used by a range including
database administrators, management
personnel, application developer, etc.
History of SQL
• The history of relational model (and indirectly
SQL) started in 1970 with publication of seminal
paper by E.F Codd written during his work at
IBM Reseach Lab.
• In 1974, D. Chamberlain also from IBM defined
a language called Structure English Query
Language (SEQUEL).
• In 1976, a revised version of SEQUEL was
defined (SEQUEL/2). But the name changed into
SQL.
History of SQL (cont)
• In 1976, IBM produced a prototype DBMS based
on SEQUEL/2 called System R. Its most
important result was the development of SQL.
• In the late 1970’s, the databases system Oracle
was produced.
• In early 1980’s a standard for SQL was defined.
• In 1990’s ISO standard for SQL was formalized.
The Importance and
Terminology of SQL
• SQL is the first and so far the only standard
database language to gain wide acceptance.
• SQL is used in other standard and even
influences the development of the other
standard as a definitional tools.
• The ISO SQL standard doesn’t use the formal
term of relations, attributes and tuples, instead
using the term tables, columns and rows. The
presentation of SQL mostly use ISO terminology.
SQL COMMAND
How to write
SQL Commands ?
A SQL statement consist of :
• Reserved word, a fixed part of SQL language.
• User define word, made up by user and
represent the name of various database
object.
Backus Naur Form (BNF)
notation to define SQL
statement
• Uppercase letter are used to represent reserved
words and must be spelled exactly as shown.
• Lowercase letter are used to define user-define
word.
• A vertical bar (|) indicates a choice among
alternative.
• Curly braces ({}) indicate a required element.
• Square bracket ([]) indicate optional element.
• An ellipsis (…) is used to indicate optional
repetition of an item zero or more times.
DDL Statement
In practice DDL statement are use to create
database structure ( the tables) and the access
mechanism.
DML Statement
DML statement are used to populate and
query the tables.
SQL DML statement are :
• SELECT, use to query data in database
• INSERT, use to insert data into a table
• UPDATE, use to update data in a table
• DELETE, use to delete data from a table
DATA DEFINITION
SQL DDL allows database object as schemas, domain,
table views, and indexes to be created.
The main SQL DDL statements are :
These statement are used to create, change and destroy
stuctures that make up the conceptual schema.
CREATE SCHEMA DROP SCHEMA
CREATE DOMAIN ALTER DOMAIN DROP DOMAIN
CREATE TABLE ALTER TABLE DROP TABLE
CREATE VIEW DROP VIEW
Although not covered by SQL standard, the
following 2 statements are provides by many
DBMS :
CREATE INDEX DROP INDEX
Creating a Database
According to ISO standard, relation and other
databases object exist in an environment.
Among other things, each environment consist
of one or more catalogs, and each catalogs
consist of one or more schemas.
Create Database (cont)
• The schema definition definition statements
has the following form :
CREATE SCHEMA [Name|AUTHORIZATION
CreatorIdentifier]
• A schema can be drop using DROP SCHEMA
statement bellows :
DROP SCHEMA Name[RESTRICT|CASCADE]
Creating a Table
After created database now we can create the
table structure for the base relations to be
stored in database. Basic syntax for CREATE
TABLE :
Creating Table (cont)
• Table constraint
The common clause to create table constraint
is :
CONSTRAINT ConstraintName
Creating Table (cont)
Primary key
• The primary key clause specifies the column or
columns that form primary key for the tables.
• It should be specified for every table created
• By default, NOT NULL is assumed for each
column comprises the primary key.
• Only 1 primary key clause is allowed per table.
• SQL reject any INSERT or UPDATE operation that
attempt to create duplicate row of primary key
column.
Creating Table (cont)
The Foreign Key clause specifies a foreign key
in the (child) table and the relationship it has
to another (parent) table. This clause
implement referential integrity constraint.
There can be as many FOREIGN KEY as
required. The CHECK and CONSTRAINT clauses
allows additional constraint to be defined.
ALTER TABLE
The definition of the ALTER TABLE statement in
the ISO standard consist of six option to :
• Add new column to a table;
• Drop a column from a table;
• Add a new table constraint;
• Drop a table constraint;
• Set a default for a column;
• Drop a default for a column.
ALTER TABLE (cont)
The basic format of ALTER TABLE statement
are:
DROP TABLE
Over time, the structure of a table will change;
new table will be created and some tables will
no longer needed. We can remove a redundant
table from the database using the DROP TABLE
statement, which has the format :
DROP TABLE TableName [RESTRICT |CASCADE]
DROP TABLE (cont)
The DROP TABLE statement allow you to specify your
action into :
• RESTRICT, The DROP operation is rejected if there any
other object that depend for their existence upon the
continued table to be dropped.
• CASCADE, the DROP operation proceeds and SQL
automatically drop all dependent object.
NOTE : effect of CASCADE can be very extensive and
should be carried out only with extreme caution.
CREATE INDEX
An index is a structure that provides
accelerated access to the rows of a table based
on the values of one or columns. The presence
of an index can be significantly improve the
performance of a query. The creation of
indexes is not standard SQL. However, most
dialects support at least the following
capability :
DROP INDEX
If we create an index for a base table and later
decided we don’t needed anymore we can use
DROP INDEX statement to remove index from
database. The format of DROP INDEX
statement is :
DROP INDEX IndexName
Reference
Connolly, T., & Begg, C. (2015). Database
System A Practical Approach to Design,
Implemetation, and Management 6th Edition.
Pearson
Thank You

Mais conteúdo relacionado

Semelhante a 20190326165338_ISYS6508-PPT5-W5-S6-R0.pptx

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
 
Structured Query Language (SQL).pptx
Structured Query Language (SQL).pptxStructured Query Language (SQL).pptx
Structured Query Language (SQL).pptx
EllenGracePorras
 
Less07 schema
Less07 schemaLess07 schema
Less07 schema
Imran Ali
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
WrushabhShirsat3
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
DraguClaudiu
 

Semelhante a 20190326165338_ISYS6508-PPT5-W5-S6-R0.pptx (20)

Sql commands
Sql commandsSql commands
Sql commands
 
Introduction to SQL, SQL*Plus
Introduction to SQL, SQL*PlusIntroduction to SQL, SQL*Plus
Introduction to SQL, SQL*Plus
 
SQL Fundamentals - Lecture 2
SQL Fundamentals - Lecture 2SQL Fundamentals - Lecture 2
SQL Fundamentals - Lecture 2
 
SQL_NOTES.pdf
SQL_NOTES.pdfSQL_NOTES.pdf
SQL_NOTES.pdf
 
Sq lite module5
Sq lite module5Sq lite module5
Sq lite module5
 
MySQL intro
MySQL introMySQL intro
MySQL intro
 
MySQL intro
MySQL introMySQL intro
MySQL intro
 
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
 
Lecture 2 sql {basics date type, constrains , integrity types etc.}
Lecture 2 sql {basics  date type, constrains , integrity types etc.}Lecture 2 sql {basics  date type, constrains , integrity types etc.}
Lecture 2 sql {basics date type, constrains , integrity types etc.}
 
SQL Intro
SQL IntroSQL Intro
SQL Intro
 
Unit - II.pptx
Unit - II.pptxUnit - II.pptx
Unit - II.pptx
 
Structured Query Language (SQL).pptx
Structured Query Language (SQL).pptxStructured Query Language (SQL).pptx
Structured Query Language (SQL).pptx
 
Less07 schema
Less07 schemaLess07 schema
Less07 schema
 
unit-ii.pptx
unit-ii.pptxunit-ii.pptx
unit-ii.pptx
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
 
Reviewing SQL Concepts
Reviewing SQL ConceptsReviewing SQL Concepts
Reviewing SQL Concepts
 
Sqlite
SqliteSqlite
Sqlite
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
 
SQL Overview-II23-PF20SA8Z.pptx
SQL Overview-II23-PF20SA8Z.pptxSQL Overview-II23-PF20SA8Z.pptx
SQL Overview-II23-PF20SA8Z.pptx
 
SQL Overview.pptx
SQL Overview.pptxSQL Overview.pptx
SQL Overview.pptx
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

20190326165338_ISYS6508-PPT5-W5-S6-R0.pptx

  • 1. ISYS6508 Database System Week 5 SQL: Data Definition Database System A Practical Approach to Design, Implemetation, and Management Connolly, T., & Begg, C. Chapter 7
  • 2. Learning Objective At the end of this semester, the student should be able to: • Construct SQL that suit the problem
  • 4. Objectives to SQL Ideally, a database language should allow a user to : • Create the database and relation structures; • Perform basic data management task such as insertion, modification, deletion from data relation; • Perform both simple and complex queries.
  • 5. Component of SQL SQL is an example of transform-oriented language. As a language, the ISO SQL standard has 2 major component : • A Data Definition Language (DDL) for defining the database structure and controlling access to the data; • A Data Manipulation Language (DML) for retrieving and updating data.
  • 6. Why SQL Relatively Easy ? • It is a nonprocedural language • SQL is essentially free-format • The commands structure is consists of standard English word • SQL can be used by a range including database administrators, management personnel, application developer, etc.
  • 7. History of SQL • The history of relational model (and indirectly SQL) started in 1970 with publication of seminal paper by E.F Codd written during his work at IBM Reseach Lab. • In 1974, D. Chamberlain also from IBM defined a language called Structure English Query Language (SEQUEL). • In 1976, a revised version of SEQUEL was defined (SEQUEL/2). But the name changed into SQL.
  • 8. History of SQL (cont) • In 1976, IBM produced a prototype DBMS based on SEQUEL/2 called System R. Its most important result was the development of SQL. • In the late 1970’s, the databases system Oracle was produced. • In early 1980’s a standard for SQL was defined. • In 1990’s ISO standard for SQL was formalized.
  • 9. The Importance and Terminology of SQL • SQL is the first and so far the only standard database language to gain wide acceptance. • SQL is used in other standard and even influences the development of the other standard as a definitional tools. • The ISO SQL standard doesn’t use the formal term of relations, attributes and tuples, instead using the term tables, columns and rows. The presentation of SQL mostly use ISO terminology.
  • 11. How to write SQL Commands ? A SQL statement consist of : • Reserved word, a fixed part of SQL language. • User define word, made up by user and represent the name of various database object.
  • 12. Backus Naur Form (BNF) notation to define SQL statement • Uppercase letter are used to represent reserved words and must be spelled exactly as shown. • Lowercase letter are used to define user-define word. • A vertical bar (|) indicates a choice among alternative. • Curly braces ({}) indicate a required element. • Square bracket ([]) indicate optional element. • An ellipsis (…) is used to indicate optional repetition of an item zero or more times.
  • 13. DDL Statement In practice DDL statement are use to create database structure ( the tables) and the access mechanism.
  • 14. DML Statement DML statement are used to populate and query the tables. SQL DML statement are : • SELECT, use to query data in database • INSERT, use to insert data into a table • UPDATE, use to update data in a table • DELETE, use to delete data from a table
  • 16. SQL DDL allows database object as schemas, domain, table views, and indexes to be created. The main SQL DDL statements are : These statement are used to create, change and destroy stuctures that make up the conceptual schema. CREATE SCHEMA DROP SCHEMA CREATE DOMAIN ALTER DOMAIN DROP DOMAIN CREATE TABLE ALTER TABLE DROP TABLE CREATE VIEW DROP VIEW
  • 17. Although not covered by SQL standard, the following 2 statements are provides by many DBMS : CREATE INDEX DROP INDEX
  • 18. Creating a Database According to ISO standard, relation and other databases object exist in an environment. Among other things, each environment consist of one or more catalogs, and each catalogs consist of one or more schemas.
  • 19. Create Database (cont) • The schema definition definition statements has the following form : CREATE SCHEMA [Name|AUTHORIZATION CreatorIdentifier] • A schema can be drop using DROP SCHEMA statement bellows : DROP SCHEMA Name[RESTRICT|CASCADE]
  • 20. Creating a Table After created database now we can create the table structure for the base relations to be stored in database. Basic syntax for CREATE TABLE :
  • 21. Creating Table (cont) • Table constraint The common clause to create table constraint is : CONSTRAINT ConstraintName
  • 22. Creating Table (cont) Primary key • The primary key clause specifies the column or columns that form primary key for the tables. • It should be specified for every table created • By default, NOT NULL is assumed for each column comprises the primary key. • Only 1 primary key clause is allowed per table. • SQL reject any INSERT or UPDATE operation that attempt to create duplicate row of primary key column.
  • 23. Creating Table (cont) The Foreign Key clause specifies a foreign key in the (child) table and the relationship it has to another (parent) table. This clause implement referential integrity constraint. There can be as many FOREIGN KEY as required. The CHECK and CONSTRAINT clauses allows additional constraint to be defined.
  • 24. ALTER TABLE The definition of the ALTER TABLE statement in the ISO standard consist of six option to : • Add new column to a table; • Drop a column from a table; • Add a new table constraint; • Drop a table constraint; • Set a default for a column; • Drop a default for a column.
  • 25. ALTER TABLE (cont) The basic format of ALTER TABLE statement are:
  • 26. DROP TABLE Over time, the structure of a table will change; new table will be created and some tables will no longer needed. We can remove a redundant table from the database using the DROP TABLE statement, which has the format : DROP TABLE TableName [RESTRICT |CASCADE]
  • 27. DROP TABLE (cont) The DROP TABLE statement allow you to specify your action into : • RESTRICT, The DROP operation is rejected if there any other object that depend for their existence upon the continued table to be dropped. • CASCADE, the DROP operation proceeds and SQL automatically drop all dependent object. NOTE : effect of CASCADE can be very extensive and should be carried out only with extreme caution.
  • 28. CREATE INDEX An index is a structure that provides accelerated access to the rows of a table based on the values of one or columns. The presence of an index can be significantly improve the performance of a query. The creation of indexes is not standard SQL. However, most dialects support at least the following capability :
  • 29. DROP INDEX If we create an index for a base table and later decided we don’t needed anymore we can use DROP INDEX statement to remove index from database. The format of DROP INDEX statement is : DROP INDEX IndexName
  • 30. Reference Connolly, T., & Begg, C. (2015). Database System A Practical Approach to Design, Implemetation, and Management 6th Edition. Pearson