0% found this document useful (0 votes)
56 views44 pages

DBMS Essentials for IT Professionals

1. A DBMS provides advantages like controlling redundancy by storing data in a single database, allowing data sharing among authorized users, easy maintenance due to centralization, reduced development and maintenance time, automatic backups and recovery, and multiple user interfaces. 2. A DBMS architecture typically uses a client-server model with clients connecting to a database server via an application server in a 3-tier architecture. This prevents direct client access to the database and increases security and scalability. 3. The main characteristics of a DBMS are that it can store any kind of data, provides protection and security, maintains consistency with multiple users, and performs operations like creating databases and tables, storing, updating, and retrieving data.

Uploaded by

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

DBMS Essentials for IT Professionals

1. A DBMS provides advantages like controlling redundancy by storing data in a single database, allowing data sharing among authorized users, easy maintenance due to centralization, reduced development and maintenance time, automatic backups and recovery, and multiple user interfaces. 2. A DBMS architecture typically uses a client-server model with clients connecting to a database server via an application server in a 3-tier architecture. This prevents direct client access to the database and increases security and scalability. 3. The main characteristics of a DBMS are that it can store any kind of data, provides protection and security, maintains consistency with multiple users, and performs operations like creating databases and tables, storing, updating, and retrieving data.

Uploaded by

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

1.

Advantages of DBMS

o Controls database redundancy: It can control data redundancy because it stores all the data in one
single database file and that recorded data is placed in the database.
o Data sharing: In DBMS, the authorized users of an organization can share the data among multiple
users.
o Easily Maintenance: It can be easily maintainable due to the centralized nature of the database system.
o Reduce time: It reduces development time and maintenance need.

o Backup: It provides backup and recovery subsystems which create automatic backup of data
from hardware and software failures and restores the data if required.
o multiple user interface: It provides different types of user interfaces like graphical user interfaces,
application program interfaces

2. Strong Entity:
A strong entity is not dependent on any other entity in the schema. A strong entity will always have a primary
key. Strong entities are represented by a single rectangle. The relationship of two strong entities is
represented by a single diamond.
Various strong entities, when combined together, create a strong entity set.
Weak Entity:
A weak entity is dependent on a strong entity to ensure its existence. Unlike a strong entity, a weak entity
does not have any primary key. It instead has a partial discriminator key. A weak entity is represented by a
double rectangle.
The relation between one strong and one weak entity is represented by a double diamond. This relationship is
also known as identifying relationship.

3. Entity Relationship Diagram (ERD) Symbols and Notations. There are three basic elements in an ER
Diagram: entity, attribute, relationship. There are more elements which are based on the main elements.
They are weak entity, multi valued attribute, derived attribute, weak relationship, and recursive relationship.
4. Needs of Normalization : Normalization is a technique for organizing data in a database. It is important
that a database is normalized to minimize redundancy (duplicate data) and to ensure only related data is
stored in each table. It also prevents any issues stemming from database modifications such as insertions,
deletions, and updates.Normalization helps to reduce redundancy and complexity by examining new
data types used in the table. It is helpful to divide the large database table into smaller tables and link them
using relationship. It avoids duplicate data or no repeating groups into a table.

5. Lock: A lock is a data variable which is associated with a data item. This lock signifies that
operations that can be performed on the data item. Locks in DBMS help synchronize access to the database
items by concurrent transactions. All lock requests are made to the concurrency-control manager.there is
one lock for each data item in the database.

6. Database Management System

o Database management system is a software which is used to manage the database. For
example: MySQL, Oracle, etc are a very popular commercial database which is used in different
applications.
o DBMS provides an interface to perform various operations like database creation, storing data in it,
updating data, creating a table in the database and a lot more.

o It provides protection and security to the database. In the case of multiple users, it also maintains data
consistency.

7. Data Manipulation Language Commends:

DML stands for Data Manipulation Language. It is used for accessing and manipulating data in a database. It
handles user requests.

Here are some tasks that come under DML:

o Select: It is used to retrieve data from a database.


o Insert: It is used to insert data into a table.

o Update: It is used to update existing data within a table.


o Delete: It is used to delete all records from a table.

o Merge: It performs UPSERT operation, i.e., insert or update operations.


