Académique Documents
Professionnel Documents
Culture Documents
IN A DATABASE
2. Queries in DBMS 3. Structure of DBMS
Initially, a database is empty state with no data then, populate (load) the database with data
Database Instance: The actual data stored in a database at a particular moment in time. Also called database state ( or occurrence, snapshot)
The database schema changes very infrequently. The database state changes every time the database is updated.
schema construct
Data model
Collection of high level data description without low level storage
details eg Relational data model Semantic data model describes a real application scenario. Eg: Entity relationship model
Relational model
Relations called as records Data are described as Schema Schema specifies its name, name of the field and type of each field. Eg: Students (Sid:String,name:String,login:String,age:integer)
Name
Jones Smith Smith Madayan Mary
Login
jones@cs smith@ee smith@math madayan@music mary@music
age
18 18 19 11 12
External schema 1
External schema 2
External schema 3
Conceptual schema
Physical schema
Disk
Describes the stored data in terms of the data model of the DBMS. This leads to conceptual database design. Also called as logical schema Represents data as a set tables. DBMS maps from conceptual schema to physical schema Example: Student(RegNo:Integer, Name:String, Sem:Integer, Branch:String) Faculty(Fid:Integer, FName:String, Salary:Float) Course(CourseNo:Integer, CName:String, Credit:Integer, Dept:String) Section(SecId:Integer, CourseNo:Integer, Sem:Integer, Year:Integer, Instructor:String) GradeReport(RegNo:Integer, SecId:Integer, Grade:Char)
Describes the actual storage details of the relations described in conceptual schema. Creates Indexes on First Column of Students, Faculty and Course relations. This leads to the physical database design. Physical schema specifies additional storage devices Describes how the relations described in conceptual schema are stored on secondary storage devices such as disks and tapes.
A Database has
One conceptual schema One Physical schema
The data independence is the ability to change the schema at one level of a database system with out changing the schema at a higher level. Logical data Independence Capacity to change the conceptual schema without having to change the external schema, is called as the logical data independence. With out changing the application programs, one can change the logical schema.
Example
Suppose the Faculty relation is modified as: Faculty_Public(Fid:Integer, FName:String, Office:Integer) Faculty_Private(Fid:Integer, Salary:Float) Any view designed before this modification can still retrieve the data with little modification (relation name) and obtain the same answer.
Database Languages
DDL Data Definition Language
SDL Storage Definition Language VDL View Definition Language DML Data Manipulation Language
Data Definition Language (DDL) Used by the DBA and database designers to specify the conceptual schema of a database. In many DBMSs, the DDL is also used to define internal and external schemas (views).
In some DBMSs, separate storage definition language (SDL) and view definition language (VDL) are used to define internal and external schemas. Data Manipulation Language (DML) Used to specify database retrievals and updates (insertion, deletion, modifications)
- Alternatively, stand-alone DML commands can be applied directly (query language).
computer languages used by computer programs and/or database users to insert, delete and update data in a database.
DML
Queries in DBMS
Consider a sample University Database Some questions user might ask: 1. What is the name & address of student with ENO = 06701442010 ? 2. How many students are enrolled in BBA 108? 3. How many students have more than 70% ? Such questions involving the data stored in a DBMS are called Queries. DBMS provides specialized language called Query Language
Relational Calculus is a formal query language based on mathematical logic. Relational Algebra is another formal query language based on collection of Operators .
DBMS takes great care to evaluate queries as efficiently as possible. Indexes can be used to speed up Queries.
Relational Calculus
Relational calculus consists of two calculi, the
tuple relational calculus and the domain relational calculus, that are part of the relational model for databases provides a declarative way to specify database queries.
This in contrast to the relational algebra which is also part of the relational model but provides a more procedural way for specifying queries.
Relational Algebra
Relational algebras received little attention until
the publication of E.F. Codd's relational model of data in 1970. Codd proposed such an algebra as a basis for database query languages The six primitive operators of Codd's algebra are the selection, the projection, the Cartesian product (also called the cross product or cross join), the set union, the set difference, and the rename
Queries
Find all courses that Mary takes
SELECT C.name FROM Students S, Takes T, Courses C WHERE S.name=Mary and S.ssn = T.ssn and T.cid = C.cid
What happens behind the scene ? Query processor figures out how to answer the query efficiently.
Structure of a DBMS
A typical DBMS has a layered architecture. This is one of several possible architectures; each system has its own variations.
Architecture of DBMS
Webforms Application front ends
SQL commands
SQL interface
parser Optimizer
Shows interaction
Query Evaluation Engine Transaction Manager Files and Access Buffer Manager Lock manager Concurrency Control Disk space Manager
Recovery Manager
Shows references
Database
DBMS accepts SQL commands generated from variety of user interfaces Query is parsed and then presented to Query optimizer An execution plan is produced which is a blueprint for evaluating query The code that implements query lies above file and access method layer in which heap files are managed
Below it is buffer manager which handles read requests of files from disk to memory The lowest layer is Disk Space Manager DBMS components associated with concurrency control and crash recovery includes: Transaction Manager which ensures transaction request and schedules Lock Manager which handles locks grant and release on data
items
Recovery Manager which maintains log and restores system to consistent state after system crash.