Introduction To Database
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.
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.
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
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:
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).
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
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.
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.
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.
o CREATE
o ALTER
o DROP
o TRUNCATE
Example:
DROP: It is used to delete both the structure and record stored in the table.
Syntax
Example
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
EXAMPLE
TRUNCATE: It is used to delete all the rows from the table and free the space containing the
table.
Example:
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);
For example:
UPDATE: This command is used to update or modify the value of a column in the table.
Syntax:
For example
Syntax:
For example:
Example
Example
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;
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;