o Call: It is used to call a structured query language or a Java subprogram.

o Explain Plan: It has the parameter of explaining data.

o Lock Table: It controls concurrency.

8. Aggregate functions: Aggregate functions in DBMS take multiple rows from the table and return a value
according to the query.

All the aggregate functions are used in Select

statement. Syntax −

SELECT <FUNCTION NAME> (<PARAMETER>) FROM <TABLE NAME>

AVG Function

Select AVG(salary) from Employee

COUNT Function

The count function returns the number of rows in the result. It does not count the null values.

Select COUNT(*) from Employee where Salary > 20000; Types

 COUNT(*): Counts all the number of rows of the table including null.

 COUNT( COLUMN_NAME): count number of non-null values in column.

 COUNT( DISTINCT COLUMN_NAME): count number of distinct values in a column.

MAX Function

The MAX function is used to find maximum value in the column that is supplied as a parameter. It can be used
on any type of data.

Select MAX(salary) from Employee

SUM Function
This function sums up the values in the column supplied as a parameter.

Select SUM(salary) from Employee

9. Normal Form in Normalization:

Normalization is the process of organizing the data in the database.

o Normalization is used to minimize the redundancy from a relation or set of relations. It is also used to
eliminate the undesirable characteristics like Insertion, Update and Deletion Anomalies.

o Normalization divides the larger table into the smaller table and links them using relationship.
o The normal form is used to reduce redundancy from the database table.

The normal form is used to reduce redundancy from the database.

Normal Description
Form

1NF A relation is in 1NF if it contains an atomic value.

2NF A relation will be in 2NF if it is in 1NF and all non-key attributes are fully functional
dependent on the primary key.

3NF A relation will be in 3NF if it is in 2NF and no transition dependency exists.

4NF A relation will be in 4NF if it is in Boyce Codd normal form and has no multi-valued
dependency.

5NF A relation is in 5NF if it is in 4NF and not contains any join dependency and joining
should be lossless.

10. Database recovery : Database recovery is the process of restoring the database to a correct
(consistent) state in the event of a failure. In other words, it is the process of restoring the database to the
most recent consistent state that existed shortly before the time of system failure.
There are four different recovery techniques are available in the Database.
 Mirroring.
 Recovery using Backups.
 Recovery using Transaction Logs.
 Shadow Paging.

1. DBMS Architecture
o The DBMS design depends upon its architecture. The basic client/server architecture is used to deal with
a large number of PCs, web servers, database servers and other components that are connected with
networks.

o The client/server architecture consists of many PCs and a workstation which are connected via the
network.

o DBMS architecture depends upon how users are connected to the database to get their request done.

Types of DBMS Architecture

1- Tier Architecture

o In this architecture, the database is directly available to the user. It means the user can directly sit on the
DBMS and uses it.
o Any changes done here will directly be done on the database itself. It doesn't provide a handy tool for
end users.
o The 1-Tier architecture is used for development of the local application, where programmers can
directly communicate with the database for the quick response.

2- Tier Architecture

o The 2-Tier architecture is same as basic client-server. In the two-tier architecture, applications on the
client end can directly communicate with the database at the server side. For this interaction, API's
like: ODBC, JDBC are used.
o The user interfaces and application programs are run on the client-side.
o The server side is responsible to provide the functionalities like: query processing and transaction
management.

o To communicate with the DBMS, client-side application establishes a connection with the server side.

3- Tier Architecture

o The 3-Tier architecture contains another layer between the client and server. In this architecture, client
can't directly communicate with the server.
o The application on the client-end interacts with an application server which further communicates with
the database system.
o End user has no idea about the existence of the database beyond the application server. The database
also has no idea about any other user beyond the application.

o The 3-Tier architecture is used in case of large web application.


2. Advantages/ Characteristics of DBMS

o Controls database redundancy: It can control data redundancy because it stores all the data in one
single database file and that recorded data is placed in the database.

o Data sharing: In DBMS, the authorized users of an organization can share the data among multiple
users.

o Easily Maintenance: It can be easily maintainable due to the centralized nature of the database system.

o Reduce time: It reduces development time and maintenance need.


o Backup: It provides backup and recovery subsystems which create automatic backup of data
from hardware and software failures and restores the data if required.

