0% found this document useful (0 votes)
6 views

Into RDBMS and Normalization

Uploaded by

patreshraddha989
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Into RDBMS and Normalization

Uploaded by

patreshraddha989
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

What is RDBMS?

RDBMS stands for Relational Database Management System. RDBMS is the basis for SQL, and
for all modern database systems like MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft
Access.

A Relational database management system (RDBMS) is a database management system (DBMS)


that is based on the relational model as introduced by E. F. Codd.

What is table?

The data in RDBMS is stored in database objects called tables. The table is a collection of related
data entries and it consists of columns and rows.

Remember, a table is the most common and simplest form of data storage in a relational database.
Following is the example of a CUSTOMERS table:

+---- ----------
+ +

| ID | NAME | AGE | ADDRESS | SALARY


+---- +----------
+ +----------- +

| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |

| 2 | Khilan | 25 | Delhi 1500.00 |

| 3 | kaushik | 23 | Kota 2000.00 |

| 4 | Chaitali | 25 | Mumbai | 6500.00 |

| 5 | Hardik | 27 | Bhopal 8500.00 |

| 6 | Komal | 22 | MP 4500.00 |

| 7 | Muffy | 24 | Indore | 10000.00 |


+---- +----------
+ +
What is field?

Every table is broken up into smaller entities called fields. The fields in the CUSTOMERS table
consist of ID, NAME, AGE, ADDRESS and SALARY.

A field is a column in a table that is designed to maintain specific information about every
record in the table.

What is record or row?

A record, also called a row of data, is each individual entry that exists in a table. For example
there are 7 records in the above CUSTOMERS table. Following is a single row of data or record
in the CUSTOMERS table:

-----------+ +

1 | Ramesh | 32 | Ahmedabad | 2000.00 |

-----------+ +

A record is a horizontal entity in a table.

What is column?

A column is a vertical entity in a table that contains all information associated with a specific
field in a table.

For example, a column in the CUSTOMERS table is ADDRESS, which represents location
description and would consist of the following:
What is NULL value?
A NULL value in a table is a value in a field that appears to be blank, which means a field with
a NULL value is a field with no value.
It is very important to understand that a NULL value is different than a zero value or a field that
contains spaces. A field with a NULL value is one that has been left blank during record creation.

SQL Constraints:

Constraints are the rules enforced on data columns on table. These are used to limit the type of
data that can go into a table. This ensures the accuracy and reliability of the data in the database.

Constraints could be column level or table level. Column level constraints are applied only to one
column whereas table level constraints are applied to the whole table.

Following are commonly used constraints available in SQL:

• NOT NULL Constraint: Ensures that a column cannot have NULL value.

• DEFAULT Constraint: Provides a default value for a column when none is specified.

• UNIQUE Constraint: Ensures that all values in a column are different.

• PRIMARY Key: Uniquely identified each rows/records in a database table.

• FOREIGN Key: Uniquely identified a rows/records in any another database table.

• CHECK Constraint: The CHECK constraint ensures that all values in a column satisfy
certain conditions.

• INDEX: Use to create and retrieve data from the database very quickly.

Q. Explain not null constraints by suitable example.


Not null constraint: It is a type of Domain integrity constraint. It is used to maintain the value
according to user specification. By default columns allows null values. When not null constraint is
assigned on a column or set of column, then it will not allow null values.
Syntax:
Create table <tablename>(column1 datatype(size),column2 datatype(size) not null);
Example:
Create table Emp (EmpId number(4),Empname varchar(20) not null);

Q. Explain Domain integrity constraint with syntax and example.


Q. Explain any four integrity constraints
1. Not Null constraint: This constraint ensures all rows in the table contain a definite
value for the column which is specified as not null. Which means a null value is not
allowed.

