Showing posts with label DBMS. Show all posts
Showing posts with label DBMS. Show all posts

SQL Tutorial : Database Design

Leave a Comment

The organization of data in a relational database in the form of tables.
Eg: Student (Name, Address, Subject, Grade)

Problems associated with this scheme are -

Redundancy
The student address is repeated for each subject.

Update anomaly
As a consequence of redundancy updating address in one tuple while leaving it unchanged in another.

Insertion anomaly
It is not possible to record address of a student unless he has registered for at least one subject.

Deletion Anomaly
This is inverse of insertion anomaly if a student drops all the subjects in which he is registered it looses students address.


Integrity Constraints

The integrity constraint is a relational database system it is broadly classified as

Integrity constraint on admissible domain values of a tuple
These constraints restrict the admissible values of the attributes of the relation to some range and are called domain dependencies.

Integrity constraint based on Inter – tuple relationship
The data dependency do not depend on the values of any given component of a tuple, but on whether the projection of two or more tuples on a subset of the attributes of the relation satisfy some relational constraints.

Types of dependencies

  • Equality generating dependencies
  • Tuple generating dependencies
  • Functional dependency
  • Multivalued dependency


Normal forms

Normalization is the process for assigning attributes to entities, which reduce data redundancies and eliminate data anomalies that result from those redundancies.

Normalization works through a series of stages called Normal forms.

1st Normal form
Given a relation R, attribute A of R is functionally dependent on attributes B of R if and only if each A value in R has associated with its precisely one B – value in R.
Parts = (part no, part name, part size, QTY – No- Hand)
Parts. part no -> parts. part name
Parts. part no -> parts. part size
Parts. part No -> parts. QTY –ON – Hand

A relation is said to be in first normal form if every attribute is functionally dependent on key.

2nd Normal form
To be in second normal form it must be in first normal form and attributes of the table must be dependent only on one part of concatenated primary key.
No key attribute is fully dependent on primary key.
Eg: ORDER (ORD – NO, ITEM – Name, QTY, Price)

Item price is not dependent on ORD – NO, it is dependent only on item – name and QTY is dependent on both parts of key.
Item (Item name, price)

3rd Normal form

Transitive dependent
If attributes a depend on B and B depends on C due to which A depends on C then A is said to be transitive dependent on C.

-> Transitive dependency causes problems in updation

Normal forms
Test
Remedy
1st N.F.
Relation should have a no non – atomic attributes or nested relations
Form new relation for each non – atomic attribute or nested relation
2nd N.F.
For relations where primary key contains multiple attributes, no non – key attributes should be functionally dependent on a part of the primary keys.
Decompose and set up a new relation for each particle key with its dependent attributes. Make sure to keep a relation with the original primary key and any attributes that are fully functional dependent on it
3rd N.F.
Relation should not have a non key attributes functionally determined by non – key attributes. i.e there should be no  transitive dependency on a non key attribute of primary key.
Decompose and set up a relation that includes the non – key attributes that functionally determine other non key attributes.


Read More...

RDBMS Questions and Answers

Leave a Comment

What is database?

A database is a logically coherent collection of data with some inherent meaning, representing some aspect of real world and which is designed, built and populated with data for a specific purpose.

What is DBMS?

It is a collection of programs that enables user to create and maintain a database. In other words it is general-purpose software that provides the users with the processes of defining, constructing and manipulating the database for various applications.

What is a Database system?

The database and DBMS software together is called as Database system.

Advantages of DBMS?

  1. Redundancy is controlled.
  2. Unauthorised access is restricted.
  3. Providing multiple user interfaces.
  4. Enforcing integrity constraints.
  5. Providing backup and recovery.

Disadvantage in File Processing System?

  1. Data redundancy & inconsistency.
  2. Difficult in accessing data.
  3. Data isolation.
  4. Data integrity.
  5. Concurrent access is not possible.
  6. Security Problems.

Describe the three levels of data abstraction?

There are three levels of abstraction:
  1. Physical level: The lowest level of abstraction describes how data are stored.
  2. Logical level: The next higher level of abstraction, describes what data are stored in database and what relationship among those data.
  3. View level: The highest level of abstraction describes only part of entire database.

Define the "integrity rules"

There are two Integrity rules.
  1. Entity Integrity: States that “Primary key cannot have NULL value”
  2. Referential Integrity: States that “Foreign Key can be either a NULL value or should be Primary Key value of other relation.

What is extension and intension?

Extension -
It is the number of tuples present in a table at any instance. This is time dependent.
Intension -
It is a constant value that gives the name, structure of table and the constraints laid on it.

What is System R? What are its two major subsystems?

System R was designed and developed over a period of 1974-79 at IBM San Jose Research Center. It is a prototype and its purpose was to demonstrate that it is possible to build a Relational System that can be used in a real life environment to solve real life problems, with performance at least comparable to that of existing system.

Its two subsystems are
  1. Research Storage
  2. System Relational Data System.

How is the data structure of System R different from the relational structure?

Unlike Relational systems in System R
  1. Domains are not supported
  2. Enforcement of candidate key uniqueness is optional
  3. Enforcement of entity integrity is optional
  4. Referential integrity is not enforced

What is Data Independence?

Data independence means that “the application is independent of the storage structure and access strategy of data”. In other words, The ability to modify the schema definition in one level should not affect the schema definition in the next higher level.

Two types of Data Independence:
a) Physical Data Independence: Modification in physical level should not affect the logical level.
b) Logical Data Independence: Modification in logical level should affect the view level.
NOTE: Logical Data Independence is more difficult to achieve

What is a view? How it is related to data independence?

A view may be thought of as a virtual table, that is, a table that does not really exist in its own right but is instead derived from one or more underlying base table. In other words, there is no stored file that direct represents the view instead a definition of view is stored in data dictionary. 

Growth and restructuring of base tables is not reflected in views. Thus the view can insulate users from the effects of restructuring and growth in the database. Hence accounts for logical data independence.

What is Data Model?

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

What is E-R model?

This data model is based on real world that consists of basic objects called entities and of relationship among these objects. Entities are described in a database by a set of attributes.

What is Object Oriented model?

This model is based on collection of objects. An object contains values stored in instance variables with in the object. An object also contains bodies of code that operate on the object. These bodies of code are called methods. Objects that contain same types of values and the same methods are grouped together into classes.

What is an Entity?

It is a thing in the real world with an independent existence.

What is an Entity type?

It is a collection (set) of entities that have same attributes.

What is an Entity set?

It is a collection of all entities of particular entity type in the database.

What is an Extension of entity type?

The collections of entities of a particular entity type are grouped together into an entity set.

What is Weak Entity set?

An entity set may not have sufficient attributes to form a primary key, and its primary key compromises of its partial key and primary key of its parent entity, then it is said to be Weak Entity set.

What is an attribute?

It is a particular property, which describes the entity.

What is a Relation Schema and a Relation?

A relation Schema denoted by R(A1, A2, …, An) is made up of the relation name R and the list of attributes Ai that it contains. A relation is defined as a set of tuples. Let r be the relation which contains set tuples (t1, t2, t3, ..., tn). Each tuple is an ordered list of n-values t=(v1,v2, ..., vn).

What is degree of a Relation?

It is the number of attribute of its relation schema.

What is Relationship?

It is an association among two or more entities.

What is Relationship set?

The collection (or set) of similar relationships.

What is Relationship type?

Relationship type defines a set of associations or a relationship set among a given set of entity types.

What is degree of Relationship type?

It is the number of entity type participating.

What is DDL (Data Definition Language)?

A data base schema is specifies by a set of definitions expressed by a special language called DDL.

What is VDL (View Definition Language)?

It specifies user views and their mappings to the conceptual schema.

What is SDL (Storage Definition Language)?

This language is to specify the internal schema. This language may specify the mapping between two schemas.

What is Data Storage - Definition Language?

The storage structures and access methods used by database system are specified by a set of definition in a special type of DDL called data storage-definition language.

What is DML (Data Manipulation Language)?

This language that enable user to access or manipulate data as organised by appropriate data model.
  1. Procedural DML or Low level: DML requires a user to specify what data are needed and how to get those data.
  2. Non-Procedural DML or High level: DML requires a user to specify what data are needed without specifying how to get those data.

