SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Er. Nawaraj Bhandari
Topic 7
SQL 1
Objectives of SQL
 Create the database and relation structures
 Perform basic tasks such as inserts, updates and deletes
 Simple and complex queries
Structured Query Language
Data Definition Language: DDL
 For defining database structures and controlling access to data
 CREATE TABLE, CREATE INDEX , CREATE SEQUENCE , GRANT ACCESS
etc.
Data Manipulation Language: DML
 For retrieving and updating data
 SELECT, INSERT, UPDATE, DELETE
History of SQL - 1
 Developed from IBM’s SYSTEM R
 The database standard language by 1970s...
 First standard published in 1987 by ISO
History of SQL - 2
 Addition to standard published 1989
 SQL 1992 – Major revision ‘SQL-92’
 SQL: 1999 - with object-relational features
 SQL: 2003 - introduced concept of ‘core SQL’
 SQL: 2006 – user of SQL with XML
 SQL: 2008 minor revisions.
Data Manipulation Language: DML
 For retrieving and updating data
 SELECT – retrieving
 INSERT, UPDATE, DELETE – updating
Difference between INSERT and UPDATE?
Literals
 Insert into Student (Stu_id, First_name, Last_name)
 Values (1,’Satpal’,’Singh’);
- Non-numeric in single quotes
- Numeric NOT in quotes
Select branchID, Count(staff_id)
From workers
Where branchType = ‘Main’
Group by branchID
Having Count (staff_id) > 1
Order by branchID
Select branchID, Count(staff_id)
From workers
Where branchType = ‘Main’
Group by branchID
Having Count (staff_id) > 1
Order by branchID
Which columns will appear?
Which table?
Condition
Groups by some column
Value
Restricts what will
Be grouped
Specifies the order of the result
Database Update
 Insert
 Update
 Delete
Insert
 Insert into students (Student_id, first_name, last_name)
 Values (1,’Satpal’,’Singh’);
 Insert into students
 Values (1,’Satpal’,’Singh’,’Overseas’,’Undergrad’);
Update
 Update Students
 Set Student_type = ‘Undergrad’;
 Update Students
 Set student_type = ‘Undergrad’
 Where student_id = 1;
Delete
 Delete from Students;
 Delete from Students
 Where student_id = 1;
Activity
 Departments
 Department_Id Integer
 Department_Name varchar 30
 Location varchar 30
 Departments
 Department_Id Integer
 Department_Name varchar 30
 Location varchar 30
• Insert into Departments
• Values (8,’Complaints’,’Glasgow’):
Commit;
Rollback;
Datatypes
 What is a datatype?
 What is a domain?
String Datatypes
 Character or Char
 Varying Character of Varchar
 Bit (N)
 Bit varying
Char or Varchar
 ‘Gary__’ a 6 long Char
 ‘Gary’ a 6 long varchar
Numeric Datatypes
 Numeric or Decimal, e.g. 8.23 with point set
 Integer, e.g. 8
 Float, e.g. 8.23 but could also be changed so that point moves when
needed
Datetime Types
 Date
 Time
 Timestamp
 Interval
Advantages of SQL
 Universal
 Easy to use
 Fits (more or less) with relational model
Disadvantages of SQL
 Does not support all features of relational model
 No one standard
 Has had to be extended
 Much redundancy – possible to do the same thing many ways
Learning Outcomes – Have We Met Them?
 By the end of this topic, students will be able to:
 Explain the purpose of SQL
 Outline the basic concepts of SQL
 Understand that there are different ‘flavours’ of SQL
References
 Benyon-Davis, P. (2003). Database Systems, 3rd edition. Palgrave Macmillan.
Chapters 11, 12 & 13.
 Connolly, T. & Begg, C. (2004). Database Systems: A Practical Approach to
Design, Implementation, and Management, 4th Edition. Addison Wesley.
Chapters 5, 6 & 7.
 Dietrich, S. W. (2001). Understanding Relational Database Query Languages, 1st
edition. Prentice Hall. Chapter 5.
ANY QUESTIONS?

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Stored procedure in sql server
Stored procedure in sql serverStored procedure in sql server
Stored procedure in sql server
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
 
Mysql
MysqlMysql
Mysql
 
Basic SQL and History
 Basic SQL and History Basic SQL and History
Basic SQL and History
 
MySQL
MySQLMySQL
MySQL
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Integrity constraints in dbms
Integrity constraints in dbmsIntegrity constraints in dbms
Integrity constraints in dbms
 