o multiple user interface: It provides different types of user interfaces like graphical user interfaces,
application program interfaces.

o A database management system is able to store any kind of data in a database.

o The database management system has to support ACID (atomicity, consistency, isolation, durability)
properties.

o The Database management system allows so many users to access databases at the same time.

o Backup and recovery are the two main methods which allow users to protect the data from damage or
loss.

o It also provides multiple views for different users in a single organization.

o It follows the concept of normalization which is helpful to minimize the redundancy of a relation.
o It also provides users query language, helpful to insert, retrieve, update, and delete the data in a
database.

3. ER model
o ER model stands for an Entity-Relationship model. It is a high-level data model. This model is used to
define the data elements and relationship for a specified system.

o It develops a conceptual design for the database. It also develops a very simple and easy to design view
of data.

o In ER modeling, the database structure is portrayed as a diagram called an entity-relationship diagram.

For example, suppose we design a school database. In this database, the student will be an entity with attributes
like address, name, id, age, etc. The address can be another entity with attributes like city, street name, pin code,
etc and there will be a relationship between them.

Component of ER Diagram
1. Entity:

An entity may be any object, class, person or place. In the ER diagram, an entity can be represented as
rectangles.

Consider an organization as an example- manager, product, employee, department etc. can be taken as an entity.

a. Weak Entity

An entity that depends on another entity called a weak entity. The weak entity doesn't contain any key attribute
of its own. The weak entity is represented by a double rectangle.
2. Attribute

The attribute is used to describe the property of an entity. Eclipse is used to represent an attribute.

For example, id, age, contact number, name, etc. can be attributes of a student.

b. Composite Attribute

An attribute that composed of many other attributes is known as a composite attribute. The composite attribute
is represented by an ellipse, and those ellipses are connected with an ellipse.

c. Multivalued Attribute

An attribute can have more than one value. These attributes are known as a multivalued attribute. The double
oval is used to represent multivalued attribute.

For example, a student can have more than one phone number.
d. Derived Attribute

An attribute that can be derived from other attribute is known as a derived attribute. It can be represented by a
dashed ellipse.

For example, A person's age changes over time and can be derived from another attribute like Date of birth.

3. Relationship

A relationship is used to describe the relation between entities. Diamond or rhombus is used to represent the
relationship.

Types of relationship are as follows:


a. One-to-One Relationship

When only one instance of an entity is associated with the relationship, then it is known as one to one
relationship.

For example, A female can marry to one male, and a male can marry to one female.

b. One-to-many relationship

When only one instance of the entity on the left, and more than one instance of an entity on the right associates
with the relationship then this is known as a one-to-many relationship.

For example, Scientist can invent many inventions, but the invention is done by the only specific scientist.

c. Many-to-one relationship

When more than one instance of the entity on the left, and only one instance of an entity on the right associates
with the relationship then it is known as a many-to-one relationship.

For example, Student enrolls for only one course, but a course can have many students.

d. Many-to-many relationship

When more than one instance of the entity on the left, and more than one instance of an entity on the right
associates with the relationship then it is known as a many-to-many relationship.

For example, Employee can assign by many projects and project can have many employees.

4. Types of relationship are as follows:

a. One-to-One Relationship

When only one instance of an entity is associated with the relationship, then it is known as one to one
relationship.

For example, If there are two entities ‘Person’ (Id, Name, Age, Address)and ‘Passport’(Passport_id,
Passport_no). So, each person can have only one passport and each passport belongs to only one person.
b. One-to-many relationship

When only one instance of the entity on the left, and more than one instance of an entity on the right associates
with the relationship then this is known as a one-to-many relationship.

For example,

c. Many-to-one relationship

When more than one instance of the entity on the left, and only one instance of an entity on the right associates
with the relationship then it is known as a many-to-one relationship.

For example, If there are two entity type ‘Customer’ and ‘Account’ then each ‘Customer’ can have more
than one ‘Account’ but each ‘Account’ is held by only one ‘Customer’. In this example, we can say that
each Customer is associated with many Account. So, it is a one-to-many relationship. But, if we see it the
other way i.e many Account is associated with one Customer then we can say that it is a many-to-one
relationship.