syntax: create table <table name>( Column_name Datatype (Size) [CONSTRAINT


constraint name] NOT NULL );
Example: To create a employee table with Null value, the query would be like
CREATE TABLE employee
( id number(5),
name char(20) CONSTRAINT nm_nn NOT NULL,
dept char(10), age number(2),
salary number(10),
location char(10)
);
OR
For Example: To create a employee table with Null value, the query would be like
CREATE TABLE employee
( id number(5),
name char(20) NOT NULL,
dept char(10),
age number(2),
salary number(10),
location char(10)
);
2) Check constraint: it defines a condition that each row must satisfy. A single
column can have multiple check constraints that reference the column in its
definition.
Syntax at table creation:
Create table <table_name>
(column_name1 datatype(size) constraint <constraint_name> check <condition or
logical expression>,
---
column_name n datatype(size)
);
Example:
create table emp( empno number(5), ename varchar2(25), salary number(7,2)
constraint emp_sal_ck check(salary > 5000), job varchar2(15) );
After table creation
Syntax:
Alter table <table_name> add constraint<constraint_name> check <condition>;
Example:
alter table emp add constraint emp_deptno_ck check(deptno>5);
3). Primary Key constraint: It is use to avoid redundant/duplicate value entry within the row of
specified column in table. It restricts null values too.
Syntax:
CREATE TABLE TABLE_NAME (COLUMN_NAME DATA_TYPE,
COLUMN_NAME DATA_TYPE CONSTRAINT CONSTRAINT_NAME PRIMARY KEY);
Example:
SQL> CREATE TABLE EMP
(ID NUMBER (5)CONSTRAINT ID_PK PRIMARY KEY,
NAME VARCHAR2 (10),
SAL NUMBER (10));
4). Unique Constraint: The UNIQUE constraint uniquely identifies each record in a database
table. The UNIQUE and PRIMARY KEY constraints both provide a guarantee for uniqueness for
a column or set of columns.
Syntax:
CREATE TABLE TABLE_NAME
(COLUMN_NAME DATA_TYPE,
COLUMN_NAME DATA_TYPE CONSTRAINT CONSTRAINT_NAME UNIQUE);
Example:
CREATE TABLE PERSONS
(P_ID NUM CONSTRAINT P_UK UNIQUE ,
FIRSTNAME VARCHAR(20),
CITY VARCHAR(20) );
5). Referential Integrity Constraint: It is a relational database concept in which multiple tables
share a relationship based on the data stored in the tables, and that relationship must remain
consistent. A value of foreign key is derived from primary key which is defined in parent table.
Syntax:
CREATE TABLE TABLE_NAME
(COLUMN_NAME DATA_TYPE,
COLUMN_NAME DATA_TYPE CONSTRAINT CONSTRAINT_NAME REFERENCES
PARENT_TABLE_NAME (PARENT_TABLE_COL_NAME ON DELETE CASCADE,
COLUMN_NAME DATA_TYPE);
Example:
CREATE TABLE DEPARTMENT (EMP_ID NUMBER(5) REFERENCES EMP(EMP_ID),
DNO NUMBER(3));

Data Integrity:
The following categories of the data integrity exist with each RDBMS:

• Entity Integrity: There are no duplicate rows in a table.


• Domain Integrity: Enforces valid entries for a given column by restricting the type, the format, or the
range of values.

• Referential integrity: Rows cannot be deleted, which are used by other records.

• User-Defined Integrity: Enforces some specific business rules that do not fall into entity, domain or
referential integrity.

Normalization
Q. Define normalization.
Q. What is meant by database normalization?
“Normalization can be defined as process of decomposition of database tables to avoid the data
redundancy.”

If a database design is not perfect, it may contain anomalies, which are like a bad dream for any
database administrator. Managing a database with anomalies is next to impossible.

• Update anomalies − If data items are scattered and are not linked to each other properly, then it could
lead to strange situations. For example, when we try to update one data item having its copies scattered
over several places, a few instances get updated properly while a few others are left with old values. Such
instances leave the database in an inconsistent state.

• Deletion anomalies − We tried to delete a record, but parts of it was left undeleted because of
unawareness, the data is also saved somewhere else.

• Insert anomalies − We tried to insert data in a record that does not exist at all.

Normalization is a method to remove all these anomalies and bring the database to a consistent
state.

Q. List advantages of Normalization.


Advantages of the normalization.
• More efficient data structure.
• Avoid redundant fields or columns.
• More flexible data structure i.e. we should be able to add new rows and data values easily
• Better understanding of data.
• Ensures that distinct tables exist when necessary.

First Normal Form


First Normal Form is defined in the definition of relations (tables) itself. This rule defines that all
the attributes in a relation must have atomic domains. The values in an atomic domain are indivisible
units.

We re-arrange the relation (table) as below, to convert it to First Normal Form.

Each attribute must contain only a single value from its pre-defined domain.

Second Normal Form


Before we learn about the second normal form, we need to understand the following −

• Prime attribute − An attribute, which is a part of the prime-key, is known as a prime attribute.

• Non-prime attribute − An attribute, which is not a part of the prime-key, is said to be a non-prime
attribute.

If we follow second normal form, then every non-prime attribute should be fully functionally
dependent on prime key attribute. That is, if X → A holds, then there should not be any proper subset
Y of X, for which Y → A also holds true.

We see here in Student_Project relation that the prime key attributes are Stu_ID and Proj_ID.
According to the rule, non-key attributes, i.e. Stu_Name and Proj_Name must be dependent upon
both and not on any of the prime key attribute individually. But we find that Stu_Name can be
identified by Stu_ID and Proj_Name can be identified by Proj_ID independently. This is
calledpartial dependency, which is not allowed in Second Normal Form.

We broke the relation in two as depicted in the above picture. So there exists no partial
dependency.

Third Normal Form

For a relation to be in Third Normal Form, it must be in Second Normal form and the following
must satisfy −

• No non-prime attribute is transitively dependent on prime key attribute.


• For any non-trivial functional dependency, X → A, then either −
• X is a superkey

Q. Explain Third normal form.


Q. Explain 3NF with example.
3NF (Third normal form)
1) After removing all transitive dependencies and making separate relations, relations get into 3NF.
2) Transitive dependency is can be stated as, let R be relation and A, B and C be the set of
attributes then, they are transitive dependent if C depends on B, B depends on A and therefore C
depends on A.
Example
Student_Detail Table :

Student_name DOB treet city State Zip


Student_id
In this table Student_id is Primary key, but street, city and state depends upon Zip. The dependency
between zip and other fields is called transitive dependency. Hence to apply 3NF, we need to
move the street, city and state to new table, with Zip as primary key.
New Student_Detail Table :
Student_name DOB zip
Student_id

Address Table :
Zip Street City state

Boyce-Codd Normal Form

Boyce-Codd Normal Form (BCNF) is an extension of Third Normal Form on strict terms. BCNF
states that −

For any non-trivial functional dependency, X → A, X must be a super-key.

In the above image, Stu_ID is the super-key in the relation Student_Detail and Zip is the super-key
in the relation ZipCodes. So,
Stu_ID

Stu_Na

me,

Zip and

Zip → City

Which confirms that both the relations are in BCNF.

Q. State properties of Boyce Codd Normal Form.

Properties of Boyce Codd normal form


1. BCNF: A relation R is in Boyce - Codd normal form (BCNF) if and only if
every determinant is a candidate key.
2. In BCNF non-trivial functional dependency is preserved for super key.
3. A table can be in 3NF but not in BCNF.
4. 3NF does not deal satisfactorily with the case of a relation with overlapping
candidates keys, in such case BCNF can be used.
5. The violation of BCNF means that the table is subject to anomalies.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy