DBMS
DBMS
DBMS
Systems
Introduction
• Data:
• It is the measurement of any measurable physical or conceptual entity
or process or fact.
• It has no meaning in itself.
• It has implicit meaning.
• Its context or environment of measurement gives its implicit meaning.
• Example:
• {40.46, 56.32, 75.88}
• weight of students = {40.46, 56.32, 75.88}
Introduction
• Information:
• It is the processed and interpreted data.
• Its meaning is explicit.
• Example:
• weight of any 3 students = {40.46, 56.32, 75.88}
• The weight of the heaviest among the 3 students = 75.88
• Average weight of the above 3 student = 57.56
• Rank of NIT-R in 2018-19 = 13
• Campus Placement percentage of CSE NIT-R = 99%
Introduction
• Database:
• Collection of related data representing some part of real world.
• Example:
• Bank Database, University Database, Facebook Database.
• Election Database, Income Tax Database etc.
• Each database has a definite use or application.
Introduction
File Handling
Data Entry, Routines
Reports File
Definition
File Handling
Data Entry, Routines
Reports File
Definition
• Components of DBMS:
Introduction
• 2. DBMS based System:
• Advantages:
• Data duplication eliminated
• Controlled redundancy.
• Restricting unauthorized access.
• Providing backup and recovery.
• Providing Multiple User Interface.
• Enforcing Security and integrity constraints.
• Centralized Control and Data quality enhanced.
Introduction
• 2. DBMS based System:
• Disadvantages:
• Problems associated with centralization
• Cost of software/hardware and migration
• Complexity of backup and recovery
• Can’t be used for many real time embedded systems
• Levels of Abstraction in Database:
User-1 User-2 User-n
View-1 View-2 View-n External Level
External/Conceptual
Mapping
Conceptual
Conceptual Schema Level
Conceptual/Internal
Mapping
Database
Levels of Abstraction in Database:
External Level:
• It contains user views of the database.
• The user’s view describes only that part of the database which is relevant to a
user.
• Different user views have different representation of the same data according to
user’s need or comfort.
• It also provides a level of security by allowing certain group of users to access
only certain types of data and not the entire database.
• Example:
• Viewing one’s bank transaction, balance etc.
• Viewing one’s online purchase order, exam result etc.
Levels of Abstraction in Database:
Conceptual Level:
• It contains the description of all the data in the database of an organization and
the relationships among the data.
• It contains the logical structure of the entire database.
• It represents:
• All entities, attributes and their relationships
• Constraints of the data
• Semantic information about the data
• Security and Integrity information
• It should not contain any storage details about the data
• Example:
• Student data is logically stored using relation schema as
Student(RollNo, Name, Branch, DoB, Sex)
Levels of Abstraction in Database:
Internal Level:
• It describes how the data is physically stored in the database.
• It is concerned with:
• Storage space allocation for data and indexes,
• Record descriptions for storage
• Record Placement
• Data compression and encryption techniques
Levels of Abstraction in Database:
Data Model:
• It is a collection of high-level data description constructs that hide many
low level storage details.
• It description is more closer to how data is stored in a database, than to
how a user thinks of the data with respect to enterprise it represents.
• Example: Relational Data Model
• ---OR------------------------
• insert into <table-name> values (value1,….);
• Example:
• insert into student values(2017001, ‘john’, 8.5);
Student
rollno name CGPA
2017001 john 8.5
2017024 mary 7.5
Command to display all the rows & columns of a table:
• select * from <table-name>;
• Example:
• select * from student;
Student
rollno name CGPA
2017001 john 8.5
2017024 mary 7.5
Command to display all columns & specific rows of a table:
• select * from <table-name> where <conditions>;
• Example:
• select * from student where student.rollno=2017001;
• select * from student where student.name=‘john’;
• select * from student where student.CGPA>7;
Student
rollno name CGPA
2017001 john 8.5
2017024 mary 7.5
Command to display specific columns & all rows of a table:
• select <column name(s)> from <table-name>;
• Example:
• select rollno, name from student;
Command to display specific columns & rows of a table:
• select <column name(s)> from <table-name> where <conditions>;
• Example:
• select rollno, name from student where student.rollno=2017024;
Command to delete a row(s) from a table:
• delete from <table-name> where <conditions>;
• Example:
• delete from student where student.rollno=2017001;
Student
rollno name CGPA
Command to update the column value(s) in a table:
• update <table-name> set <col-1=val-1,col-2-val-2,…>
where <conditions>;
• Example:
• update student set student.CGPA=9.98 where student.roll=2017024;
Grade
Null Value:
• Not applicable
• Unknown
Relational Model Constraints:
1. Domain Constraint:
• It specifies that for each tuple the value of each of its attribute, A, must be
an atomic value from the domain of A.
2. Entity Integrity:
• It specifies that in a base relation, no attribute(s) of a primary key can be
null.
3. Referential Integrity:
• If a foreign key exits in a child relation, then either the foreign key
value(s) must match the primary key value(s) of the parent relation or the
foreign key value(s) must be null.
FA-ID Faculty-Advisor-name
FA976 Smith
FA764 Tomas
Faculty_Advisor
student
Command to Specify Primary & Foreign Key for a table:
• Create table <table-name>
( col-1 data-type,
col-2 data-type, …
constraint <constraint_name> primary key (col-1,col-2,…)
);
• Example:
• Create table student
(rollno number,
name char(20),
constraint student_pk primary key (rollno)
);
Command to Specify Primary Key using alter table command:
• Alter table <table-name>
add constraint <constraint_name> primary key (col-1,col-2,…);
• Example:
• alter table student
add constraint student_pk primary key (rollno);
• Example:
• alter table student
drop constraint student_pk;
Disable Primary Key using alter table command:
• Alter table <table-name>
disable constraint <constraint_name>;
• Example:
• alter table student
disable constraint student_pk;
• Example:
• alter table student
enable constraint student_pk;
Command for Foreign Key constraint: