Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 39

FAIRFIELD INSTITUTE OF MANAGEMENT AND TECHNOLOGY

LAB FILE

Information System Management (307)

Submitted
To: Submitted By:
Mr. Raj Kumar
Garg Student Name: JOJAF MASSY
Asst.Professor Enrol. No.
- 00451488819
ITDepartment B.Com. Sem.
-V
TABLE OF CONTENTS

S. No. Name of Program Signature Remarks


1 Introduction to relational database management system.

2 Introduction to structure query language.

3 To illustrate data definition language commands in


RDBMS.
4 To illustrate data manipulation language command in RDBMS

5 To illustrate create table command in SQL.

6 To illustrate insert values command in SQL.

7 To illustrate select table command in SQL.

8 To illustrate update table command in SQL.

9 To illustrate alter command in SQL.

10 To illustrate delete command in SQL.

11 To illustrate drop table command in SQL.

12 To illustrate difference between delete & drop table command


in SQL.

13 To illustrate rename command in SQL.

14 To illustrate integrity constraint in SQL.

15 To illustrate relational model in DBMS

16 To illustrate Aggregate Functions in SQL.

17 Introduction to Entity Relationship Model in DBMS

18 Database design using Entity Relationship Model.

19 Draw an ER diagram for Banking system.

20 Draw an ER diagram for Library Management system.


Structure Query
Language RDBMS (relational database management system)

A relational database management system (RDBMS) is a collection of programs and


capabilities that enable IT teams and others to create, update, administer and otherwise
interact with a relational database. RDBMSes store data in the form of tables, with most
commercial relational database management systems using Structured Query
Language (SQL) to access the database. However, since SQL was invented after the initial
development of the relational model, it is not necessary for RDBMS use.
The RDBMS is the most popular database system among organizations across the world. It
provides a dependable method of storing and retrieving large amounts of data while offering
a combination of system performance and ease of implementation.
RDBMS vs DBMS
In general, databases store sets of data that can be queried for use in other applications. A
database management system supports the development, administration and use of database
platforms. An RDBMS is a type of database management system (DBMS) that stores data in
a row-based table structure which connects related data elements. An RDBMS includes
functions that maintain the security, accuracy, integrity and consistency of the data. This is
different than the file storage used in a DBMS.
Other differences between database management systems and relational database
management systems include:

• Number of allowed users. While a DBMS can only accept one user at a time, an
RDBMS can operate with multiple users.
• Hardware and software requirements. A DBMS needs less software and hardware
than an RDBMS.
• Amount of data. RDBMSes can handle any amount of data, from small to large,
while a DBMS can only manage small amounts.
• Database structure. In a DBMS, data is kept in a hierarchical form, whereas an
RDBMS utilizes a table where the headers are used as column names and the rows
contain the corresponding values.
• ACID implementation. DBMSes do not use the atomicity, consistency, isolation and
durability (ACID) model for storing data. On the other hand, RDBMSes base the
structure of their data on the ACID model to ensure consistency
• Distributed databases. While an RDBMS offers complete support for distributed
databases, a DBMS will not provide support.
• Types of programs managed. While an RDBMS helps manage the relationships
between its incorporated tables of data, a DBMS focuses on maintaining databases
that are present within the computer network and system hard disks.
• Support of database normalization. An RDBMS can be normalized, but a DBMS
cannot.
FEATURES OF RELATIONAL DATABASE MANAGEMENT
SYSTEMS
• Elements of the relational database management system that overarch the basic
relational database are so intrinsic to operations that it is hard to dissociate the two in
practice.
• The most basic RDBMS functions are related to create, read, update and delete
operations -- collectively known as CRUD. They form the foundation of a well-
organized system that promotes consistent treatment of data.
• The RDBMS typically provides data dictionaries and metadata collections that are
useful in data handling. These programmatically support well-defined data structures
and relationships. Data storage management is a common capability of the RDBMS,
and this has come to be defined by data objects that range from binary large object --
or blob -- strings to stored procedures. Data objects like this extend the scope of basic
relational database operations and can be handled in a variety of ways in different
RDBMSes.
• The most common means of data access for the RDBMS is SQL. Its main language
components comprise data manipulation language and data definition language
statements. Extensions are available for development efforts that pair SQL use with
common programming languages, such as the Common Business-Oriented Language
(COBOL), Java and .NET.
• RDBMSes use complex algorithms that support multiple concurrent user access to the
database while maintaining data integrity. Security management, which enforces
policy-based access, is yet another overlay service that the RDBMS provides for the
basic database as it is used in enterprise settings.
• RDBMSes support the work of database administrators (DBAs) who must manage
and monitor database activity. Utilities help automate data loading and database
backup. RDBMSes manage log files that track system performance based on selected
operational parameters. This enables measurement of database usage, capacity and
performance, particularly query performance. RDBMSes provide graphical interfaces
that help DBAs visualize database activity.
• While not limited solely to the RDBMS, ACID compliance is an attribute of relational
technology that has proved important in enterprise computing. These capabilities have
particularly suited RDBMSes for handling business transactions.
• As RDBMSes have matured, they have achieved increasingly higher levels of query
optimization, and they have become key parts of reporting, analytics and data
warehousing applications for businesses as well. RDBMSes are intrinsic to operations
of a variety of enterprise applications and are at the center of most master data
management systems.
How RDBMS works
As mentioned before, an RDBMS will store data in the form of a table. Each system will
have varying numbers of tables with each table possessing its own unique primary key. The
primary key is then used to identify each table.
Within the table are rows and columns. The rows are known as records or horizontal
entities; they contain the information for the individual entry. The columns are known as

