DB Topic 7 - SQL 1
DB Topic 7 - SQL 1
Topic 7:
SQL 1
Learning Outcomes
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
Objectives of SQL
• Create the database and relation structures
• Perform basic tasks such as inserts, updates and
deletes
• Simple and complex queries
History of SQL - 1
• Developed from IBM’s SYSTEM R
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.
• SELECT – retrieving
• INSERT, UPDATE, DELETE – updating
Literals
• Insert into Student (Stu_id, First_name,
Last_name)
• Values (1,’Satpal’,’Singh’);
Order by branchID
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’);
Update
• Update Students
• Set Student_type = ‘Undergrad’;
• Update Students
• Set student_type = ‘Undergrad’
• Where student_id = 1;
Delete
• Delete from Students;
Activity
• Departments
• Department_Id Integer
• Department_Name varchar 30
• Location varchar 30
• Departments
• Department_Id Integer
• Department_Name varchar 30
• Location varchar 30
Commit;
Rollback;
Datatypes
• What is a datatype?
u ch
r e m t
• What is a domain? s a r e n
e
p yd i f f e
t a t y L
a
D cte d b S Q
o f
af f e ou rs ’
v
‘fla
String Datatypes
• Character or Char
• Varying Character of Varchar
• Bit (N)
• Bit varying
Char or Varchar
• ‘Gary__’ a 6 long Char
Numeric Datatypes
• Numeric or Decimal, e.g. 8.23 with point set
• Integer, e.g. 8
Datetime Types
• Date
• Time
• Timestamp
• Interval
Advantages of SQL
• Universal
• Easy to use
Disadvantages of SQL
• Does not support all features of relational model
• No one standard
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.
Topic 7 – SQL 1
Any Questions?