SQL Fundamentals
Oracle 11g
M U H A M M A D WA H E E D
O R A C L E D ATA B A S E D E VE L O P E R
E M A I L : m.w a h e e d 3 6 6 8 @ g ma i l . c om
.
1
Lecture#1
Introduction
2
How to achieve certificate?
•Attendance
•Quizzes
•Assignments
•Final( if possible)
3
Course Policies
•All deadlines will be hard.
•Reading assignments are expected to be read before next lecture.
•Anyone may be asked to describe the summary or a particular
discussion from the same.
4
Course Policies(cont’d)
Exams/Quizzes can be from the following:
• Current lecture
• Material covered in any previous lecture
• Reading assignments
• From any assigned homework.
5
Course Policies(cont’d)
•Quizzes will be unannounced some time.
•They will be taken either in the first ten minutes of the class (so come to
the class on time & be prepared!) or in the last ten minutes of the class
(so listen to the lecture carefully).
6
Course Includes
•20 % theory
•80% Practical
•You are required to have laptop in each class to complete practical work
7
How Much this course
Valuable?
After the SUCCESSFUL completion of this course
you can appear for the following oracle exams
•1Z0-051:OracleDatabase 11g: SQL Fundamentals I
•1Z0-061:OracleDatabase 12c: SQL Fundamentals
•1Z0-071:OracleDatabase SQL Fundamentals
8
Database
•What is Database?
Databaseis an organizedcollection of logically relateddata that is
stored in an efficientand compact manner.
•Organized means data stored in a way that is easy to use.
•Logically related term refers to the topic of interest.
•Efficient means data can be accessed quickly.
•Compact is used for the storage optimization.
•Example :
Campus ManagementSystem(CMS), UAAR.
9
Data vs Information
1. Data should be arranged/structured in such a way that one can effectively process it
when necessary.
Example : Data about student
Unorganized Data:
Muhammadwaheeduiit12-arid-197124
Muhammad,waheeduiit12-arid-197124
 difficult to distinguish between L name and dept then between arid no and age.
Organized Data:
Muhammad#waheed#uiit#12-arid-1971#24
OR
Muhammad
Waheed
Uiit
12-arid-1971
24
10
Data vs Information (cont’d)
Simple difference between data and information is that information is
data that have been processed in such a way that the knowledge of
the person who uses the data is increased. Example
Muhammad
waheed
uiit
12-arid-1971
24
11
Cont’d
From above data we can obtain some knowledge on the base of guess.
This data can be converted into information by doing some process as
follow. Student
adding a few additional data items and providing some structure. After
that we recognize that it’s a data of some student; f name, l name ,dept,
age and reg no.
12
F Name L name Dept Age Reg no
Muhammad Waheed Uiit 24 12-arid-1971
Metadata
•Dataabout data is called metadata.
•Just like in above examplef_name, l_name ,dept, age, and reg no is a
data that is used to describe actual data. So this additional data is called
metadata.
13
Some Database Terminologies
•Table/Relation/File/Entity/object
•Tuple/row/record
•Attribute/Column/Field
•Metadata/Data about Data/Domain/Data
Dictionary
14
Database
Terminologies(cont’d)
F Name L name Dept Age Reg no
Muhamma
d
Waheed Uiit 20 12-arid-xyz
Danyal Khan Uiit 20 12-arid-xyz
Shabano Malik Uiit 20 12-arid-xyz
Humza Hamid Uiit 24 12-arid-xyz
15
Student TableAttribute
Metadata
Records
Data
Entity-Relationship Daigrams
16
•Entity
•Attribute
•Relationship
•Cardinality
ERD(cont’d)
Entities
17
ERD(cont’d)
Attribute
18
ERD(cont’d)
Relationship
19
ERD(cont’d)
Cardinality
20
DatabaseKeys
Databasesupports the following types of keys.
•Super Key
•Candidate Key
•Primary Key
•Unique Key
•Composite Key
21
Cont’d
•Foreign Key
•Natural Key
•Surrogate Key
22
Example
23
Super key
Super key is a set of one or more than one keys that can be used to
uniquely identify the record in Table.
•Branch_Id
•Branch_Name
•Branch_Code
•{ Branch_Id, Branch_Code }
•{ Branch_Name , Branch_Code }
24
Super keys
Student_Information Table:
•Student_Id
•College_Id
•Rtu_Roll_No
•{ Student_Id, Student_Name}
•{ College_Id, Branch_Id }
•{ Rtu_Roll_No, Session }
25
Candidate key
•A Candidate key is an attribute or set of attributes that uniquely
identifies a record.
• Among the set of candidate, one candidate key is chosen as Primary
Key.
• table can have multiple candidate key but each table can have
maximum one primary key.
26
Example
Possible Candidate Keys in Branch_Info table.
•Branch_Id
•Branch_Name
•Branch_Code
27
Primary key
•Selected from Candidate keys
•Unique and not null
•Can be more than one Attributes
•Example:
Branch_Id, College_Id
28
Alternate key/Secondary key
•Alternate keys are candidate keys that are not selected as primary key.
•Alternate key can also work as a primary key.
•Alternate key is also called “Secondary Key”.
•Example:
Branch_Name, Branch_Code, Student_Id, Rtu_Roll_No
29
Unique Key
•Unique key is similar to primary key but unique key field can contain a
“Null” value but primary key doesn’t allow “Null” value.
•Example:
Branch_Name, Rtu_Roll_No
30
Composite key/Compound key
•Composite key is a combination of more than one attributes.
•It is also known as “Compound” key.
•A composite key may be a candidate or primary key.
•Example:
{ Branch_Name, Branch_Code}
{ Student_Id, Student_Name }
31
Natural Key/Business
key/Domain Key
•A natural key is a key composed of columns that actually have a logical
relationship to other columns within a table.
• Example:
if we use Student_Id, Student_Name and Father_Name columns to
form a key then it would be “Natural Key”
32
Surrogate key
•It is an artificial key that is used to uniquely identify the record in table.
It can either be used just for simple sequential number.
•Example:
Sql server “is identity”, Ms access “auto number”
33
Foreign key
•Foreign key is used to generate the relationship between the tables.
•Foreign Key is a field in database table that is Primary key in another
table.
•Example:
Branch_Id is a Foreign Key in Student_Information table and related
primary key existin Branch_Info(Branch_Id) table.
34
Keys confusion?
35
Ok Only Remember Two
i.e. Primary, Foriegn
Conclusion
Databasegenerally only contain Primary Key, Foreign Key, Unique Key
and Surrogate key (some time) and other remaining keys are just
concept.
36
Short Quiz
•Why we Using Keys?
•What is P.K?
•What is F.k?
•F.K can be null?
•F.K Can be Duplicate?
•What is parent Table ?
•What is child Table?
37