vertical entities and possess information about the specific field.

Before creating these tables, the RDBMS must check the following
constraints:
• Primary keys - this identifies each row in the table. One table can only contain one
primary key. The key must be unique and without null values.
• Foreign keys - this is used to link two tables. The foreign key is kept in one table and
refers to the primary key associated with another table.
• Not null - this ensures that every column does not have a null value, such as an empty
cell.
• Check - this confirms that each entry in a column or row satisfies a precise condition
and that every column holds unique data. • Data integrity - the integrity of the data
must be confirmed before the data is created.

Assuring the integrity of data includes several specific tests, including entity, domain,
referential and user-defined integrity. Entity integrity confirms that the rows are not
duplicated in the table. Domain integrity makes sure that data is entered into the table based
on specific conditions, such as file format or range of values. Referential integrity ensures
that any row that is re-linked to a different table cannot be deleted. Finally, user-defined
integrity confirms that the table will satisfy all user-defined conditions.
SQL INTRODUCTION
SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of
the International Organization for Standardization (ISO) in 1987.
Structure Query Language(SQL) is a database query language used for storing and managing
data in Relational DBMS. SQL was the first commercial language introduced for E.F Codd's
Relational model of database. Today almost all RDBMS(MySql, Oracle, Infomix, Sybase, MS
Access) use SQL as the standard database query language. SQL is used to perform all types of

data operations in RDBMS.

SQL Command
SQL defines following ways to manipulate data stored in an RDBMS.

DDL: Data Definition Language


This includes changes to the structure of the table like creation of table, altering table,
deleting a table etc.
All DDL commands are auto-committed. That means it saves all the changes permanently in
the database.

COMMAND DESCRIPTION
Create To create new table or database
Alter For alteration
Truncate Delete data from table
Drop To drop a table
Rename To rename a table

DML: Data Manipulation Language


DML commands are used for manipulating the data stored in the table and not the table itself.
DML commands are not auto-committed. It means changes are not permanent to database,
they can be rolled back.
COMMAND DESCRIPTION
Insert To insert a new row
Update To update existing row
Delete To delete a row
Merge Merging two rows or two tables
TCL: Transaction Control Language
These commands are to keep a check on other commands and their affect on the database.
These commands can annul changes made by other commands by rolling the data back to its
original state. It can also make any temporary change permanent.
COMMAND DESCRIPTION
commit To permanently save
rollback To undo change
savepoint To save temporarily

DCL: Data Control Language