ORACLE PL SQL
ORACLE PL SQLORACLE PL SQL
ORACLE PL SQL
 
PL/SQL TRIGGERS
PL/SQL TRIGGERSPL/SQL TRIGGERS
PL/SQL TRIGGERS
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
Database
DatabaseDatabase
Database
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteDatabase Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and delete
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
SQL for interview
SQL for interviewSQL for interview
SQL for interview
 
Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
 
Sql ppt
Sql pptSql ppt
Sql ppt
 
Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Server
 

Andere mochten auch

Crosstab query techniques
Crosstab query techniquesCrosstab query techniques
Crosstab query techniquesaabaap
 
computer software
computer softwarecomputer software
computer softwareRiya Gupta
 
Microsoft access 2007_tutorial
Microsoft access 2007_tutorialMicrosoft access 2007_tutorial
Microsoft access 2007_tutorialAchemm Net
 
Users Guide To Microsoft Word Tables
Users Guide To Microsoft Word TablesUsers Guide To Microsoft Word Tables
Users Guide To Microsoft Word TablesMadhubanti Dasgupta
 
Database Relationships
Database RelationshipsDatabase Relationships
Database Relationshipswmassie
 
Creating relationships with tables
Creating relationships with tablesCreating relationships with tables
Creating relationships with tablesJhen Articona
 
Basic Access Notes
Basic Access NotesBasic Access Notes
Basic Access NotesPyi Soe
 
MS Word 2007 insert tables
MS Word 2007 insert tablesMS Word 2007 insert tables
MS Word 2007 insert tablesVTC
 
The Power Of Mail Merge!
The Power Of Mail Merge!The Power Of Mail Merge!
The Power Of Mail Merge!Rina Banerjee
 
Mail merge made easy
Mail merge made easyMail merge made easy
Mail merge made easyRoel Palmaers
 
Basic introduction to ms access
Basic introduction to ms accessBasic introduction to ms access
Basic introduction to ms accessjigeno
 
Online Shopping Cart Business Requirement Dcoument
Online Shopping Cart Business Requirement DcoumentOnline Shopping Cart Business Requirement Dcoument
Online Shopping Cart Business Requirement DcoumentH2Kinfosys
 
Intro to Microsoft Word 2010 for Kids
Intro to Microsoft Word 2010 for Kids Intro to Microsoft Word 2010 for Kids
Intro to Microsoft Word 2010 for Kids Queens Library
 

Andere mochten auch (20)

Software
SoftwareSoftware
Software
 
Crosstab query techniques
Crosstab query techniquesCrosstab query techniques
Crosstab query techniques
 
computer software
computer softwarecomputer software
computer software
 
Microsoft access 2007_tutorial
Microsoft access 2007_tutorialMicrosoft access 2007_tutorial
Microsoft access 2007_tutorial
 
MS Access 2007 in ITT
MS Access 2007 in ITTMS Access 2007 in ITT
MS Access 2007 in ITT
 
Tables
TablesTables
Tables
 
Users Guide To Microsoft Word Tables
Users Guide To Microsoft Word TablesUsers Guide To Microsoft Word Tables
Users Guide To Microsoft Word Tables
 
Ch03 cmpt110
Ch03 cmpt110Ch03 cmpt110
Ch03 cmpt110
 
Database Relationships
Database RelationshipsDatabase Relationships
Database Relationships
 
Creating relationships with tables
Creating relationships with tablesCreating relationships with tables
Creating relationships with tables
 
Basic Access Notes
Basic Access NotesBasic Access Notes
Basic Access Notes
 
MS Word 2007 insert tables
MS Word 2007 insert tablesMS Word 2007 insert tables
MS Word 2007 insert tables
 
Access 2007
Access 2007Access 2007
Access 2007
 
The Power Of Mail Merge!
The Power Of Mail Merge!The Power Of Mail Merge!
The Power Of Mail Merge!
 
Mail merge made easy
Mail merge made easyMail merge made easy
Mail merge made easy
 
Basic introduction to ms access
Basic introduction to ms accessBasic introduction to ms access
Basic introduction to ms access
 
Online Shopping Cart Business Requirement Dcoument
Online Shopping Cart Business Requirement DcoumentOnline Shopping Cart Business Requirement Dcoument
Online Shopping Cart Business Requirement Dcoument
 