d. Many-to-many relationship
When more than one instance of the entity on the left, and more than one instance of an entity on the right
associates with the relationship then it is known as a many-to-many relationship.

For example, If there are two entity type ‘Customer’ and ‘Product’ then each customer can buy more than
one product and a product can be bought by many different customers.

5. Schema: The overall design of the database is called database schema. Schema will not be changed
frequently. It is the logical structure of a database. It does not show the data in the database.

The schema is pictorially represented as follows −

Types of Schema

The different types of schemas are as follows −

 Physical schema − It is a database design at the physical level.It is hidden below the logical schema and
can be changed easily without affecting the application programs.
 Logical schema − It is a database design at the logical level. Programmers construct applications using
logical schema.

 External − It is schema at view level. It is the highest level of a schema which defines the views for end
users.

Generally the Database Management System (DBMS) assists one physical schema, one logical schema and
several sub or external schemas.

Database schema refers to the format and layout of the database in which the data will be stored. It is the one
thing that remains the same throughout unless otherwise modified. It defines the structure of what type of data
and how it will be stored.

Example

A database schema for a person will have fields for name, email, phone and address as shown below −

Person

Name Email Phone no

Instance

Instance or extension or database state is a collection of information that stored in a database at a particular
moment is called an instance of the database. The Database instance refers to the information stored in the
database at a given point of time. Thus, it is a dynamic value which keeps on changing.

Example

A database instance for the Person database can be (User1,emai.com,11345679,addr) So the person construct
will contain their individual entities in the attributes called as instance. This is shown below −

Person

Name Email Phone no


BOB kksd@yasd.com 2343435

JANU werwr@sdas.in 5345464

PRIYA wefrwer@sdf.com 2342342

Differences

The major differences between schema and instance are as follows –

Database Schema Database Instance

It is the definition of the database or it is It is a snapshot of a database at a specific


defined as the description of the database. moment.

It rarely changes. It changes frequently.

Example” We take two tables emp table At a moment, what is the value of the database
and dept table.Emp schema is called instance.At t=8 A.M

Id Empid name salary did

Name 1 A 5000 d1

Salary 2 B 2000 d2

At t=9 A.M
dept 3

Dept
C

Dept_id
3000

dname
d3

Emp and dept both called as schemas


It gives database definition Empid 1 and 2 are called as Instance 1
At time 9 A.M instance 2 changes

This corresponds to the variable declaration The value of the variable in a program at a point
of a programming language. in time corresponds to an instance of the database
schema.
6. Data Definition Language
o DDL stands for Data Definition Language. It is used to define database structure or pattern.
o It is used to create schema, tables, indexes, constraints, etc. in the database.
o Using the DDL statements, you can create the skeleton of the database.

o Data definition language is used to store the information of metadata like the number of tables and
schemas, their names, indexes, columns in each table, constraints, etc.

Here are some tasks that come under DDL:

o Create: It is used to create objects in the database.


o Alter: It is used to alter the structure of the database.
o Drop: It is used to delete objects from the database.
o Truncate: It is used to remove all records from a table.

o Rename: It is used to rename an object.

o Comment: It is used to comment on the data dictionary.

These commands are used to update the database schema that's why they come under Data definition language.
7. Relational Calculus

o Relational calculus is a non-procedural query language. In the non-procedural query language, the user
is concerned with the details of how to obtain the end results.

o The relational calculus tells what to do but never explains how to do.

Types of Relational calculus:

1. Tuple Relational Calculus (TRC)

o The tuple relational calculus is specified to select the tuples in a relation. In TRC, filtering variable uses
the tuples of a relation.

o The result of the relation can have one or more tuples.

Notation:

1. {T | P (T)} or {T | Condition (T)}

Where

T is the resulting tuples

P(T) is the condition used to fetch T.

For example:

1. { T.name | Author(T) AND T.article = 'database' }

OUTPUT: This query selects the tuples from the AUTHOR relation. It returns a tuple with 'name' from Author
who has written an article on 'database'.

TRC (tuple relation calculus) can be quantified. In TRC, we can use Existential (∃) and Universal Quantifiers
(∀).

For example:

1. { R| ∃T ∈ Authors(T.article='database' AND R.name=T.name)}


Output: This query will yield the same result as the previous one.

2. Domain Relational Calculus (DRC)