Data control language are the commands to grant and take back authority from any database
user.
COMMAND DESCRIPTION
grant Grant permission of right
revoke take back permission
DQL: Data Query Language
Data query language is used to fetch data from tables based on conditions that we can easily
apply.
COMMAND DESCRIPTION
select Retrieve records from one or more table

DDL COMMANDS IN RDBMS


• 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:


• CREATE
• ALTER
• DROP
• TRUNCATE
a. 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 D
ATE);

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

Syntax:
DROP TABLE table_name;
Example
DROP TABLE EMPLOYEE;
c. 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));

d. 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;
DML COMMAND IN RDBMS

• 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.

Here are some commands that come under DML:


• INSERT
• UPDATE
• DELETE
a. 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
2. (col1, col2, col3,. ... col N)
3. VALUES (value1, value2, value3, ..... valueN); Or
1. INSERT INTO TABLE_NAME
2. VALUES (value1, value2, value3, ..... valueN);

For example:
1. INSERT INTO javatpoint (Author, Subject) VALUES ("Sonoo", "DBMS");

b. UPDATE: This command is used to update or modify the value of a column in the table.
Syntax:
1. UPDATE table_name SET [column_name1= value1,...column_nameN =
valueN] [W HERE CONDITION] For example:
1. UPDATE students
2. SET User_Name = 'Sonoo'
3. WHERE Student_Id = '3'
c. DELETE: It is used to remove one or more row from a table.
Syntax:
1. DELETE FROM table_name [WHERE condition]; For example:
1. DELETE FROM javatpoint

2. WHERE Author="Sonoo";
1. SQL
CREATE TABLE COMMAND IN

SYNTAX:
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype, ....
);
2. SQL

INSERT VALUES COMMAND IN

SYNTAX:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
3. SQL

SYNTAX:
4. SQL
SELECT TABLE COMMAND IN

SELECT column1, column2, ...


FROM table_name;
5. SQL

SYNTAX:
6. SQL

SYNTAX:
UPDATE TABLE COMMAND IN

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
7.

SYNTAX:

ALTER COMMAND IN SQL

ALTER TABLE table_name


ADD column_name datatype;
8.

DELETE COMMAND IN SQL

SYNTAX:
DELETE FROM table_name WHERE condition;
9.

SYNTAX:
10.

DROP TABLE COMMAND IN SQL

SYNTAX: DROP TABLE table_name;

DIFFERENCE BETWEEN DELETE AND DROP TABLE COMMAND


IN SQL
Sr. Key DELETE DROP
No.

Purpose DELETE Command, removes DROP Command, removes named


1 some or all tuples/records from a elements of schema like relations/table,
relation/table constraints or entire schema.

2 Language DELETE is DML. DROP is DDL.

Clause Where clause is used to add No where clause is available.


3 filterin

Rollback Delete command can be Drop command can't be rollbacked as it


4 rollbacked as it works on data works directly on data.
buffer.

Memory Table memory space is not free if Drop command frees the memory space.
5 Space all records are deleted using
Delete Command.

Problem DELETE command may face DROP Command may cause memory
6 shortage of memory. fragmentation.

Interaction SQL directly interacts with PL/SQL does not directly interacts with
6 database server. database server.

Orientation SQL is data oriented language. PL/SQL is application oriented


7 language.

Objective SQL is used to write queries, PL/SQL is used to write program blocks,
8 create and execute DDL and functions, procedures, triggers and
DML statments. packages.

INTEGRITY CONSTRAINTS IN SQL


SQL constraints are used to specify rules for the data in a table.Constraints are used to limit
the type of data that can go into a table. This ensures the accuracy and reliability of the data
in the table. If there is any violation between the constraint and the data action, the action is
aborted. Constraints can be column level or table level. Column level constraints apply to a

column, and table level constraints apply to the whole table.

1. SQL Primary key:

This constraint defines a column or combination of columns which uniquely identifies each
row in the table

Syntax to define a Primary key:

[CONSTRAINT constraint_name] PRIMARY KEY (column_name1,column_name2,..) For


Eg : To create an employee table with Primary Key constraint, the query would be like.

CREATE TABLE employee


( id number(5), NOT NULL,
name char(20), dept
char(10), age number(2),
salary number(10), location
char(10),
ALTER TABLE employee ADD CONSTRAINT PK_EMPLOYEE_ID PRIMARY KEY (id)
);

2. SQL Foreign key or Referential Integrity :

This constraint identifies any column referencing the PRIMARY KEY in another table. It
establishes a relationship between two columns in the same table or between different
tables. For a column to be defined as a Foreign Key, it should be a defined as a Primary
Key in the table which it is referring. One or more columns can be defined as Foreign key.
Syntax to define a Foreign key

[CONSTRAINT constraint_name]
FOREIGN KEY(column_name)
REFERENCES referenced_table_name(column_name);
EXAMPLE: To create an employee table with Unique key, the query would be like,
CREATE TABLE order_items
( order_id number(5) , product_id
number(5), product_name
char(20), supplier_name
char(20), unit_price number(10)
CONSTRAINT od_id_pk PRIMARY KEY(order_id),
CONSTRAINT pd_id_fk FOREIGN KEY(product_id) REFERENCES product(product_id)
);

3. SQL Not Null Constraint :


This constraint ensures all rows in the table contain a definite value for the column which is

specified as not null. Which means a null value is not allowed.

Syntax to define a Not Null constraint:


[CONSTRAINT constraint name] NOT NULL
For Example: To create a employee table with Null value, the query would be like
CREATE TABLE employee
( id number(5),
name char(20) CONSTRAINT nm_nn NOT NULL,
dept char(10), age number(2), salary number(10),
location char(10)
);
4. SQL Unique Key:

This constraint ensures that a column or a group of columns in each row have a distinct
value. A column(s) can have a null value but the values cannot be duplicated.

Syntax to define a Unique key


[CONSTRAINT constraint_name] UNIQUE(column_name)
For Eg: To create an employee table with Unique key, the query would be like,
CREATE TABLE employee ( id
number(5) PRIMARY KEY,
name char(20), dept char(10),
age number(2), salary
number(10), location char(10),
CONSTRAINT loc_un UNIQUE(location)
);

5. SQL CHECK CONSTRAINT :

This constraint defines a business rule on a column. All the rows must satisfy this rule. The
constraint can be applied for a single column or a group of columns.

SYNTAX TO DEFINE A CHECK CONSTRAINT:


[CONSTRAINT constraint_name] CHECK (condition)

For Example: In the employee table to select the gender of a person, the query would be
like
CREATE TABLE employee ( id
number(5) PRIMARY KEY,
name char(20), dept char(10),

age number(2),
gender char(1),
salary number(10),
location char(10),
CONSTRAINT gender_ck CHECK (gender in ('M','F'))
);
RELATIONAL MODEL IN DBMS
Relational Model (RM) represents the database as a collection of relations. A relation is
nothing but a table of values. Every row in the table represents a collection of related data
values. These rows in the table denote a real-world entity or relationship.
The table name and column names are helpful to interpret the meaning of values in each row.
The data are represented as a set of relations. In the relational model, data are stored as
tables. However, the physical storage of the data is independent of the way the data are
logically organized.

Some popular Relational Database management systems are:

DB2 and Informix Dynamic Server – IBM

Oracle and RDB – Oracle

SQL Server and Access – Microsoft

Relational Model Concepts

• Attribute: Each column in a Table. Attributes are the properties which define a
relation. e.g., Student_Rollno, NAME,etc.
• Tables – In the Relational model the, relations are saved in the table format. It is
stored along with its entities. A table has two properties rows and columns. Rows
represent records and columns represent attributes.
• Tuple – It is nothing but a single row of a table, which contains a single record.
• Relation Schema: A relation schema represents the name of the relation with its
attributes.
• Degree: The total number of attributes which in the relation is called the degree of the
relation.
• Cardinality: Total number of rows present in the Table.
• Column: The column represents the set of values for a specific attribute.
• Relation instance – Relation instance is a finite set of tuples in the RDBMS system.
Relation instances never have duplicate tuples.
• Relation key – Every row has one, two or multiple attributes, which is called relation
key.
• Attribute domain – Every attribute has some pre-defined value and scope which is
known as attribute domain.

