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.
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
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
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;
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
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.