DATABASE CONCEPT-NOTES

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

What is Data?

In simple words, data can be facts related to any object in consideration. For example, your
name, age, height, weight, etc. are some data related to you. A picture, image, file, pdf, etc.
can also be considered data.

What is Database?
A database is a systematic collection of data. They support electronic storage and
manipulation of data. Databases make data management easy.

Let us discuss a database example: An online telephone directory uses a database to store
data of people, phone numbers, and other contact details. Your electricity service provider
uses a database to manage billing, client-related issues, handle fault data, etc.

Let us also consider Facebook. It needs to store, manipulate, and present data related to
members, their friends, member activities, messages, advertisements, and a lot more. We can
provide a countless number of examples for the usage of databases.

Types of Databases
Here are some popular types of databases.

Distributed databases:

A distributed database is a type of database that has contributions from the common database
and information captured by local computers. In this type of database system, the data is not
in one place and is distributed at various organizations.

Relational databases:

This type of database defines database relationships in the form of tables. It is also called
Relational DBMS, which is the most popular DBMS type in the market. Database example of
the RDBMS system include MySQL, Oracle, and Microsoft SQL Server database.

Object-oriented databases:

This type of computers database supports the storage of all data types. The data is stored in
the form of objects. The objects to be held in the database have attributes and methods that
define what to do with the data. PostgreSQL is an example of an object-oriented relational
DBMS.

Centralized database:
It is a centralized location, and users from different backgrounds can access this data. This
type of computers databases store application procedures that help users access the data even
from a remote location.

Open-source databases:

This kind of database stored information related to operations. It is mainly used in the field of
marketing, employee relations, customer service, of databases.

Cloud databases:

A cloud database is a database which is optimized or built for such a virtualized environment.
There are so many advantages of a cloud database, some of which can pay for storage
capacity and bandwidth. It also offers scalability on-demand, along with high availability.

Data warehouses:

Data Warehouse is to facilitate a single version of truth for a company for decision making
and forecasting. A Data warehouse is an information system that contains historical and
commutative data from single or multiple sources. Data Warehouse concept simplifies the
reporting and analysis process of the organization.

NoSQL databases:

NoSQL database is used for large sets of distributed data. There are a few big data
performance problems that are effectively handled by relational databases. This type of
computers database is very efficient in analyzing large-size unstructured data.

Graph databases:

A graph-oriented database uses graph theory to store, map, and query relationships. These
kinds of computers databases are mostly used for analyzing interconnections. For example,
an organization can use a graph database to mine data about customers from social media.

OLTP databases:

OLTP another database type which able to perform fast query processing and maintaining
data integrity in multi-access environments.

Personal database:

A personal database is used to store data stored on personal computers that are smaller and
easily manageable. The data is mostly used by the same department of the company and is
accessed by a small group of people.

Multimodal database:
The multimodal database is a type of data processing platform that supports multiple data
models that define how the certain knowledge and information in a database should be
organized and arranged.

Document/JSON database:

In a document-oriented database, the data is kept in document collections, usually using the
XML, JSON, BSON formats. One record can store as much data as you want, in any data
type (or types) you prefer.

Hierarchical:

This type of DBMS employs the “parent-child” relationship of storing data. Its structure is
like a tree with nodes representing records and branches representing fields. The windows
registry used in Windows XP is a hierarchical database example.

Network DBMS:

This type of DBMS supports many-to-many relations. It usually results in complex database
structures. RDM Server is an example of database management system that implements the
network model.

Database Components

Database Components

There are five main components of a database:

Hardware:
The hardware consists of physical, electronic devices like computers, I/O devices, storage
devices, etc. This offers the interface between computers and real-world systems.

Software:

This is a set of programs used to manage and control the overall database. This includes the
database software itself, the Operating System, the network software used to share the data
among users, and the application programs for accessing data in the database.

Data:

Data is a raw and unorganized fact that is required to be processed to make it meaningful.
Data can be simple at the same time unorganized unless it is organized. Generally, data
comprises facts, observations, perceptions, numbers, characters, symbols, images, etc.

Procedure:

Procedure are a set of instructions and rules that help you to use the DBMS. It is designing
and running the database using documented methods, which allows you to guide the users
who operate and manage it.

Database Access Language:

Database Access language is used to access the data to and from the database, enter new data,
update already existing data, or retrieve required data from DBMS. The user writes some
specific commands in a database access language and submits these to the database.

What is a Database Management System (DBMS)?


Database Management System (DBMS) is a collection of programs that enable its users to
access databases, manipulate data, report, and represent data. It also helps to control access to
the database. Database Management Systems are not a new concept and, as such, had been
first implemented in the 1960s.