Mail Merge in Microsoft Word
Mail Merge in Microsoft WordMail Merge in Microsoft Word
Mail Merge in Microsoft Word
 
Ms access 2007
Ms access 2007Ms access 2007
Ms access 2007
 
Intro to Microsoft Word 2010 for Kids
Intro to Microsoft Word 2010 for Kids Intro to Microsoft Word 2010 for Kids
Intro to Microsoft Word 2010 for Kids
 

Ähnlich wie SQL

Database Management Lab -SQL Queries
Database Management Lab -SQL Queries Database Management Lab -SQL Queries
Database Management Lab -SQL Queries shamim hossain
 
Adv DB - Full Handout.pdf
Adv DB - Full Handout.pdfAdv DB - Full Handout.pdf
Adv DB - Full Handout.pdf3BRBoruMedia
 
U-SQL Intro (SQLBits 2016)
U-SQL Intro (SQLBits 2016)U-SQL Intro (SQLBits 2016)
U-SQL Intro (SQLBits 2016)Michael Rys
 
Unit 3 rdbms study_materials-converted
Unit 3  rdbms study_materials-convertedUnit 3  rdbms study_materials-converted
Unit 3 rdbms study_materials-convertedgayaramesh
 
Introduction to SQL, SQL*Plus
Introduction to SQL, SQL*PlusIntroduction to SQL, SQL*Plus
Introduction to SQL, SQL*PlusChhom Karath
 
Islamic University Previous Year Question Solution 2018 (ADBMS)
Islamic University Previous Year Question Solution 2018 (ADBMS)Islamic University Previous Year Question Solution 2018 (ADBMS)
Islamic University Previous Year Question Solution 2018 (ADBMS)Rakibul Hasan Pranto
 
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?Chuk-Munn Lee
 
Student handbook xii
Student handbook xiiStudent handbook xii
Student handbook xiigeetu84
 
DATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMDATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMSonia Pahuja
 

Ähnlich wie SQL (20)

Database Management Lab -SQL Queries
Database Management Lab -SQL Queries Database Management Lab -SQL Queries
Database Management Lab -SQL Queries
 
Adv DB - Full Handout.pdf
Adv DB - Full Handout.pdfAdv DB - Full Handout.pdf
Adv DB - Full Handout.pdf
 
U-SQL Intro (SQLBits 2016)
U-SQL Intro (SQLBits 2016)U-SQL Intro (SQLBits 2016)
U-SQL Intro (SQLBits 2016)
 
Unit 3 rdbms study_materials-converted
Unit 3  rdbms study_materials-convertedUnit 3  rdbms study_materials-converted
Unit 3 rdbms study_materials-converted
 
Module02
Module02Module02
Module02
 
Introduction to Database SQL & PL/SQL
Introduction to Database SQL & PL/SQLIntroduction to Database SQL & PL/SQL
Introduction to Database SQL & PL/SQL
 
Introduction to SQL, SQL*Plus
Introduction to SQL, SQL*PlusIntroduction to SQL, SQL*Plus
Introduction to SQL, SQL*Plus
 
sql-commands.pdf
sql-commands.pdfsql-commands.pdf
sql-commands.pdf
 
Sql commands
Sql commandsSql commands
Sql commands
 
Sql commands
Sql commandsSql commands
Sql commands
 
Pl sql content
Pl sql contentPl sql content
Pl sql content
 
oodb.ppt
oodb.pptoodb.ppt
oodb.ppt
 
Database part2-
Database part2-Database part2-
Database part2-
 
Islamic University Previous Year Question Solution 2018 (ADBMS)
Islamic University Previous Year Question Solution 2018 (ADBMS)Islamic University Previous Year Question Solution 2018 (ADBMS)
Islamic University Previous Year Question Solution 2018 (ADBMS)
 
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Student handbook xii
Student handbook xiiStudent handbook xii
Student handbook xii
 
DATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMDATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEM
 
PO WER - Piotr Mariat - Sql
PO WER - Piotr Mariat - SqlPO WER - Piotr Mariat - Sql
PO WER - Piotr Mariat - Sql
 
PT- Oracle session01
PT- Oracle session01 PT- Oracle session01
PT- Oracle session01
 

Mehr von Bhandari Nawaraj

Mehr von Bhandari Nawaraj (7)

Implementation
ImplementationImplementation
Implementation
 
Supporting Transactions
Supporting TransactionsSupporting Transactions
Supporting Transactions
 