AGGREGATE FUNCTIONS IN SQL


1)

COUNT

SYNTAX:
SELECT COUNT(column_name)
FROM table_name
WHERE condition;
2)

AVERAGE

SYNTAX:
SELECT AVG(column_name)
FROM table_name
WHERE condition;
3)

SUM

SYNTAX
SELECT SUM(column_name)
4)

FROM table_name
WHERE condition;

MINIMUM
5)

SYNTAX:
SELECT MIN(column_name)
FROM table_name
WHERE condition;
6)

MAXIMUM

SYNTAX:
SELECT MAX(column_name)
FROM table_name
WHERE condition;
7)
INTRODUCTION TO ENTITY RELATIONSHIP MODEL IN DBMS 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

Operations in Relational Model

Four basic update operations performed on relational database model are


Insert, update, delete and select.
• Insert is used to insert data into the relation • Delete is used
to delete tuples from the table.
• Modify allows you to change the values of some attributes in
existing tuples.
• Select allows you to choose a specific range of data.

DATABASE DESIGN USING ENTITY RELATIONSHIP MODEL


Entity Relationship Diagram Symbols & Notations mainly contains three basic
symbols which are rectangle, oval and diamond to represent relationships between
elements, entities and attributes. There are some sub-elements which are based on
main elements in ERD Diagram. ER Diagram is a visual representation of data that
describes how data is related to each other using different ERD Symbols and
Notations. Following are the main components and its symbols in ER Diagrams.

1. Attribute: Each column in a Table. Attributes are the


properties which definea relation. e.g., Student_Rollno,
NAME,etc.
2. Tables – In the Relational model the, relations are saved in the
table format. It is stored along with its entities. A table has two
properties rows and columns. Rows represent records and
columns represent attributes.
3. Tuple – It is nothing but a single row of a table, which contains
a single record.
4. Relation Schema: A relation schema represents the name of
the relation with its attributes.
5. Degree: The total number of attributes which in the relation is
called the degree of the relation.
6. Cardinality: Total number of rows present in the Table.
7. Column: The column represents the set of values for a specific
attribute.
8. Relation instance – Relation instance is a finite set of tuples in
the RDBMS system. Relation instances never have duplicate tuples.
9. Relation key - Every row has one, two or multiple attributes,
which is called relation key.
10.Attribute domain – Every attribute has some pre-defined value
and scope which is known as attribute domain
DRAW AN ER DIAGRAM FOR BANKING SYSTEM
ER diagram is known as Entity-Relationship diagram. It is used to analyze to structure
of the Database. It shows relationships between entities and their attributes. An ER
model provides a means of communication.
ER diagram of Bank has the following description :

● Bank have Customer.


● Banks are identified by a name, code, address of main office.
● Banks have branches.
● Branches are identified by a branch_no., branch_name, address.
● Customers are identified by name, cust-id, phone number, address.
● Customer can have one or more accounts.
● Accounts are identified by acc_no., acc_type, balance.
● Customer can avail loans.
● Loans are identified by loan_id, loan_type and amount.
● Account and loans are related to bank’s branch.

DRAW AN ER DIAGRAM FOR LIBRARY MANAGEMENT SYSTEM

The Library Management System database keeps track of readers with the following considerations –

● The system keeps track of the staff with a single point authentication system comprising
login Id and password.

● Staff maintains the book catalog with its ISBN, Book title, price(in INR), category(novel,
general, story), edition, author Number and details.

● A publisher has publisher Id, Year when the book was published, and name of the book.
● Readers are registered with their user_id, email, name (first name, last name), Phone no
(multiple entries allowed), communication address. The staff keeps track of readers.

● Readers can return/reserve books that stamps with issue date and return date. If not
returned within the prescribed time period, it may have a due date too.

● Staff also generate reports that has readers id, registration no of report, book no and
return/issue info.

● This Library ER diagram illustrates key information about the Library, including entities
such as staff, readers, books, publishers, reports, and authentication system. It allows for
understanding the relationships between entities.

You might also like