Charles Bachman’s Integrated Data Store (IDS) is said to be the first DBMS in history. With
time database, technologies evolved a lot, while usage and expected functionalities of
databases increased immensely.

Advantages of DBMS
• DBMS offers a variety of techniques to store & retrieve data.
• DBMS serves as an efficient handler to balance the needs of multiple applications
using the same data.
• Uniform administration procedures for data.
• Application programmers never exposed to details of data representation and storage.
• A DBMS uses various powerful functions to store and retrieve data efficiently.
• Offers Data Integrity and Security.
• The DBMS implies integrity constraints to get a high level of protection against
prohibited access to data.
• A DBMS schedules concurrent access to the data in such a manner that only one user
can access the same data at a time.
• Reduced Application Development Time.

Disadvantage of DBMS
DBMS may offer plenty of advantages but, it has certain flaws-

• Cost of Hardware and Software of a DBMS is quite high which increases the budget
of your organization.
• Most database management systems are often complex systems, so the training for
users to use the DBMS is required.
• In some organizations, all data is integrated into a single database which can be
damaged because of electric failure or database is corrupted on the storage media.
• Use of the same program at a time by many users sometimes lead to the loss of some
data.
• DBMS can’t perform sophisticated calculations.

Difference between RDBMS and DBMS


Database Management System (DBMS) is a software that is used to define, create and
maintain a database and provides controlled access to the data.

Relational Database Management System (RDBMS) is an advanced version of a DBMS.

DBMS RDBMS

DBMS stores data as file. RDBMS stores data in tabular form.

Multiple data elements can be accessed at the same


Data elements need to access individually.
time.

Data is stored in the form of tables which are related


No relationship between data.
to each other.

Normalization is not present. Normalization is present.

DBMS does not support distributed


RDBMS supports distributed database.
database.

It uses a tabular structure where the headers are the


It stores data in either a navigational or
column names, and the rows contain corresponding
hierarchical form.
values.

It deals with small quantity of data. It deals with large amount of data.
DBMS RDBMS

Data redundancy is common in this model. Keys and indexes do not allow Data redundancy.

It is used for small organization and deal


It is used to handle large amount of data.
with small data.

It supports single user. It supports multiple users.

Data fetching is slower for the large amount


Data fetching is fast because of relational approach.
of data.

The data in a DBMS is subject to low


There exists multiple levels of data security in a
security levels with regards to data
RDBMS.
manipulation.

Low software and hardware necessities. Higher software and hardware necessities.

Examples: MySQL, PostgreSQL, SQL Server, Oracle,


Examples: XML, Window Registry, etc.
Microsoft Access etc.

What is SQL?
SQL was initially developed at IBM by Donald D. Chamberlin and Raymond F. Boyce after
learning about the relational model from Edgar F. Codd in the early 1970s.

It is used in programming and managing data held in relational database management


systems such as MySql, MS SQL Server, oracle Sybase, etc as a medium (instructions) for
accessing and interacting with data.

It enables performing several operations such as creating, deleting, modifying, and fetching
entries in the database and some other advanced statistical, arithmetic, and mathematical
operations. Let us try understanding the basics of SQL now.

What is SQL Used For?


This database language is mainly designed for maintaining the data in relational database
management systems. It is a special tool used by data professionals for handling structured
data (data that is stored in the form of tables).

It is also designed for stream processing in RDBMS. You can easily create and manipulate
the database, access and modify the table rows and columns, etc. It is used in relational
database management systems such as MySql, MS SQL Server, Oracle Sybase, etc as a
medium (instructions) for accessing and interacting with data.

Types of SQL Commands


In this article on SQL basics, we study about following types of commands:
• DDL(Data Definition Language): To make/perform changes to the physical
structure of any table residing inside a database, DDL is used. These commands when
executed are auto-commit in nature and all the changes in the table are reflected and
saved immediately.
• DML(Data Manipulation Language): Once the tables are created and the database
is generated using DDL commands, manipulation inside those tables and databases is
done using DML commands. The advantage of using DML commands is, that if in
case any wrong changes or values are made, they can be changed and rolled back
easily.

Data Definition Language


In SQL DDL commands are used to create and modify the structure of a database and
database objects. These commands are CREATE, DROP, ALTER, TRUNCATE, and
RENAME. Let us discuss these commands one at a time.

CREATE

The syntax for create command is:

For creating a database:

CREATE DATABASE database_name;

Creates a database named 'database_name'. Let us create our own database and table which
we will use as a reference throughout this article:

CREATE DATABASE testdb;

For creating a table:

CREATE TABLE table_name(


column1 datatype,
column2 datatype,
.....
columnN datatype
);

