0% found this document useful (0 votes)
20 views10 pages

Introduction To Database

The document provides an introduction to databases and database management systems. It describes what a database is, the components and purpose of a database management system, and some advantages and disadvantages of using a DBMS. It also discusses entity relationship diagrams and their components as well as an introduction to the structured query language SQL.

Uploaded by

ajithkumarasan2
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)
20 views10 pages

Introduction To Database

The document provides an introduction to databases and database management systems. It describes what a database is, the components and purpose of a database management system, and some advantages and disadvantages of using a DBMS. It also discusses entity relationship diagrams and their components as well as an introduction to the structured query language SQL.

Uploaded by

ajithkumarasan2
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/ 10

INTRODUCTION TO DATABASE

Database
A database is an organized collection of structured information, or data, typically
stored electronically in a computer system. A database is usually controlled by a
database management system (DBMS). The data can then be easily accessed, managed,
modified, updated, controlled, and organized.

A database-management system (DBMS)


A database-management system (DBMS) is a collection of interrelated data and a set of
programs to access those data. This is a collection of related data with an implicit meaning
and hence is a database. The collection of data, usually referred to as the database,
contains information relevant to an enterprise. The primary goal of a DBMS is to provide a
way to store and retrieve database information that is both convenient and efficient. By data,
we mean known facts that can be recorded and that have implicit meaning.

A Database management system is a computerized record-keeping system. It is a repository


or a container for collection of computerized data files. The overall purpose of DBMS is to
allow he users to define, store, retrieve and update the information contained in the
database on demand. Information can be anything that is of significance to an individual or
organization.

Databases touch all aspects of our lives. Some of the major areas of application are as
follows: 1. Banking 2. Airlines 3. Universities 4. Manufacturing and selling 5. Human
resources

Advantages of DBMS:
Controlling of Redundancy:

Data redundancy refers to the duplication of data (i.e storing same data multiple times). In a
database system, by having a centralized database and centralized control of data by the
DBA the unnecessary duplication of data is avoided. It also eliminates the extra time for
processing the large volume of data. It results in saving the storage space.

Improved Data Sharing : DBMS allows a user to share the data in any number of
application programs.

Data Integrity : Integrity means that the data in the database is accurate. Centralized
control of the data helps in permitting the administrator to define integrity constraints to the
data in the database. For example: in customer database we can can enforce an integrity
that it must accept the customer only from Noida and Meerut city.

Security : Having complete authority over the operational data, enables the DBA in
ensuring that the only mean of access to the database is through proper channels. The DBA
can define authorization checks to be carried out whenever access to sensitive data is
attempted.
Data Consistency : By eliminating data redundancy, we greatly reduce the opportunities
for inconsistency. For example: is a customer address is stored only once, we cannot have
disagreement on the stored values. Also updating data values is greatly simplified when
each value is stored in one place only. Finally, we avoid the wasted storage that results from
redundant data storage.

Efficient Data Access : In a database system, the data is managed by the DBMS and all
access to the data is through the DBMS providing a key to effective data processing

Enforcements of Standards : With the centralized of data, DBA can establish and
enforce the data standards which may include the naming conventions, data quality
standards etc.

Data Independence : Ina database system, the database management system provides
the interface between the application programs and the data. When changes are made to
the data representation, the meta data obtained by the DBMS is changed but the DBMS is
continues to provide the data to application program in the previously used way. The DBMs
handles the task of transformation of data wherever necessary.

Reduced Application Development and Maintenance Time : DBMS supports many


important functions that are common to many applications, accessing data stored in the
DBMS, which facilitates the quick development of application.

Disadvantages of DBMS

1) It is bit complex. Since it supports multiple functionality to give the user the best, the
underlying software has become complex. The designers and developers should have
thorough knowledge about the software to get the most out of it.

2) Because of its complexity and functionality, it uses large amount of memory. It also needs
large memory to run efficiently.