o The second form of relation is known as Domain relational calculus. In domain relational calculus,
filtering variable uses the domain of attributes.

o Domain relational calculus uses the same operators as tuple calculus. It uses logical connectives 𝖠 (and),
∨ (or) and ┓ (not).

o It uses Existential (∃) and Universal Quantifiers (∀) to bind the variable.

Notation:

1. { a1, a2, a3, ..., an | P (a1, a2, a3, ... ,an)}

Where

a1,a2 are attributes


P stands for formula built by inner attributes

For example:

1. {< article, page, subject > | ∈ javatpoint 𝖠 subject = 'database'}

Output: This query will yield the article, page, and subject from the relational javatpoint, where the subject is a
database.

8. Aggregate functions in SQL


 Difficulty Level : Easy
 Last Updated : 20 Aug, 2019
In database management an aggregate function is a function where the values of multiple rows are
grouped together as input on certain criteria to form a single value of more significant meaning.

Various Aggregate Functions


1) Count()
2) Sum()

3) Avg()

4) Min()

5) Max()

Now let us understand each Aggregate function with a

example: Id Name Salary

1 A 80

2 B 40

3 C 60

4 D 70

5 E 60

6 F Null

Count():

Count(*): Returns total number of records .i.e 6.


Count(salary): Return number of Non Null values over the column salary. i.e 5.
Count(Distinct Salary): Return number of distinct Non Null values over the column salary .i.e 4

Sum():

sum(salary): Sum all Non Null values of Column salary i.e., 310
sum(Distinct salary): Sum of all distinct Non-Null values i.e., 250.
Avg():

Avg(salary) = Sum(salary) / count(salary) = 310/5


Avg(Distinct salary) = sum(Distinct salary) / Count(Distinct Salary) = 250/4

Min():

Min(salary): Minimum value in the salary column except NULL i.e., 40.
Max(salary): Maximum value in the salary i.e., 80.

9. Types of Table Relationship:

A relational database collects different types of data sets that use tables, records, and columns. It is used to
create a well-defined relationship between database tables so that relational databases can be easily stored. For
example of relational databases such as Microsoft SQL Server, Oracle Database, MYSQL, etc.

There are some important parameters of the relational database:

o It is based on a relational model (Data in tables).

o Each row in the table with a unique id, key.

o Columns of the table hold attributes of data.

Employee table (Relation / Table Name)

EmpID EmpName EmpAge CountryName

Emp 101 Andrew Mathew 24 USA


Emp 102 Marcus dugles 27 England

Emp 103 Engidi Nathem 28 France

Emp 104 Jason Quilt 21 Japan

Emp 108 Robert 29 Italy

Following are the different types of relational database tables.

Competitive questions on Structures in Hindi

Keep Watching

1. One to One relationship

2. One to many or many to one relationship

3. Many to many relationships

One to One Relationship (1:1): It is used to create a relationship between two tables in which a single row of
the first table can only be related to one and only one records of a second table. Similarly, the row of a second
table can also be related to anyone row of the first table.

Following is the example to show a relational database, as shown below.


One to Many Relationship: It is used to create a relationship between two tables. Any single rows of the first
table can be related to one or more rows of the second tables, but the rows of second tables can only relate to
the only row in the first table. It is also known as a many to one relationship.

Representation of One to Many relational databases:

Representation of many to one relational database

Many to Many Relationship: It is many to many relationships that create a relationship between two tables.
Each record of the first table can relate to any records (or no records) in the second table. Similarly, each record
of the second table can also relate to more than one record of the first table. It is also represented
an N:N relationship.
For example, there are many people involved in each project, and every person can involve more than one
project.

10. Boyce Codd normal form (BCNF):

o BCNF is the advance version of 3NF. It is stricter than 3NF.

o A table is in BCNF if every functional dependency X → Y, X is the super key of the table.

o For BCNF, the table should be in 3NF, and for every FD, LHS is super key.

Example: Let's assume there is a company where employees work in more than one department.

EMPLOYEE table:

EMP_ID EMP_COUNTRY EMP_DEPT DEPT_TYPE EMP_DE

264 India Designing D394 283

264 India Testing D394 300


364 UK Stores D283 232

364 UK Developing D283 549

In the above table Functional dependencies are as follows:

1 . EMP_ID → EMP_COUNTRY
2 . EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}

Candidate key: {EMP-ID, EMP-DEPT}

The table is not in BCNF because neither EMP_DEPT nor EMP_ID alone are keys.

To convert the given table into BCNF, we decompose it into three tables:

EMP_COUNTRY table:

EMP_ID EMP_COUNTRY

264 India

264 India

EMP_DEPT table:

EMP_DEPT DEPT_TYPE EMP_DEPT_NO

Designing D394 283

Testing D394 300


Stores D283 232

Developing D283 549

EMP_DEPT_MAPPING table:

EMP_ID EMP_DEPT

D394 283

D394 300

D283 232

D283 549

Functional dependencies:

. EMP_ID → EMP_COUNTRY
1
. EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
2

Candidate keys:

For the first table: EMP_ID


For the second table: EMP_DEPT
For the third table: {EMP_ID, EMP_DEPT}

Normalization

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.

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 candidate-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 called partial 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 −


o X is a superkey or,
o A is prime attribute.

We find that in the above Student_detail relation, Stu_ID is the key and only prime key attribute. We find that
City can be identified by Stu_ID as well as Zip itself. Neither Zip is a superkey nor is City a prime attribute.
Additionally, Stu_ID → Zip → City, so there exists transitive dependency.

To bring this relation into third normal form, we break the relation into two relations as follows −

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_Name,

Zip and

Zip → City

Which confirms that both the relations are in BCNF


HDAM or PHDAM databases consist of two parts: a root addressable area and an overflow area.

The root addressable area contains root segments and is the primary storage area for dependent segments in a
database record. The overflow area is for the storage of segments that do not fit in the root addressable area.
You specify the size of the root addressable area in the relative block number (RBN) operand of the RMNAME
parameter in the DBD statement. For PHDAM, you can also use the HALDB Partition Definition utility to
specify the size of the root addressable area. You also specify the maximum number of bytes of a database
record to be stored in the root addressable area by using the BYTES operand of the RMNAME parameter in
the DBD statement. For PHDAM databases, you can use the HALDB Partition Definition utility to specify the
maximum number of bytes in the root addressable area.

The following figure shows example SKILL database records.

Figure 1. Two example SKILL records in an HD database

The following figure shows how these records are stored in a HDAM or HIDAM database.

Figure 2. HDAM or PHDAM database records in storage


When the database is initially loaded, the root and each dependent segment are put in the root addressable area
until the next segment to be stored will cause the total space used to exceed the amount of space you specified
in the BYTES operand. At this point, all remaining dependent segments in the database record are stored in
the overflow area.

In an HDAM or a PHDAM database, the order in which you load database records does not matter. The user
randomizing module determines where each root is stored. However, as with all types of databases, when
the database is loaded, all dependents of a root must be loaded in hierarchical sequence following the root.

To store an HDAM or a PHDAM database record, the randomizing module takes the root's key and, by hashing
or some other arithmetic technique, computes an RBN or CI number and a RAP number within the block or CI.
The module gives these numbers to IMS, and IMS determines where in the root addressable area to store the
root. The RBN or CI tells IMS in which CI or block (relative to the beginning of the data set) the RAP will be
stored. The RAP number tells which RAP in the CI or block will contain the address of the root. During load,
IMS stores the root and as many of its dependent segments that will fit (based on the bytes operand) in the root
addressable area.
When the database is initially loaded, it puts the root and segments in the first available space in the specified
CI or block, if this is possible. IMS then puts the 4-byte address of the root in the RAP of the CI or block
designated by the randomizing module. RAPs only exist in the root addressable area. If space is not available
in the root addressable area for a root, it is put in the overflow area. The root, however, is chained from a RAP
in the root addressable area.

Comments in SQL

There are two ways in which you can comment in SQL, i.e. either the Single-Line Comments or the Multi-Line
Comments.

Single-Line Comments
The single line comment starts with two hyphens (–). So, any text mentioned after (–), till the end of a single
line will be ignored by the compiler.

Example:
1 --Select all:

2 SELECT * FROM Employee_Info;

Multi-Line Comments
The Multi-line comments start with /* and end with */. So, any text mentioned between /* and */ will be
ignored by the compiler.