Database Design
Database DesignDatabase Design
Database Design
 
SQL
SQL SQL
SQL
 
The Relational Model
The Relational ModelThe Relational Model
The Relational Model
 
Entity Relationship Modelling
Entity Relationship ModellingEntity Relationship Modelling
Entity Relationship Modelling
 
Dbms
DbmsDbms
Dbms
 

Kürzlich hochgeladen

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 

Kürzlich hochgeladen (20)

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 

SQL

  • 2. Objectives of SQL  Create the database and relation structures  Perform basic tasks such as inserts, updates and deletes  Simple and complex queries Structured Query Language
  • 3. Data Definition Language: DDL  For defining database structures and controlling access to data  CREATE TABLE, CREATE INDEX , CREATE SEQUENCE , GRANT ACCESS etc.
  • 4. Data Manipulation Language: DML  For retrieving and updating data  SELECT, INSERT, UPDATE, DELETE
  • 5. History of SQL - 1  Developed from IBM’s SYSTEM R  The database standard language by 1970s...  First standard published in 1987 by ISO
  • 6. History of SQL - 2  Addition to standard published 1989  SQL 1992 – Major revision ‘SQL-92’  SQL: 1999 - with object-relational features  SQL: 2003 - introduced concept of ‘core SQL’  SQL: 2006 – user of SQL with XML  SQL: 2008 minor revisions.
  • 7. Data Manipulation Language: DML  For retrieving and updating data  SELECT – retrieving  INSERT, UPDATE, DELETE – updating Difference between INSERT and UPDATE?
  • 8. Literals  Insert into Student (Stu_id, First_name, Last_name)  Values (1,’Satpal’,’Singh’); - Non-numeric in single quotes - Numeric NOT in quotes
  • 9. Select branchID, Count(staff_id) From workers Where branchType = ‘Main’ Group by branchID Having Count (staff_id) > 1 Order by branchID
  • 10. Select branchID, Count(staff_id) From workers Where branchType = ‘Main’ Group by branchID Having Count (staff_id) > 1 Order by branchID Which columns will appear? Which table? Condition Groups by some column Value Restricts what will Be grouped Specifies the order of the result
  • 11. Database Update  Insert  Update  Delete
  • 12. Insert  Insert into students (Student_id, first_name, last_name)  Values (1,’Satpal’,’Singh’);  Insert into students  Values (1,’Satpal’,’Singh’,’Overseas’,’Undergrad’);
  • 13. Update  Update Students  Set Student_type = ‘Undergrad’;  Update Students  Set student_type = ‘Undergrad’  Where student_id = 1;
  • 14. Delete  Delete from Students;  Delete from Students  Where student_id = 1;
  • 15. Activity  Departments  Department_Id Integer  Department_Name varchar 30  Location varchar 30
  • 16.  Departments  Department_Id Integer  Department_Name varchar 30  Location varchar 30 • Insert into Departments • Values (8,’Complaints’,’Glasgow’):
  • 19. Datatypes  What is a datatype?  What is a domain?
  • 20. String Datatypes  Character or Char  Varying Character of Varchar  Bit (N)  Bit varying
  • 21. Char or Varchar  ‘Gary__’ a 6 long Char  ‘Gary’ a 6 long varchar
  • 22. Numeric Datatypes  Numeric or Decimal, e.g. 8.23 with point set  Integer, e.g. 8  Float, e.g. 8.23 but could also be changed so that point moves when needed
  • 23. Datetime Types  Date  Time  Timestamp  Interval
  • 24. Advantages of SQL  Universal  Easy to use  Fits (more or less) with relational model
  • 25. Disadvantages of SQL  Does not support all features of relational model  No one standard  Has had to be extended  Much redundancy – possible to do the same thing many ways
  • 26. Learning Outcomes – Have We Met Them?  By the end of this topic, students will be able to:  Explain the purpose of SQL  Outline the basic concepts of SQL  Understand that there are different ‘flavours’ of SQL
  • 27. References  Benyon-Davis, P. (2003). Database Systems, 3rd edition. Palgrave Macmillan. Chapters 11, 12 & 13.  Connolly, T. & Begg, C. (2004). Database Systems: A Practical Approach to Design, Implementation, and Management, 4th Edition. Addison Wesley. Chapters 5, 6 & 7.  Dietrich, S. W. (2001). Understanding Relational Database Query Languages, 1st edition. Prentice Hall. Chapter 5.