3) DBMS system works on the centralized system, i.e.; all the users from all over the world
access this database. Hence any failure of the DBMS, will impact all the users.

4) DBMS is generalized software, i.e.; it is written work on the entire systems rather specific
one. Hence some of the application will run slow.

Entity Relationship Diagram


An ER diagram shows the relationship among entity sets. An entity set is a group of similar
entities and these entities can have attributes. In terms of DBMS, an entity is a table or
attribute of a table in database, so by showing relationship among tables and their attributes,
ER diagram shows the complete logical structure of a database.
ER diagram has three main components:
1. Entity
2. Attribute
3. Relationship

Entity

An entity is an object or component of data. An entity is represented as rectangle in an ER


diagram.
Weak Entity:
An entity that cannot be uniquely identified by its own attributes and relies on the relationship
with other entity is called weak entity. The weak entity is represented by a double rectangle.

Attribute
An attribute describes the property of an entity. An attribute is represented as Oval in an ER
diagram. There are four types of attributes:

1. Key attribute
2. Composite attribute
3. Multivalued attribute
4. Derived attribute

Key attribute:

A key attribute can uniquely identify an entity from an entity set. For example, student roll
number can uniquely identify a student from a set of students. Key attribute is represented
by oval same as other attributes however the text of key attribute is underlined.

Composite attribute:

An attribute that is a combination of other attributes is known as composite attribute. For


example, In student entity, the student address is a composite attribute as an address is
composed of other attributes such as pin code, state, country.
Multivalued attribute:
An attribute that can hold multiple values is known as multivalued attribute. It is represented
with double ovals in an ER Diagram. For example – A person can have more than one
phone numbers so the phone number attribute is multivalued.

Derived attribute:

A derived attribute is one whose value is dynamic and derived from another attribute. It is
represented by dashed oval in an ER Diagram. For example – Person age is a derived
attribute as it changes over time and can be derived from another attribute (Date of birth).

ENTITY-SET AND KEYS

Key is an attribute or collection of attributes that uniquely identifies an entity among entity
set. For example, the roll_number of a student makes him/her identifiable among students.

Super Key: A set of attributes (one or more) that collectively identifies an entity in an entity
set

Candidate Key: A minimal super key is called a candidate key. An entity set may have more
than one candidate key.

Primary Key: A primary key is one of the candidate keys chosen by the database designer to
uniquely identify the entity set.

Relationship
A relationship is represented by diamond shape in ER diagram, it shows the relationship
among entities. There are four types of relationships:
1. One to One
2. One to Many
3. Many to One
4. Many to Many

One to One Relationship


When a single instance of an entity is associated with a single instance of another entity then
it is called one to one relationship. For example, a person has only one passport and a
passport is given to one person.

One to Many Relationship

When a single instance of an entity is associated with more than one instances of another
entity then it is called one to many relationship. For example – a customer can place many
orders but a order cannot be placed by many customers.

Many to One Relationship

When more than one instances of an entity is associated with a single instance of another
entity then it is called many to one relationship. For example – many students can study in a
single college but a student cannot study in many colleges at the same time.

Many to Many Relationship

When more than one instances of an entity is associated with more than one instances of
another entity then it is called many to many relationship. For example, a can be assigned to
many projects and a project can be assigned to many students.

Introduction to SQL

SQL stands for Structured Query Language. It is used for storing and managing data in
relational database management system (RDMS).It is a standard language for Relational
Database System. It enables a user to create, read, update and delete relational databases
and tables Structure query language is not case sensitive. Generally, keywords of SQL are
written in uppercase.

Types of SQL Commands


There are five types of SQL commands: DDL, DML, DCL, TCL, and DQL.
Data Definition Language (DDL)
DDL changes the structure of the table like creating a table, deleting a table, altering a table,
etc. All the command of DDL are auto-committed that means it permanently save all the
changes in the database.
Here are some commands that come under DDL:

o CREATE
o ALTER
o DROP
o TRUNCATE

CREATE It is used to create a new table in the database.

Syntax:CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,....]);

Example:

CREATE TABLE EMPLOYEE(Name VARCHAR2(20), Email VARCHAR2(100), DOB DATE);

DROP: It is used to delete both the structure and record stored in the table.

Syntax

DROP TABLE table_name;

Example

DROP TABLE EMPLOYEE;

ALTER: It is used to alter the structure of the database. This change could be either to
modify the characteristics of an existing attribute or probably to add a new attribute.

Syntax:
To add a new column in the table

ALTER TABLE table_name ADD column_name COLUMN-definition;

To modify existing column in the table:

ALTER TABLE table_name MODIFY(column_definitions....);

EXAMPLE

ALTER TABLE STU_DETAILS ADD(ADDRESS VARCHAR2(20));


ALTER TABLE STU_DETAILS MODIFY (NAME VARCHAR2(20));

TRUNCATE: It is used to delete all the rows from the table and free the space containing the
table.

Syntax: TRUNCATE TABLE table_name;

Example:

TRUNCATE TABLE EMPLOYEE;

Data Manipulation Language


DML commands are used to modify the database. It is responsible for all form of changes in
the database. The command of DML is not auto-committed that means it can't permanently
save all the changes in the database. They can be rollback.

o INSERT
o UPDATE
o DELETE

INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of a
table.

Syntax:

1. INSERT INTO TABLE_NAME (col1, col2, col3,.... col N) VALUES (value1, value2, va
lue3, .... valueN);

2. INSERT INTO TABLE_NAME VALUES (value1, value2, value3, .... valueN);

For example:

INSERT INTO text (Author, Subject) VALUES (‘sonu’, ‘english’);

UPDATE: This command is used to update or modify the value of a column in the table.
Syntax:

UPDATE table_name SET [column_name1= value1,...column_nameN = valueN] [W


HERE CONDITION]

For example

UPDATE students SET User_Name = 'Sonoo' WHERE Student_Id = '3'

DELETE: It is used to remove one or more row from a table.

Syntax:

DELETE FROM table_name [WHERE condition];

For example:

DELETE FROM text WHERE Author=’sonu’;

Data Control Language


DCL commands are used to grant and take back authority from any database user.Here are
some commands that come under DCL:
o Grant
o Revoke

Grant: It is used to give user access privileges to a database.

Example

GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTHER_USER;

Revoke: It is used to take back permissions from the user.

Example

REVOKE SELECT, UPDATE ON MY_TABLE FROM USER1, USER2;

Transaction Control Language


TCL commands can only use with DML commands like INSERT, DELETE and UPDATE
only. These operations are automatically committed in the database that's why they cannot
be used while creating tables or dropping them.

Here are some commands that come under TCL:


o COMMIT
o ROLLBACK
o SAVEPOINT

Commit: Commit command is used to save all the transactions to the database.

Syntax:

COMMIT;

Example:
DELETE FROM CUSTOMERS WHERE AGE = 25;
COMMIT;

Rollback: Rollback command is used to undo transactions that have not already been
saved to the database.

Syntax:

ROLLBACK;

Example:
DELETE FROM CUSTOMERS WHERE AGE = 25;
ROLLBACK;

SAVEPOINT: It is used to roll the transaction back to a certain point without rolling back the
entire transaction.

Syntax:

SAVEPOINT SAVEPOINT_NAME;

Data Query Language


DQL is used to fetch the data from the database. It uses only one command:
o SELECT

SELECT: This is the same as the projection operation of relational algebra. It is used to
select the attribute based on the condition described by WHERE clause.

Syntax:
SELECT * FROM TABLE;
Or
SELECT expressions FROM TABLES WHERE conditions;

For example: SELECT emp_name FROM employee WHERE age > 20;

You might also like