Example:
1 /*Select all the columns

2 of all the records

3 from the Employee_Info table:*/

4 SELECT * FROM Students;

SQL Commands: Data Definition Language Commands (DDL)

This section of the article will give you an insight into the commands through which you can define your
database. The commands are as follows:


 CREATE
 DROP
 TRUNCATE
 ALTER
 BACKUP DATABASE

CREATE
This statement is used to create a table or a database.

The ‘CREATE DATABASE’ Statement


As the name suggests, this statement is used to create a database.

Syntax
CREATE DATABASE DatabaseName;
Example
1 CREATE DATABASE Employee;

The ‘CREATE TABLE’ Statement


This statement is used to create a table.

Syntax
CREATE TABLE TableName (
Column1 datatype,
Column2 datatype,
Column3 datatype,
....

ColumnN datatype
);
Example
1 CREATE TABLE Employee_Info

2 (

3 EmployeeID int,
4 EmployeeName varchar(255),

5 Emergency ContactName

6 varchar(255), PhoneNumber int,

7 Address

8 varchar(255), City

9 varchar(255),

10 Country varchar(255)

);
You can also create a table using another table. Refer the below sytax and example:

The ‘CREATE TABLE AS’ Statement


Syntax
CREATE TABLE NewTableName AS
SELECT Column1, column2,..., ColumnN
FROM ExistingTableName
WHERE.....;
Example
1 CREATE TABLE ExampleTable AS

2 SELECT EmployeeName, PhoneNumber

3 FROM Employee_Info;
DROP
This statement is used to drop an existing table or a database.

The ‘DROP DATABASE’ Statement


This statement is used to drop an existing database. When you use this statement, complete information present
in the database will be lost.

Syntax
DROP DATABASE DatabaseName;
Example
1 DROP DATABASE Employee;

The ‘DROP TABLE’ Statement


This statement is used to drop an existing table. When you use this statement, complete information present in
the table will be lost.

Syntax
DROP TABLE TableName;
Example
1 DROP Table Employee_Info;

TRUNCATE
This command is used to delete the information present in the table but does not delete the table. So, once you
use this command, your information will be lost, but not the table.

Syntax
TRUNCATE TABLE TableName;
Example
1 TRUNCATE Table Employee_Info;

ALTER
This command is used to delete, modify or add constraints or columns in an existing table.

The ‘ALTER TABLE’ Statement


This statement is used to add, delete, modify columns in an existing table.

The ‘ALTER TABLE’ Statement with ADD/DROP COLUMN


You can use the ALTER TABLE statement with ADD/DROP Column command according to your need. If you
wish to add a column, then you will use the ADD command, and if you wish to delete a column, then you will
use the DROP COLUMN command.

Syntax
ALTER TABLE TableName
ADD ColumnName Datatype;

ALTER TABLE TableName


DROP COLUMN ColumnName;
Example
1 --ADD Column BloodGroup:

3 ALTER TABLE

4 Employee_Info ADD

5 BloodGroup varchar(255);

7 --DROP Column BloodGroup:

9 ALTER TABLE

Employee_Info DROP

COLUMN BloodGroup ;
The ‘ALTER TABLE’ Statement with ALTER/MODIFY COLUMN
This statement is used to change the datatype of an existing column in a table.

Syntax
ALTER TABLE TableName
ALTER COLUMN ColumnName Datatype;
Example
1 --Add a column DOB and change the data type to Date.

3 ALTER TABLE Employee_Info

4 ADD DOB year;

6 ALTER TABLE Employee_Info

7 ALTER DOB date;


BACKUP DATABASE
This statement is used to create a full backup of an existing database.

Syntax
BACKUP DATABASE DatabaseName
TO DISK = 'filepath';
Example
1 BACKUP DATABASE Employee

2 TO DISK = 'C:UsersSahitiDesktop';

You can also use a differential back up. This type of back up only backs up the parts of the database,
which have changed since the last complete backup of the database.

Syntax
BACKUP DATABASE DatabaseName
TO DISK = 'filepath'
WITH DIFFERENTIAL;
Example
1 BACKUP DATABASE Employee

2 TO DISK = 'C:UsersSahitiDesktop'

3 WITH DIFFERENTIAL;

You might also like