Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Computer Science Notes

Database Concepts
Database

Database is a collection of related information that is organized in such a way that supports for easy
access, modification, and maintenance data.

Database Management System

A database management system (DBMS) or database system is a software that can be used to create
and manage databases. DBMS lets users to create a database, store, manage, update/modify and
retrieve data from that database by users or application programs.

Some examples of DBMS include MySQL, Oracle, PostgreSQL, SQL Server, Microsoft Access, MongoDB.

Features of a good DBMS

Provides ease of access to data: The DBMS serves as an interface between the database and end users
or application programs. Retrieving data from a database through special type of commands is called
querying the database. In addition, users can modify the structure of the database itself through a DBMS

Reduces data redundancy: Redundancy means same data are duplicated in different places.
Redundancy leads to excess storage use and may cause data inconsistency also. A good database
reduces redundancy.

Reduces data inconsistency: Data inconsistency occurs when same data maintained in different places
do not match. A good database has features to avoid inconsistency.

Facilitates controlled data sharing: A database system hides certain details about how data are actually
stored and maintained. Thus, it provides users with an abstract view of the data. A database system has
a set of programs through which users or other programs can access, modify, and retrieve the stored
data. Data in a database can also be shared between various applications.

Relational data model

In the relational data model, database is represented as collection of related tables. Each table is termed
as relation and has its unique name in the relational data model. Tables are formed by using rows and
columns. A row (horizontal subset) of a table represents a tuple or record, while column (vertical subset)
of a table represents an attribute.

Terms related to Relational data model

Relation: In a relational database, a relation means a 'table', in which data are organized in the form of
rows and columns. Therefore, in database, relations are equivalent to tables.

Attribute: It is a vertical subset of a relation. Simply stated, the columns of a relation are the attributes
which are also referred as fields.
Tuple: Each row of data in a relation (table) is called a tuple. It is a horizontal subset of a relation.

Domain: It is a set of values from which an attribute can take a value in each row.

Degree: The number of attributes in a relation is called the Degree of the relation.

Cardinality: The number of tuples in a relation is called the Cardinality of the relation.

For example

Relation: Student

AdNo Name Sex Class Section Average


101 Anu F 12 A 85
105 Balu M 12 D 65
203 Leena F 11 B 95
205 Madhu F 10 B 75
305 Surpreeth M 9 C 70
483 Usha F 6 A 60

The relation Student has six attributes viz., Adno, Name, Sex, Class, Section, Average.

So, its degree is 6

It has six tuples, each holding information about one distinct student.

So, its cardinality is 6

The domain of the Sex attribute is (M, F)

Three Important Properties of a Relation

Property 1: imposes following rules on an attribute of the relation.

• Each attribute in a relation has a unique name.

• Sequence of attributes in a relation is immaterial.

Property 2: governs following rules on a tuple of a relation.

• Each tuple in a relation is distinct.

• Sequence of tuples in a relation is immaterial. The tuples are not considered to be ordered, even
though they appear to be in tabular form.

Property 3: imposes following rules on the state of a relation.

• All data values in an attribute must be from the same domain ( or same data type).
• Each data value associated with an attribute must be atomic (cannot be further divisible into
meaningful subparts).

• No attribute can have many data values in one tuple.

• A special value “NULL” is used to represent values that are unknown or non-applicable to certain
attributes.

Keys in a Relational Database

Relational data model imposes some restrictions or constraints on the values of the attributes and how
the contents of one relation be referred through another relation. These restrictions are specified at the
time of defining the database through different types of keys

Primary Key: An attribute or set of attributes that uniquely identifies a tuple within a relation is called
primary key.

Composite Primary Key: If no single attribute in a relation is able to uniquely distinguish the tuples,
then more than one attributes are taken together as primary key. Such a primary key consisting of more
than one attribute is called Composite Primary key.

Candidate Key: Candidate keys are set of attributes in the relation that are eligible to act as a primary
key.

Alternate Key: Out of the candidate keys, after selecting a key as primary key, the remaining keys are
called alternate key.

Foreign Key: A foreign key is an attribute whose value is derived from the primary key of another
relation. A foreign key is used to represent the relationship between two relations.

The table this attribute is the primary key is called the master relation (or master table), and the table
where it is the foreign key is called the foreign relation (or detail table)

You might also like