What is DBMS
An application software/tool that is used to create , maintain and
provide control access/security to database is called DBMS.
•Oracle RDBMS
•MS SQL server
•IBM DB2
•Mysql
•Postgre sql
•Mongo DB
38
DBMS?
•Is MS Access a DBMS?
•Is MS Excel a DBMS?
•Real world databaseapplication examples?
39
Popularity & Demand of the Tool
Oracle on which we will work?
40
Architecture of Oracle DB Apps
Oracle 6i
41
3- tier
42
What is Oracle GUI Tier?
Oracle Forms
43
Oracle Reports
44
Home Work (Ans with Example)
•What is data, entity, domain ,referential and User-Defined Integrity.
•Datatypes in oracle 11g.
•How to select Candidate keys from super keys?
•How to select P.K from candidate keys?
45
Your Suggestions?
“Connecting with Student is not hard. I like the interaction and the
feedback after Lecture”
46

SQL Fundamentals (Oracle 11g) - Lecture 1

  • 1.
    SQL Fundamentals Oracle 11g MU H A M M A D WA H E E D O R A C L E D ATA B A S E D E VE L O P E R E M A I L : m.w a h e e d 3 6 6 8 @ g ma i l . c om . 1 Lecture#1
  • 2.
  • 3.
    How to achievecertificate? •Attendance •Quizzes •Assignments •Final( if possible) 3
  • 4.
    Course Policies •All deadlineswill be hard. •Reading assignments are expected to be read before next lecture. •Anyone may be asked to describe the summary or a particular discussion from the same. 4
  • 5.
    Course Policies(cont’d) Exams/Quizzes canbe from the following: • Current lecture • Material covered in any previous lecture • Reading assignments • From any assigned homework. 5
  • 6.
    Course Policies(cont’d) •Quizzes willbe unannounced some time. •They will be taken either in the first ten minutes of the class (so come to the class on time & be prepared!) or in the last ten minutes of the class (so listen to the lecture carefully). 6
  • 7.
    Course Includes •20 %theory •80% Practical •You are required to have laptop in each class to complete practical work 7
  • 8.
    How Much thiscourse Valuable? After the SUCCESSFUL completion of this course you can appear for the following oracle exams •1Z0-051:OracleDatabase 11g: SQL Fundamentals I •1Z0-061:OracleDatabase 12c: SQL Fundamentals •1Z0-071:OracleDatabase SQL Fundamentals 8
  • 9.
    Database •What is Database? Databaseisan organizedcollection of logically relateddata that is stored in an efficientand compact manner. •Organized means data stored in a way that is easy to use. •Logically related term refers to the topic of interest. •Efficient means data can be accessed quickly. •Compact is used for the storage optimization. •Example : Campus ManagementSystem(CMS), UAAR. 9
  • 10.
    Data vs Information 1.Data should be arranged/structured in such a way that one can effectively process it when necessary. Example : Data about student Unorganized Data: Muhammadwaheeduiit12-arid-197124 Muhammad,waheeduiit12-arid-197124  difficult to distinguish between L name and dept then between arid no and age. Organized Data: Muhammad#waheed#uiit#12-arid-1971#24 OR Muhammad Waheed Uiit 12-arid-1971 24 10
  • 11.
    Data vs Information(cont’d) Simple difference between data and information is that information is data that have been processed in such a way that the knowledge of the person who uses the data is increased. Example Muhammad waheed uiit 12-arid-1971 24 11
  • 12.
    Cont’d From above datawe can obtain some knowledge on the base of guess. This data can be converted into information by doing some process as follow. Student adding a few additional data items and providing some structure. After that we recognize that it’s a data of some student; f name, l name ,dept, age and reg no. 12 F Name L name Dept Age Reg no Muhammad Waheed Uiit 24 12-arid-1971
  • 13.
    Metadata •Dataabout data iscalled metadata. •Just like in above examplef_name, l_name ,dept, age, and reg no is a data that is used to describe actual data. So this additional data is called metadata. 13
  • 14.
  • 15.
    Database Terminologies(cont’d) F Name Lname Dept Age Reg no Muhamma d Waheed Uiit 20 12-arid-xyz Danyal Khan Uiit 20 12-arid-xyz Shabano Malik Uiit 20 12-arid-xyz Humza Hamid Uiit 24 12-arid-xyz 15 Student TableAttribute Metadata Records Data
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
    DatabaseKeys Databasesupports the followingtypes of keys. •Super Key •Candidate Key •Primary Key •Unique Key •Composite Key 21
  • 22.
  • 23.
  • 24.
    Super key Super keyis a set of one or more than one keys that can be used to uniquely identify the record in Table. •Branch_Id •Branch_Name •Branch_Code •{ Branch_Id, Branch_Code } •{ Branch_Name , Branch_Code } 24
  • 25.
    Super keys Student_Information Table: •Student_Id •College_Id •Rtu_Roll_No •{Student_Id, Student_Name} •{ College_Id, Branch_Id } •{ Rtu_Roll_No, Session } 25
  • 26.
    Candidate key •A Candidatekey is an attribute or set of attributes that uniquely identifies a record. • Among the set of candidate, one candidate key is chosen as Primary Key. • table can have multiple candidate key but each table can have maximum one primary key. 26
  • 27.
    Example Possible Candidate Keysin Branch_Info table. •Branch_Id •Branch_Name •Branch_Code 27
  • 28.
    Primary key •Selected fromCandidate keys •Unique and not null •Can be more than one Attributes •Example: Branch_Id, College_Id 28
  • 29.
    Alternate key/Secondary key •Alternatekeys are candidate keys that are not selected as primary key. •Alternate key can also work as a primary key. •Alternate key is also called “Secondary Key”. •Example: Branch_Name, Branch_Code, Student_Id, Rtu_Roll_No 29
  • 30.
    Unique Key •Unique keyis similar to primary key but unique key field can contain a “Null” value but primary key doesn’t allow “Null” value. •Example: Branch_Name, Rtu_Roll_No 30
  • 31.
    Composite key/Compound key •Compositekey is a combination of more than one attributes. •It is also known as “Compound” key. •A composite key may be a candidate or primary key. •Example: { Branch_Name, Branch_Code} { Student_Id, Student_Name } 31
  • 32.
    Natural Key/Business key/Domain Key •Anatural key is a key composed of columns that actually have a logical relationship to other columns within a table. • Example: if we use Student_Id, Student_Name and Father_Name columns to form a key then it would be “Natural Key” 32
  • 33.
    Surrogate key •It isan artificial key that is used to uniquely identify the record in table. It can either be used just for simple sequential number. •Example: Sql server “is identity”, Ms access “auto number” 33
  • 34.
    Foreign key •Foreign keyis used to generate the relationship between the tables. •Foreign Key is a field in database table that is Primary key in another table. •Example: Branch_Id is a Foreign Key in Student_Information table and related primary key existin Branch_Info(Branch_Id) table. 34
  • 35.
    Keys confusion? 35 Ok OnlyRemember Two i.e. Primary, Foriegn
  • 36.
    Conclusion Databasegenerally only containPrimary Key, Foreign Key, Unique Key and Surrogate key (some time) and other remaining keys are just concept. 36
  • 37.
    Short Quiz •Why weUsing Keys? •What is P.K? •What is F.k? •F.K can be null? •F.K Can be Duplicate? •What is parent Table ? •What is child Table? 37 
  • 38.
    What is DBMS Anapplication software/tool that is used to create , maintain and provide control access/security to database is called DBMS. •Oracle RDBMS •MS SQL server •IBM DB2 •Mysql •Postgre sql •Mongo DB 38
  • 39.
    DBMS? •Is MS Accessa DBMS? •Is MS Excel a DBMS? •Real world databaseapplication examples? 39
  • 40.
    Popularity & Demandof the Tool Oracle on which we will work? 40
  • 41.
    Architecture of OracleDB Apps Oracle 6i 41
  • 42.
  • 43.
    What is OracleGUI Tier? Oracle Forms 43
  • 44.
  • 45.
    Home Work (Answith Example) •What is data, entity, domain ,referential and User-Defined Integrity. •Datatypes in oracle 11g. •How to select Candidate keys from super keys? •How to select P.K from candidate keys? 45
  • 46.
    Your Suggestions? “Connecting withStudent is not hard. I like the interaction and the feedback after Lecture” 46