This creates a new table with the name 'table_name' in our database. It will have N columns
for each of the same datatypes as mentioned adjacent to it in the create syntax.

For instance:

CREATE TABLE my_table(


first_name varchar(20),
age INT
);

This creates an empty table. For clarity suppose we add an entry (row) in the column (as in
the image) the result will be:
first_name age
myFirstName 20

DROP

To drop a table:

DROP TABLE table_name;

deletes the table named 'table_name' if present.

Suppose if we drop our my_table, the result is as:

drop table my_table;

Output:

Query OK, 0 rows affected (0.01 sec)

To drop a database:

DROP DATABASE database_name;

This removes the database named 'database_name' if present. Suppose we try this with our
database, the result looks like this:

drop database testdb;

Output:

Query OK, 0 rows affected (0.01 sec)

ALTER

Following is the syntax to alter the contents of a table:

ALTER TABLE table_name


ADD column_name column_definition;

Let's try performing this operation on our table my_table:

alter table my_table


add column employed boolean;

Output:

| first_name | age |
|:-----------:|:---:|
| myFirstName | 20 |
In the above example, we are adding a column to our table. Apart from that, we can perform
other operations such as dropping a column, modifying it, etc.

To change the properties of a column such as its type, type capacity, add constraints, etc:

ALTER TABLE table_name


ALTER COLUMN column_name column_type;

Lets try using it in our database:

alter my_table modify column


first_name varchar(25);

Output:

Query OK, 0 rows affected (0.01 sec)

We changed the column first_name from data type varchar(20) to varchar(25).

Similarly, we can drop a column using alter with the following syntax:

ALTER TABLE table_name


DROP COLUMN column_name;

We can remove our column 'employed' as:

alter table my_table


drop column employed;

Output:

Query OK, 0 rows affected (0.01 sec)

TRUNCATE

This command is similar to the drop table command. The only difference is that while the
drop command removes the table as well as its contents, the truncate command only erases
the contents of the table's contents and not the table itself. Let us take an example to be
clearer:

truncate table my_table;


select * from my_table;

Output:

Query OK, 0 rows affected (0.01 sec)


Empty set (0.00 sec)

As shown in the image above, truncate has removed the contents of the table. The table,
though now empty, still exists. Think of truncating a table as emptying it rather than deleting
it.
RENAME

This command is used to change the name of an existing table. The syntax is

RENAME TABLE table_name TO table_name_new;

The following image shows how to rename our table from 'my_table' to 'some_table':

rename table my_table to some_table;

Output:

Query OK, 0 rows affected (0.01 sec)

Data Manipulation Language


DML is used for inserting, deleting, and updating data in a database. It is used to retrieve and
manipulate data in a relational database. It includes INSERT, UPDATE, and DELETE. Let's
discuss these commands one at a time.

INSERT

Insert statement is used to insert data in a SQL table. Using the Insert query, we can add one
or more rows to the table. Following is the syntax of the MySQL INSERT Statement.

INSERT INTO table_name


(attribute1, attribute2, ...)
VALUES(val1, val2, ...)

Let's take a quick instance for understanding this better. Suppose that we need to insert 2
rows {"myName3", 2, true} and {"myName4", 28, false}. This is how we would accomplish
that:

insert into my_table


values("myName3", 5, false),
("myName4", 51, true);

Output:

Query OK, 2 rows affected (0.01 sec)

We don't necessarily have to include all column values. We can for example omit the age
column as shown below:

insert into my_table


(first_name, employed)
values("myName4", true);

Output:

Query OK, 1 rows affected (0.01 sec)


This is also a fine example of how we insert just one row.

UPDATE

This command is used to make changes to the data in the table. Its syntax is:

UPDATE table_name
SET column1 = val1,
column2 = val2,
...
WHERE CLAUSE;

How about we update the employment status of myName of age 12 which has it as NULL?
This is how we achieve it:

update my_table
set employed=true
where age=12;

Output:

Query OK, 1 rows affected (0.01 sec)

Let's batch-update all our rows without filtering them on any condition. Suppose we want to
increment the value of every row in the age column. The following query is what we need:

update my_table
set age = age + 1;

Output:

Query OK, 5 rows affected (0.01 sec)

DELETE

This command is used to remove a row from a table. the syntax for delete is

DELETE FROM table_name


WHERE CLAUSE;

The where clause is optional. To delete the row with first_name "myName5 run this query:

delete from my_table


where first_name = "myName5";

Output:

Query OK, 0 rows affected (0.01 sec)

It is to be noted that omitting the use where clause results in the emptying of the table just as
truncating does.

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