Midexam

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

What is a DBMS?

Database Management System DBMS is software designed to assist in maintaining and


utilizing large collections of data.
Advantages of a DBMS
1. Program-Data Independence: Allows changing data storage structures and operations
without having to change the DBMS access programs.
2. Efficient Data Access DBMS uses a variety of techniques to store & retrieve data
efficiently.
3. Data Integrity & Security Before inserting salary of an employee, the DBMS can check
that the dept. budget is not exceeded
4. Enforces access controls that govern what data is visible to different classes of users.
5. When several users share data, centralizing the administration offers significant
improvement.
6. DBMS schedules concurrent access to the data in such a manner that users think of the
data as being accessed by only one user at a time.
7. DBMS protects users from the ill-effects of system failures.
8. Reduced Application Development Time.
Data Model: A data model is collection of concepts for describing data.
Schema: is a description of a particular collection of data, using the given data model.
Levels of Abstraction: There 3 types;
1. Physical or Internal Level: Lowest level of abstraction describes how data are actually
stored. Describes complex low-level data structures in detail.
2. Logical or Conceptual Level: Describes what data are stored in the DB & what
relationships exist among those data. Describes the entire DB in terms of relatively
simpler structures
3. View or External Level: Highest level of abstraction which describes only a part of the
DB. User’s view of the DB. This level describes part of the DB that is relevant to each
user.
Procedural DML: require a user to specify what data are needed and how to get those data.
Declarative DML: require a user to specify what data are needed without specifying how to
get those data.
Storage Manager: A program module that provides the interface between the low-level
data stored in the database and the application programs and queries submitted to the
system. The storage manager is responsible to the following tasks:
 Interaction with the OS file manager
 Efficient storing, retrieving and updating of data
Transaction Management: A transaction is a collection of operations that performs a single
logical function in a database application
Transaction-management component ensures that the database remains in a consistent
(correct) state despite system failures (e.g., power failures and operating system crashes)
and transaction failures.
Relational Algebra: A procedural language consisting of a set of operations that take one or
two relations as input and produce a new relation as their result.
Introduction to SQL: Domain Types in SQL
 char(n): Fixed length character string, with user-specified length n.
 varchar(n): Variable length character strings, with user-specified maximum length n.
 int: Integer (a finite subset of the integers that is machine-dependent).
 Smallint: Small integer (a machine-dependent subset of the integer domain type).
 numeric(p,d): Fixed point number, with user-specified precision of p digits, with d digits
to the right of decimal point. (ex., numeric (3,1), allows 44.5 to be stores exactly, but not
444.5 or 0.32)
 real, double precision: Floating point and double-precision floating point numbers, with
machine-dependent precision.
 float(n): Floating point number, with user-specified precision of at least n digits.
Create table
create table takes (
ID varchar(5),
course_id varchar(8),
sec_id varchar(8),
semester varchar(6),
year numeric(4,0),
grade varchar(2),
primary key (ID, course_id, sec_id, semester, year),
foreign key (ID) references student,
foreign key (course_id, sec_id, semester, year) references section);
insert: insert into instructor values ('10211', 'Smith', 'Biology', 66000);
Null Values: null signifies an unknown value or that a value does not exist.
Ex: 5 + null returns null. Boolean operations of null:
and:
 (true and unknown) = unknown, or:
 (false and unknown) = false,  (unknown or true) = true,
 (unknown and unknown) = unknown  (unknown or false) = unknown
 (unknown or unknown) = unknown
Note: predicates in the having clause are applied after the formation of groups
whereas predicates in the where clause are applied before forming groups.
“some” Clause:
Find names of instructors with salary greater than that of some (at least one) instructor in
the Biology department.
select name from instructor
where salary > some (select salary from instructor where dept name = 'Biology');
“all” Clause:
Find the names of all instructors whose salary is greater than the salary of all instructors in
the Biology department.
select name from instructor
where salary > all (select salary from instructor where dept name = 'Biology');
“exists” Clause:
Find all courses taught in both the Fall 2017 semester and in the Spring 2018 semester.
select course_id from section as S
where semester = 'Fall' and year = 2017
and exists (select * from section as T where semester = 'Spring' and year= 2018 and
S.course_id = T.course_id);

unique Clause: Find all courses that were offered at most once in 2017
select T.course_id from course as T
where unique ( select R.course_id from section as R where T.course_id= R.course_id and
R.year = 2017);
Subqueries in the Form Clause: Find the average instructors’ salaries of those departments
where the average salary is greater than $42,000.
select dept_name, avg_salary
from ( select dept_name, avg (salary) as avg_salary from instructor group by dept_name)
where avg_salary > 42000;
OR
select dept_name, avg_salary from (select dept_name, avg (salary) from instructor group by
dept_name) as dept_avg (dept_name, avg_salary)
where avg_salary > 42000;

You might also like