Académique Documents
Professionnel Documents
Culture Documents
Formal Definition:
DBMS: is a general purpose software system that facilitates the processes of defining, constructing,
manipulating, and sharing databases among various users and applications.
o Defining Defining a database involves specifying the datatypes, structures, and constraints of the
data that has to be stored in the database. oConstructing Constructing the database is the
process of storing the data itself on some storage medium that is controlled by the DBMS.
o Manipulating Manipulating a database includes such functions as querying the database to retrieve
specific data, updating the database to reflect changes in the mini world, and generating reports from
the data.
o Sharing Sharing a database allows multiple users and programs to access the database
simultaneously.
Example :
University Database:
Bank Database:
Data Stored: Data about Bank accounts, Customer details, Deposits, Loans and credits, Online
banking registrations etc
Purpose: To keep daily bank transaction of all branches of the bank through data sharing
As shown in figure 7.1, the DBMS software users interact with the database system using queries (written
in software like SQL plus) or Application programs (like Java) to make operations on the database. These
queries are the processed by the DBMS software and the user is given access to the database. The data
present in the database is stored in the hardware in 2 forms, one is metadata which is the definition of the
data stored and the other is the real data present in the database.
- DB system contains the complete definition of structure and the constraints which makes itself
describing.
- The description of the structure and constraints of the data is termed as Meta-data.
- This information (meta-data) is used either by the DBMS software or database users who need
information about the database structures.
- On the other hand, in file based systems, the definition of the data is a part of application program
that has to be handled by the users.
- In file based system, the structure of the data is stored in the application program. As a result, if we
want to change any definition of the data, then the program that accesses that data has to be
changed.
- Whereas, in database systems, as the data structures are stored in the catalog and not in programs,
we can manipulate any one i.e. either program or data whichever is needed.
- Thus DBMS provides program and data independence. iii. Support multiple views of the Data :
- View is a subset of the database. View contains virtual data that is derived from the database files but
it is not explicitly stored.
- Multiple users in the same Database system might have different views of that system. Each view
might contain only the data of interest to that user or a group of users.
- The Concurrency Control Techniques of DBMS ensures that several users trying to access and
update the same data do so in a controlled manner.
- Not all users of the system have the same accessing privileges. DBMS provides a security sub
system to create and control the user accounts.
- At view level, the ER model is considered a good option for designing databases.
- Entity :
Example, in an university database, students, teachers, classes, and courses offered can be
considered as entities.
- Entity set :
An entity set may contain entities with their properties sharing similar values.
For example, a Students set may contain all the students of university; likewise a Teachers set may
contain all the teachers of university from all faculties.
Attributes:
For example, a student entity may have name, class, and age as attributes.
There exists a domain or range of values that can be assigned to attributes. For example, a student's
name cannot be a numeric value. It has to be alphabetic. A student's age cannot be negative, etc.
Types of attributes :
Simple attribute: The attributes with the atomic values which cannot be divided further are classified
as Simple attributes. For example, a student's phone number is an atomic value of 10 digits.
Composite attribute: Attributes made up of more than one simple attribute are termed as Composite
attributes. For example, a student's complete name may have first_name , middle_name and
last_name.
Derived attribute: Derived attributes are the attributes that do not exist in the physical database, but
their values are derived from other attributes present in the database. For example, average_salary in
a department should not be saved directly in the database, instead it can be derived. To quote
another example, age can be derived from data_of_birth.
Single value attribute: Single value attributes contain single value. For example ,
Social_security_number of an employee, USN of a student etc..
Multi value attribute: Multi value attributes may contain more than one values. For example, a person
can have more than one phone numbers, email addresses etc ..
Key is an attribute or collection of attributes that uniquely identifies an entity among entity set.
For example, the roll_number of a student makes him/her identifiable among students.
o Super Key A set of attributes (one or more) that collectively identifies an entity in an entity set.
o Candidate Key A minimal super key is called a candidate key. An entity set may have more than
one candidate key.
o Primary Key A primary key is one of the candidate keys chosen by the database designer to
uniquely identify the entity set.
Relationship:
Types :
Mapping cardinalities:
Cardinality defines the number of entities in one entity set, which can be associated with the number
of entities of other entity set via relationship set.
Types of Cardinality :
II. One-to-many One entity from entity set A can be associated with more than one entities of entity set B
however an entity from entity set B, can be associated with at most one entity.
III.Many-to-one More than one entities from entity set A can be associated with at most one entity of entity
set B, however an entity from entity set B can be associated with more than one entity from entity set
A.
ER NOTATION:
Relational Schema:
o Relational Schema consists of relational name,and a set of attributes or field names or column
names.
o Each attribute is associated with its domain. o Domain = Set of atomic values + Data types.
Example:
Normalization:
-A relation can be normalized to a specific form to prevent the possible occurrence of update anomalies.
- As normalization proceeds, the relations become progressively more restricted (stronger) in format and
also less vulnerable to update anomalies.
-This Violates 1NF, because of DeptName i.e. a single student cannot belong to two departments.
Solution1:
Use multiple tuples one per value.
Student_Apply(RollNo, DeptName, Name, Age)
Solution2:
Split the Student table into two different tables.
Student(RollNo, Name, Age)
Apply(RollNo,DepName)
Def: A relation schema R is in 2NF if and only if it is in 1NF and every non-prime attribute in R is fully
functionally dependent on key.
Example :
Consider:
Student (RollNo, Name, Dept, Gender, HostelName, RoomNo)
Assumption: Boys & girls are accommodated in separate hostels
Keys: RollNo, (HostelName, RoomNo)
SELECT clause
FROM clause
WHERE clause
GROUP BY HAVING
DBMS Languages
Data definition language (DDL)
Defines schemas
Storage definition language (SDL)
Specifies the internal schema
View definition language (VDL)
Specifies user views/mappings to conceptual schema
Data manipulation language (DML)
Allows retrieval, insertion, deletion, modification
Syntax:
Syntax:
Alter table <tablename>add(<new col><datatype(size),<new col>datatype(size));
Syntax:
Alter table <tablename> drop column <col>;
Syntax:
Alter table <tablename>modify(<col><newdatatype>(<newsize>));
Syntax:
Rename <oldtable> to <new table>;
Ex:
rename emp to emp1;
Syntax:
Truncate table <tablename>;
7. Destroying tables.
Syntax:
Drop table <tablename>;
DML commands:
1. Inserting Data into Tables: -
Once a table is created the most natural thing to do is load this table with data to be
manipulated later.
Syntax 3:
insert into <tablename> values(<val 1>,<val 2>.......,<val n>);
Ex 1:
Insert into skc(sname,rollno,class,dob,fee_paid)values(sri,104B,cse,27-feb-05,10000.00);
Ex 3:
insert into skc values(sri,104B,cse,27-feb-05,10000.00);
2. Delete operations.
Syntax:
Syntax:
delete from <tablename> where <condition>;
Syntax:
Update <tablename> set <col>=<exp>,<col>=<exp>;
Syntax:
Update <tablename> set <col>=<exp>,<col>=<exp> where <condition>;
Syntax:
<col><datatype>(size)not null
b) unique constraint
Syntax:
Unique constraint at column level. <col><datatype>(size)unique;
Syntax: Create
table
tablename(col=format,col=format,unique(<col1>,<col2>);
Syntax:
<col><datatype>(size)primary key;
e) primary key constraint at table level.
Syntax:
Syntax:
<col><datatype>(size>) references <tablename>[<col>];
h) check constraint
Syntax:
<col><datatype>(size) check(<logical expression>)
Syntax:
check(<logical expression>)
DCL commands:
Oracle provides extensive feature in order to safeguard information stored in its tables from unauthoraised
viewing and damage. The rights that allow the user of some or all oracle resources on the server are
called privileges.
Syntax:
GRANT <object privileges> ON <objectname> TO<username> [WITH GRANT OPTION];
Syntax:
REVOKE<object privilege>
ON
FROM<user name>;
METHOD 2:
Insert into Student252 values(104,sri,,cse,27-feb-05,70); 1
row created.
METHOD 3:
Insert into Student252(sid,sname,sbranch,dob,spercent) values(&sid,
&sname,&sbranch,&dob,&spercent); 1 row created.
METHOD 4:
Insert into Student252(sid,sname,sbranch,dob,spercent) values(&sid,
&sname,&sbranch,&dob,&spercent); 1
row created.
Operators in Database:
What is an Operator in SQL?
An operator is a reserved word or a character used primarily in an SQL statement's WHERE clause to
perform operation(s), such as comparisons and arithmetic operations.
Operators are used to specify conditions in an SQL statement and to serve as conjunctions for multiple
conditions in a statement.
Arithmetic operators
Comparison operators
Logical operators
< Checks if the value of left operand is less than the (a < b) is
value of right operand, if yes then condition true.
becomes true.
!< Checks if the value of left operand is not less than (a !< b) is
the value of right operand, if yes then condition false.
becomes true.
Operator Description
Syntax:
SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DSC
SQL aggregate functions return a single value, calculated from values in a column.
Syntax:
SELECT SUM(column_name) FROM table_name;
The COUNT(column_name) function returns the number of values (NULL values will not be
counted) of the specified column
Syntax:
Syntax:
SELECT COUNT(DISTINCT column_name) FROM table_name;
The MAX() function returns the largest value of the selected column.
Syntax:
SELECT MAX(column_name) FROM table_name;
The MIN() function returns the smallest value of the selected column.
Syntax:
SELECT MIN(column_name) FROM table_name;
Syntax:
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name ;
The HAVING clause was added to SQL because the WHERE keyword could not be used with
aggregate functions.
Syntax:
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value ;
What Is a Subquery?
select<column(s)>
from table =>Outer Query where<condn>
operator
(select<column> =>Inner Query from
table);