Read More...

Relational Database Management System [DBMS]

Leave a Comment

The arrangement of data in the form of records and fields is called a database

Database Management System: The DBMS is the management of databases in the form of a package.

Features:
  1. Creating Tables
  2. Entering database records
  3. Sorting
  4. Deleting
  5. Updating
  6. Merging Database files
  7. Copying
  8. Printing
  9. Validating
  10. Converting
  11. Generating Reports

Relational Database Model

Arranging of data in a logical way in the form of table of showing relationship between different fields.

Terms used in RDBMS
  1. Entity:- Is a person, place, event or thing
  2. Attributes:- Characteristic of an entity is known as attribute
  3. Relation:- It shows relation between any two entities
  4. Tuple:- Row of a relation
  5. Domain:- Values of attributes or column
  6. Degree:- Relationship degree indicate number of associated entities.

Types of relationships
  1. Urnary
  2. Binary
  3. Ternary

Relational Algebra

It define theoretical way of manipulating table contents using the eight relational functions.
  1. SELECT
  2. PROJECT
  3. JOIN
  4. INTERSECTION
  5. UNION
  6. DIFFERENCE
  7. PRODUCT
  8. DIVIDE

  • UNION: Combine all rows from two tables
  • Intersection: Produce a listing that contain only rows that appear in both tables.
  • Difference: Yields all rows in one table that are not found in other table
  • Cartesian product: Produces a list of all possible pair of rows from two tables
  • Select: Yields values for all attributes found in a table
  • Project: Produces list of all values for selected attributes
  • Join: Allows to combine information from two or more tables
  • Divide: Divide the table into separate tables based on its columns

E – R Diagrams

The overall logical structure of a database can be expressed graphically by an E–R diagram.

E–R diagram consist of following components

E-R diagram of part of project- management system
E-R diagram of part of project- management system

Cardinality: 
The number mentioned on the relation shows types of relationship
  1. one–one
  2. one–many
  3. many–one
  4. many–many

Key

Common attributes that enable us to link tables, such attributes are called keys.

Types of Keys:

  1. Super key: An attribute that uniquely identifies each entity in a table.
  2. Candidate key: A minimal super key that does not contain a subset of attributes that is itself a super key.
  3. Primary key: A candidate key selected to uniquely identify all other attribute values in any given row cannot contain null entries.
  4. Secondary key: An attribute used strictly for data retrieval purpose
  5. Foreign key: An attribute in one table whose values must either match the primary key in another table to be null.

Tuple Calculus

It is a special case of language of the semantical system consider semantic system in following form ∑i.

∑i = < Ri U C, {Φ, R, S,-------}, Φ, R, S,------- >

where, Ri = the set of real numbers.
           C = set of character strings of finite length
           { Φ, R, S,-------} = set of relational symbols.

Atomic wff of ∑i

  1. R(t) is an atomic wff of ∑i if R is a relation symbol and t is a R – string whose components are in Ri U C
  2. Φ u [i] v [j] this is written as u [i] Φ v [j] is an atomic wff of i provided that u and v are both R – strings or one is a R – string and other is a S – string where R and S are two relation symbols of ∑i

Quasi – wff
Ψ is a quasi quantifier ∑i if

  1. Ψ is an atomic wff of ∑i or
  2. Any expression of Ψ obtained from Ψ by substituting constants of ∑i for the placeholders used in Ψ, is an atomic wff of  ∑i .
  3. (Ψ1 V Ψ2) is a quasi wff if Ψ1  and Ψ2 are Quasi – wff and no place holder I in both free in Ψ1 and bound in Ψ2 or vice versa.
A wff is a quasi w f f in which no place holder is free.

Safe Expressions
A tuple calculus expressions {t/ Ψ(t)} is said to be a safe expression provided following conditions hold good

  1. All components of each t that makes y true are in DOM (Ψ).
  2. If there is a quasi – wff of the form (for all s) (W(s)) in Ψ then all the components of that u which make W (with possible values of other free variables in w).
  3. If Ψ has within itself a quasi – wff of the form (for all s) (W(s)) then the components of all Ss irrespective of the fact that whether w is satisfied by these or not must be DOM(Ψ).

Read More...