Introduction to RDBMS
Database Management System
is a software package where you maintain and control the information to run the business and to do the day to day operations in an organized and user friendly method. In the DBMS we can back up the data, implement the security so that certain information can be modified or viewed by certain people working in the organization. In this section we learn the main concepts which we must follow while working in DBMS.
In simple words, a Database Management System is a Software program which makes the task easier, the task being adding, deleting, modifying and maintain the information. Here are some database terms and concepts.
Database Concepts- Data
- Databases
- Entity, Attribute and Data
- Entity Relationships
- Data Models
Data Data is information about some thing. Data gets differed from business to business,FOR EXAMPLE:- For a bus transportation company BUS, DRIVERS, CITY, SEATS OCCUPIED are data, for a computer hardware company MONITOR, CPU, HARD DISK are data.
Databases Database is an area where you save the data needed to run the business. Database provides the following features like Sharing Data,enforcing Business rules,Data security which can be applied centrally
Entity, Attribute and Data An Entity is an object which has some attributes, FOR EXAMPLE:- A employee in an organization has a name and a particular Job.Here EMPLOYEE is an ENTITY, NAME and JOB are ATTRIBUTES. Entity - EMPLOYEE Attribute - EMP_NAME and JOB Data - Name of Employee like (Mike Modano) , his Job is like (Marketing).
Entity Relationships Database contains many Entities (Tables), we can relate an entity to another,FOR EXAMPLE:- In an organization we have many departments and many employees working , here we have two entities one is EMPLOYEE and the other is DEPARTMENT. So how do we relate these two entities?We can RELATE these two entities as:- In one department there can be many employees.
The relationship between two different entities can be classified as:
- ONE to ONE example PERSON - PASSPORT (one individual can have only one passport)
- ONE to MANY example DEPARTMENT - EMPLOYEE (In one department there can be many employees working)
- MANY to MANY example DOCTOR - PATIENT (A doctor can have many patients and a patient can have many doctors)
Concepts of RDBMS
To understand the basic concepts of RDBMS,the following information is provided to you.
Table is the place where you can save all your data in the relational model(RDBMS). Data is organized in terms of Rows and columns in a table. For Example, see the information we have here in employee table.
EMPLOYEE TABLE
| EMPNO | ENAME | DEPTNO | DNAME | LOC | SAL | COMM |
|---|---|---|---|---|---|---|
| 7000 | KING | 10 | MARKETING | DALLAS | 5000.00 | 300.00 |
| 7001 | ALEX | 20 | DEVELOPMENT | NY | 3500 | 100 |
| 7002 | CHRIS | 10 | MARKETING | DALLAS | 4000 | 100 |
| 7003 | STEVE | 20 | DEVELOPMANT | NY | 4000 | 200 |
| 7004 | KELLY | 30 | HUMAN RESOURCES | LA | 2000 | 50 |
| 7005 | JONES | 30 | HUMAN RESOURCES | LA | 1700 | 40 |
In the above example,we have 6 employee records. 2 employees for each department.Take a look at it and see how many times we have the same information ie duplicate information. The departments are occuring twice and so more memory space is occupied. To calculate this,
| DNAME | BYTES |
|---|---|
| MARKETING | 9 BYTES |
| DEVELOPMENT | 10 BYTES |
| HUMAN RESOURCES | 9 BYTES |
| DALLAS | 6 BYTES |
| NY | 2 BYTES |
| LA | 2 BYTES |
| TOTAL | 28 BYTES |
For 6 records we wasted 26 bytes, Imagine having 5000 employees working in the company! Then we are wasting 28 * 5000 bytes = 140000bytes,which is around 13 MB of memory.
Advantages of the new system(Relational model)
- If you split the above shown data into two different tables then it becomes easy to maintain the data
For example:- If a particular department moved from Dallas to Atlanta,we need to change the city table for deptno 10 in the new system where as in the previous system we have to update all the employee records whose department is deptno 10. - removes the duplicate information (Data Redundancy) instead of duplicating the Department name and Location for every employee record as seen in the previous system,You can see Department name and Location only once in the Department table based on the common column in the new system
- Reduces the Memory space in the database
Employee Table
| EMPNO | ENAME | DEPTNO | SAL | COMM |
|---|---|---|---|---|
| 7000 | KING | 10 | 5000.00 | 300.00 |
| 7001 | ALEX | 20 | 3500 | 100 |
| 7002 | CHRIS | 10 | 4000 | 100 |
| 7003 | STEVE | 20 | 4000 | 200 |
| 7004 | KELLY | 30 | 2000 | 50 |
| 7005 | JONES | 30 | 1700 | 40 |
Department Table
| DEPTNO | DNAME | LOC |
|---|---|---|
| 10 | MARKETING | DALLAS |
| 20 | DEVELOPMENT | NY |
| 10 | MARKETING | DALLAS |
| 20 | DEVELOPMANT | NY |
| 30 | HUMAN RESOURCES | LA |
| 30 | HUMAN RESOURCES | LA |
We have the same information now as before but the difference is we have two tables instead of one table. To relate the two tables, we need a common column between the tables. In the above example, there is a common column (DEPTNO).
Codd's rules
Codd's Rules
| RULE | DESCRIPTION |
|---|---|
| Representation of information | All data must be represented logically in tables |
| Guaranteed logical accessibility | All data is accessible logically using a combination of table name, key name, key value and column. |
| NULL support | Null value represents missing information and are not to be confused with empty, blank or zero filled data. They also are not necessarily equal. |
| Dynamic online catalog | The definition of data is represented in the same manner as data so that it can be relationally accessed. Example every database has catalog tables |
| Comprehensive data sub-language (high level language example SQL ) | A unique language which is supported along with several other programming languages to achieve data definition, view and manipulation. |
| Updatable views | All views that can theoretically exists can be updated. |
| High level insert, updates and delete | Both base and derived relations can be handled as singular requests and apply to retrieval, insert, update and deletion of data. |
| Physical data independence | Program and terminal activities are preserved when changes are made in storage representation or access methods. |
| Logical data independence | Program and terminal activities are preserved when changes are made to base tables. |
| Integrity independence | Integrity constraints must be definable in the unique sub-language and stored in the catalog. |
| Distribution independence | The unique sub-language must support database distribution while preserving program and terminal activities. |
| Nonsubersion | A relational system which perform low-level processing of records cannot supplant the integrity rules in effect in high level, record processing by a relational language. |
| Relational Table database | Defined as a rectangular array of columns and rows where columns are homogenous, non-grouped, uniquely named data items( attributes ) and rows are not duplicated. It is also important to impose the property that column and row order within the array is immaterial. |
Primary keys
Constraints
When you bind a business rule to a column in the table then those rules are called the Constraints. Constraints are defined while creating the table. Say for example, you cannot have an employee who does not have a name, then employee name column in employee table should be a NOT NULL column. The NOT NULL is a constraint.
The following table shows the constraint types and short descriptions.
Constraints
| CONSTRAINTTYPE | DESCRIPTION |
|---|---|
| NOT NULL | you must provide the value in that column. you cannot leave that column blank |
| PRIMARY KEY | No duplicate values allowed, for example Empno in Employee table should be unique |
| CHECK | checks the value and controls the inserting and updating values. |
| DEFAULT | Assigns a default value if no value is given. |
| REFERENCES | To maintain the referential integrity (Foreign Key) |
NOT NULL
If we have a business rule saying that all customers should have a name, we cannot have any customer with out a name. So to implement that business rule we can create customer table and specify customer name column as NOT NULL (constraint)
Example
#-- Install Oracle on your machine
CREATE TABLE employee (empno NUMBER(4) PRIMARY KEY, ename VARCHAR(4) NOT NULL);
CHECK
Check constraint is used where we define a condition on a column. Check constraint consists of the keyword
col_name datatype CHECK (col_name in(value1, value2))
Example If you have a business rule saying that all employees in the organization should get atleast $500 then we can use CHECK constraint while creating table.
#-- Install Oracle on your machine
CREATE TABLE employee ( empno NUMBER(4) PRIMARY KEY, ename VARCHAR(4) NOT NULL,
salary NUMBER(7,2) CHECK (salary > 500) );
DEFAULT
While inserting a row into a table without giving values for every column, SQL must insert a default value to fill in the excluded columns, or the command will be rejected. The most common default value is NULL. This can be used with columns not defined with a NOT NULL.
Default value assigned to a column while creating the table using CREATE TABLE operation.
Example
#-- Install Oracle on your machine
CREATE TABLE item (item_id NUMBER(4) PRIMARY KEY, item_name VARCHAR(15),
item_desc VARCHAR(100), qoh NUMBER(4) DEFAULT 100)
Assigning a default value 0 for numeric columns makes the computation.
PRIMARY KEY
Primary Key in a table is a unique identifier of a row. For example,if you are maintaning the customer profiles, you should assign particular number to each one. So customer_number should be defined as a Primary key in Customer table.
REFERENCES
is a Foreign key. A foreign key column value refers a column in another table to check whether the value exists or not.
UNIQUE
The values entered into a column are unique ie no duplicate values exists.This constraint ensures business that there is no duplicates allowed.
Referential integrity
Normalization
SQL
Hierarchial Database Management System
Based on the concept of hierarchy, entities and relationships are modelled in the form of a Tree.
ORGANIZATION -----> DEPARTMENTS -------> EMPLOYEES
This type of model can represent ONE to ONE and ONE to MANY relationships naturally, but not MANY to MANY relationships.
Network Database Management System
This model is an Extension of Hierarchial Model. Here,
- Child can be related to more than one parent.
- Subordinate entities can be associated with superior entities.
- Cannot model MANY to MANY
- Complex Navigational Paths to get the information.
- Relationships are physical Pointers.
Introduction
RDBMS Concepts
For every programmer who is getting into the IT world, its important to understand the business and the data which gets generated and reused in the business.
Business, now a days generate lots of information through the activities they perform in daily operations. Technology group should gather and store the data / information in a right way. IT programmers should know how to get the data from the databases in an easier and optimized way.
More than 75% of business data gets stored in the Relational database managemet systems. So, its imperative for resources to understand the concepts of RDBMS. No matter what RDBMS you are going to use, the concepts are same across the board.
We follow a unique methodology to teach our students. While explaining a simple concept or a complex concept, we depend on the scenarios. We explain the scenario first, then we go ahead and solve the problem with a concept what we teach. As you get exposure to more business scenarios, you will be able to relate to things better in the actual implementation.
About Insturctor:
Rajesh Kumar V.S, is the course creator. He has a rich experience in Databases, Data Modeling and implementing data warehousing projects. His expertise is to understand the business and model the information in a right way for easy and faster access. He is well versed with different RDBMS in the industry.