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

Important terms

DATA: Representation of facts, concepts, Instructions

Field: To represent a specific data element

Record: collection of fields

Information: Processed data

Redundancy: Repetition of data

Data Semantics.

CIA

DBMS:

Is a collection of Interrelated data and a set of procedures to access that data.

Advantages of DBMS

 Control of data redundancy


 Data consistency
 More information from same amount of data
 Sharing of data
 Search capabilities
 Improved data integrity
 Privacy and security
 Economy of scale
 Improved backup and recovery
 Standards can be maintained(formats)

Instance, Schema and Database state.

 The collection of information stored in database at a particular instant of time is called an


instance of database.
 The data in the database at a particular time is called as database state
 Database Schema
A database schema is the skeleton structure that represents the logical view of the
entire database. It defines how the data is organized and how the relations among
them are associated.

DBMS 3- Tier Architecture

It has Three Levels

1. External Schema (User View)


2. Conceptual Schema (What data is stored and the relation among that data)
3. Internal Schema (How data is stored in the database)
Mapping Constraints:

1. One to One Relationship


2. One to many Functions
3. Many to One Relationship
4. Many to many relationship

MCQ

1. The DBMS acts as an interface between what two components of an enterprise-class


database system?
A
Database application and the database
.
B.Data and the database
C.The user and the database application
D
Database application and SQL
.

The following are components of a database except ________ .


A
user data
.
B.metadata
C.reports
D
indexes
.

An application where only one user accesses the database at a given time is an example of
a(n) ________ .
A
single-user database application
.
B.multiuser database application
C.e-commerce database application
D data mining database application
.

An on-line commercial site such as Amazon.com is an example of a(n) ________ .


A
single-user database application
.
B.multiuser database application
C.e-commerce database application
D
data mining database application
.

SQL stands for ________ .


A
Structured Query Language
.
B.Sequential Query Language
C.Structured Question Language
D
Sequential Question Language
.

The following are functions of a DBMS except ________ .


A
creating and processing forms
.
B.creating databases
C.processing data
D
administrating databases
.
a

Helping people keep track of things is the purpose of a(n) ________ .


A
database
.
B.table
C.instance
D
Relationship
.

a
Data Independence:

The ability to modify a schema definition in one level without affecting a schema definition in the
next higher level is called a s data independence.

Physical Data independence:

(Changes in physical schema without causing app. Programs to be rewritten.)

Logical Data Independence:

Changes to conceptual schema, such a addition of entry or deletion of new entries should be
possible without affecting existing external schema.

Data Models:
• Underlying the structure of a database is the Data Model:

A collection of conceptual tools for describing data, data relationships and consistency
constraints.

• A data model provides a way to describe the design of a database at the physical, logical and
view level.

The data models can be classified in 4 different categories:

1. Relational Model

2. The Entity-Relationship Model

3. Object-Based Data Model

4. Semi-structured Data Model

Entity
An entity can be a real-world object, either animate or inanimate, that can be easily
identifiable. For example, in a school database, students, teachers, classes, and courses
offered can be considered as entities. All these entities have some attributes or properties that
give them their identity.

Attributes
Entities are represented by means of their properties, called attributes. All attributes have
values. For example, a student entity may have name, class, and age as attributes.

Types of Attributes

 Simple attribute − Simple attributes are atomic values, which cannot be divided
further. For example, a student's phone number is an atomic value of 10 digits.
 Composite attribute − Composite attributes are made of more than one simple
attribute. For example, a student's complete name may have first_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. For another example, age can be derived from
data_of_birth.
 Single-value attribute − Single-value attributes contain single value. For example −
Social_Security_Number.
 Multi-value attribute − Multi-value attributes may contain more than one values.
For example, a person can have more than one phone number, email_address, etc.

Relationship
The association among entities is called a relationship. For example, an employee works_at a
department, a student enrolls in a course. Here, Works_at and Enrolls are called
relationships.

Entity
Entities are represented by means of rectangles. Rectangles are named with the entity set they
represent.

Imp terms

1. Composite
2. Multivalued (double eclipse)
3. Derived (dotted eclipse)
4. Dependent Entity
5. Weak Entity

Generalization
Specialization
ER Diagrams

EXAMPLES

Driver drives a car


Student in a College:

Students in a Class:
Consumer and Supplier

People/Employee in a company:
Cardinality Ratio:

Number of relationship instances in which the entity can participate is defined as Cardinality
Ratio. The possible cardinality ratios are as follows. For the explanation let us consider, there
are two entity sets A and B. :

1.  One to one Relationship (1:1) : An entity in A can have relationship with atmost one


entity in B and vice versa. For example, a principal can manage one school and a
school can be managed by just one principal.
2.  One to Many Relationship (1:M) :   An entity in A can have relationship with zero or
more entities in B while an entity of B can have relationship with only one entity of
A. For example, A batch can have more than one student while a student can be
present in only one batch. 
3. Many to One Relationship (M:M) : An entity in A can have relationship with any no
of entities in B and vice versa. For example, An employee can work on more than one
projects and a project can be handles by more than one employee.  

Degree:

The degree of relationship (also known as cardinality) is the number of occurrences in one
entity which are associated (or linked) to the number of occurrences in another.

There are three degrees of relationship, known as:

1. one-to-one (1:1)
2. one-to-many (1:M)
3. many-to-many (M:N)
One-to-one (1:1)
This is where one occurrence of an entity relates to only one occurrence in another entity.

A one-to-one relationship rarely exists in practice, but it can. However, you may consider
combining them into one entity.

For example, an employee is allocated a company car, which can only be driven by that
employee.

Therefore, there is a one-to-one relationship between employee and company car.

One-to-Many (1:M)
Is where one occurrence in an entity relates to many occurrences in another entity.

For example, taking the employee and department entities shown on the previous page, an
employee works in one department but a department has many employees.

Therefore, there is a one-to-many relationship between department and employee.


Many-to-Many (M:N)
This is where many occurrences in an entity relate to many occurrences in another entity.

The normalisation process discussed earlier would prevent any such relationships but the
definition is included here for completeness.

As with one-to-one relationships, many-to-many relationships rarely exist. Normally they


occur because an entity has been missed.

For example, an employee may work on several projects at the same time and a project has a
team of many employees.

Therefore, there is a many-to-many relationship between employee and project.

SQL Components: DDL and DML commands

What are database Sub languages?


A data sublanguage mainly has two parts:

 Data Definition Language (DDL) and


 Data Manipulation Language (DML).

Data Definition Language


Data Definition Language (DDL) statements are used to classify the database structure or
schema. It is a type of language that allows the DBA or user to depict and name those
entities, attributes, and relationships that are required for the application along with any
associated integrity and security constraints. Here are the lists of tasks that come under DDL:

 CREATE - used to create objects in the database


 ALTER - used to alters the structure of the database
 DROP - used to delete objects from the database
 TRUNCATE - used to remove all records from a table, including all spaces allocated
for the records are removed
 COMMENT - used to add comments to the data dictionary
 RENAME - used to rename an object

Data Manipulation Language


A language that offers a set of operations to support the fundamental data manipulation
operations on the data held in the database. Data Manipulation Language (DML) statements
are used to manage data within schema objects. Here are the lists of tasks that come under
DML:

 SELECT - It retrieves data from a database


 INSERT - It inserts data into a table
 UPDATE - It updates existing data within a table
 DELETE - It deletes all records from a table, the space for the records remain
 MERGE - UPSERT operation (insert or update)
 CALL - It calls a PL/SQL or Java subprogram
 EXPLAIN PLAN - It explains access path to data
 LOCK TABLE - It controls concurrency

Data Control Language


There are another two forms of database sub-languages. The Data Control Language (DCL)
is used to control privilege in Database. To perform any operation in the database, such as for
creating tables, sequences or views we need privileges. Privileges are of two types,

 System - creating a session, table, etc. are all types of system privilege.
 Object - any command or query to work on tables comes under object privilege. DCL
is used to define two commands. These are:
 Grant - It gives user access privileges to a database.
 Revoke - It takes back permissions from the user.
Transaction Control Language (TCL)
Transaction Control statements are used to run the changes made by DML statements. It
allows statements to be grouped into logical transactions.

 COMMIT - It saves the work done


 SAVEPOINT - It identifies a point in a transaction to which you can later roll back
 ROLLBACK - It restores the database to original since the last COMMIT
 SET TRANSACTION - It changes the transaction options like isolation level and
what rollback segment to use

Types of key:
2. Candidate key

In the EMPLOYEE table, id is best suited for the primary key. Rest of the attributes like
SSN, Passport_Number, and License_Number, etc. are considered as a candidate key.
. Super Key

Super key is a set of an attribute which can uniquely identify a tuple. Super key is a superset
of a candidate key.

For example: In the above EMPLOYEE table, for(EMPLOEE_ID, EMPLOYEE_NAME)


the name of two employees can be the same, but their EMPLYEE_ID can't be the same.
Hence, this combination can also be a key.

The super key would be EMPLOYEE-ID, (EMPLOYEE_ID, EMPLOYEE-NAME), etc.

4. Foreign key

 Foreign keys are the column of the table which is used to point to the primary key of another
table.

Various Keys in Database Management System (DBMS)


1. Super key
2. Candidate key
3. Primary key
4. Composite key
5. Secondary or Alternative key
6. Prime attribute
7. Non- prime attribute
Types of Integrity Constraint

. Domain constraints

 Domain constraints can be defined as the definition of a valid set of values for an attribute.
 The data type of domain includes string, character, integer, time, date, currency, etc. The
value of the attribute must be available in the corresponding domain.
Example:

2. Entity integrity constraints

 The entity integrity constraint states that primary key value can't be null.
 This is because the primary key value is used to identify individual rows in relation and if the
primary key has a null value, then we can't identify those rows.
 A table can contain a null value other than the primary key field.

Example:

3. Referential Integrity Constraints

 A referential integrity constraint is specified between two tables.


 In the Referential integrity constraints, if a foreign key in Table 1 refers to the Primary Key of
Table 2, then every value of the Foreign Key in Table 1 must be null or be available in Table
2.

Example:
4. Key constraints

 Keys are the entity set that is used to identify an entity within its entity set uniquely.
 An entity set can have multiple keys, but out of which one key will be the primary key. A
primary key can contain a unique and null value in the relational table.

Example:

TYPES OF INTEGRITY CONSTRAINTS


Various types of integrity constraints are-

1. Domain Integrity
2. Entity Integrity Constraint
3. Referential Integrity Constraint
4. Key Constraints
1. Domain Integrity-

Domain integrity means the definition of a valid set of values for an attribute. You define
data type, length or size, is null value allowed , is the value unique or not for an attribute ,the
default value, the range (values in between) and/or specific values for the attribute.

2. Entity Integrity Constraint-

This rule states that in any database relation value of attribute of a primary key can't be null.

EXAMPLE- Consider a relation "STUDENT" Where "Stu_id" is a primary key and it must
not contain any null value whereas other attributes may contain null value e.g "Branch" in the
following relation contains one null value.

3.Referential Integrity Constraint-

It states that if a foreign key exists in a relation then either the foreign key value must match a
primary key value of some tuple in its home relation or the foreign key value must be null.

The rules are:

1. You can't delete a record from a primary table if matching records exist in a related
table.
2. You can't change a primary key value in the primary table if that record has related
records.
3. You can't enter a value in the foreign key field of the related table that doesn't exist in
the primary key of the primary table.
4. However, you can enter a Null value in the foreign key, specifying that the records are
unrelated.

EXAMPLE-

Consider 2 relations "stu" and "stu_1" Where "Stu_id " is the primary key in the "stu" relation
and foreign key in the "stu_1" relation.

Relation "stu"

Stu_id Name Branch


11255234 Aman CSE
11255369 Kapil EcE
11255324 Ajay ME
11255237 Raman CSE
11255678 Aastha ECE
Relation "stu_1"

Stu_id Duration
11255234 B TECH 4 years
11255369 B TECH 4 years
11255324 B TECH 4 years
11255237 B TECH 4 years
11255678 B TECH 4 years

4.Key Constraints-

A Key Constraint is a statement that a certain minimal subset of the fields of a relation is a
unique identifier for a tuple.

You might also like