0% found this document useful (0 votes)
64 views

DBMS LAB File

The document provides information about SQL, databases, database management systems, and some popular DBMS software. It includes: 1) An introduction to SQL, the standard language used to create, retrieve, update and manage data in relational database management systems. 2) A definition of what a database is and common types of databases. 3) An explanation of what a database management system (DBMS) is used for and some popular DBMS software like MySQL, Oracle, MongoDB, Amazon RDS, and Microsoft SQL Server.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

DBMS LAB File

The document provides information about SQL, databases, database management systems, and some popular DBMS software. It includes: 1) An introduction to SQL, the standard language used to create, retrieve, update and manage data in relational database management systems. 2) A definition of what a database is and common types of databases. 3) An explanation of what a database management system (DBMS) is used for and some popular DBMS software like MySQL, Oracle, MongoDB, Amazon RDS, and Microsoft SQL Server.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

DELHI TECHNOLOGICAL UNIVERSITY

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CO-202: DATABASE MANAGEMENT SYSTEM (DBMS)

PRACTICAL FILE

SUBMITTED TO : SUBMITTED BY
:

Dr. Indu Singh Siddartha


Aggarwal
Assistant professor
2K20/EE/266
Department of CSE, DTU
Experiment-1

Aim: Introduction to SQL, DATABASE and DATABASE MANAGEMENT


SYSTEM.

THEORY :
1. SQL
What is SQL ?
Structured Query Language (SQL) is an acronym for Structured Query
Language. In a relational data management system, it is used to store and manage
data (RDBMS). It is the Related databases' standard language. Creates, reads,
updates, and deletes information and tables for the user. SQL is the standard
language for all RDBMS, including MySQL, Informix, Oracle, MS Access, and
SQL Server. SQL allows users to query data in a variety of methods, including
utilizing English statements.

SOME SQL COMMANDS:


● UPDATE: It's used to keep data in a database up to date.
● SELECT: It selects and extracts data.
● INSERT INTO: Used to insert new data into a Database.
● DELETE: Data is deleted from a database.
● CREATE DATABASE: Establishing a new database.
● DROP TABLE: Used to remove a table.
● DROP INDEX: To delete an index.
● ALTER DATABASE: To make changes to a database.
● CREATE TABLE: A new table is being built.
● ALTER TABLE: Make changes to a table.
● AVG: Yields the average of a numeric column values.
● COUNT: Returns the number of rows that satisfy the provided
condition.
● SUM: A numeric column's total sum.

2. DATABASE
What is DATABASE ?
A database is a collection of interconnected data that organizes data into tables,
views, schemas, and reports and enables for efficient data retrieval, insertion, and
deletion from a database.

Types of DATABASES are:

● Distributed Database
● Cloud Database
● Relational Database
● NoSQL Database
● Centralized Database
● End User database
● Commercial Database
● Personal Database
● Operational Database

Applications Of DATABASE :
● The police maintain a database with information on all known criminals,
such as crimes they've committed.
● A hospital will keep track of all of its patients' information in a database,
such as their medical history.
● Schools employ a database to keep track of information about their
students, such as how many days they've missed due to illness.
● The government keeps track of people's income tax payments in a
database.
● A database is used to keep track of all the drivers in central London who
have (or haven't) paid the Congestion Charge.

3. DATABASE MANAGEMENT SYSTEM


What is DATABASE MANAGEMENT SYSTEM ?
A database management system is a system of software that manages databases
(DBMS). MySQL, Oracle, and other commercial DBMSs are examples of
well-known commercial DBMSs used in a wide range of applications.
Users can do the following operations with the help of a database management
system (DBMS):
● DATA DEFINITION : It facilitates the development, editing, and deletion
of definitions that define the database's data structure.
● DATA UPDATION : It assists with the actual data input, alteration, and
deletion from the database.
● DATA RETRIEVAL : It makes data retrieval from a database easier for
apps to employ for a variety of purposes.
● USER ADMINISTRATION : It aids in user registration and monitoring,
data security enforcement, performance monitoring, data integrity
maintenance, concurrency management, and the recovery of information
tainted by unexpected failure.
Features of a Database Management System ;
● A database system's self-descriptive nature.
● Secures data and eliminates redundancy.
● Support for numerous data views.
● Abstraction of data and shielding between programs.
● Multi User transaction processing and data sharing.
● Tables can be created using a database management system (DBMS).

Advantages of Database Management System :


● A database management system (DBMS) serves as a good host for
balancing the needs of multiple applications that use the same data.
● A database management system (DBMS) can store and retrieve data in a
variety of ways.
● To efficiently store and retrieve data, DBMS employs a range of powerful
functionalities.
● Because of the consistent administration procedures, data application
programmers are never exposed to the nuances of data representation and
storage.
● Barriers to integrity are referred to as DBMSs in order to obtain the best
level of protection from restricted data access.
● Ensures the integrity and security of data.
● Reduced Application Development Time.
● A database management system (DBMS) organizes simultaneous data
access so that only one user can view the same data at the same time.
Disadvantages of Database Management System :
● SIZE : To run, it demands a large amount of disk space and RAM.
● COST OF HARDWARE AND SOFTWARE : You'll need a fast data
processor and a lot of memory to run DBMS software.
● THE CONSEQUENCES OF FAILURE ARE MORE SEVERE :
Because most organizations store all data in a single location database,
failure has a substantial influence on the database, and if the database is
destroyed as a consequence of a power outage or if the database is
corrupted, the data may be lost permanently.
● COMPLEXITY : The database system adds to the complexity
requirements.
EXPERIMENT-2

AIM :
Introduction to various softwares of Database Management System and
Database Language.
THEORY :
DBMS Software : A database management system, often known as a DBMS, is a
computer programme that stores, manipulates, and manages data in a database. A
database management system (DBMS) is a software programme that links a user
to a database and allows them to interact with it. The database management
system (DBMS) can be used to create, read, update, and delete data.

LIST OF SOME DBMS SOFTWARES :


● MySql
● Oracle
● AmazonRDS
● MongoDB
● Microsoft SQL server
● ADABAS
● MariaDB
● SQLite

1. MySQL

● MySQL is an Oracle-developed relational database management system


(RDBMS) based on structured query language (SQL).
● MySQL is used to construct and maintain everything from customer-facing
web applications to complex, data-driven B2B services in many of the
most prominent software stacks.
Some Features Of MySQL :
● MySQL databases are relational.
● MySQL is highly compatible.
● MySQL is open-source.
● MySQL is easy to use.

2. ORACLE

A relational database management system such as Oracle is a relational database


management system. OracleDB, or just Oracle, is another name for it.
SOME FEATURES OF ORACLE :
● Always available and provides high availability of databases.
● Oracle has a mechanism for controlling and accessing the database to
prevent unauthorized access .
● Oracle provides features like RAC(Real Application cluster) and
portability.
● Oracle provides performance optimization tools such as Oracle Advanced
Compression, Oracle Database In-Memory, Oracle Real Application
Testing, and Oracle TimesTen Application-Tier Database Cache.

3. MongoDB

● MongoDB is an open source, non relational database management system


(DBMS) that uses flexible documents instead of tables and rows to process
and store various forms of data.

● Because MongoDB does not require a relational database management


system (RDBMS), it offers an elastic data storage paradigm that allows
users to easily store and query multiple data types. This not only makes
database management easier for developers, but it also makes
cross-platform applications and services more scalable.
SOME FEATURES OF MONGODB :
● Load balancing.
● Ad hoc database queries.
● Multi Language support.

4. Amazon RDS

Amazon Relational Database Service (RDS) is an Amazon Web Services


managed SQL database service (AWS). To store and manage data, Amazon RDS
offers a variety of database engines. Data transfer, backup, recovery, and patching
are just a few of the relational database management chores it may aid with.
SOME FEATURES OF AMAZON RDS :
● RDS uses the replication feature to create read replicas.
● Amazon RDS provides SSD , IOPS and magnetic storage
● The Amazon Cloudwatch service enables managed monitoring.
● RDS provides managed instance backups with transaction logs to enable
point-in-time recovery.

5. Microsoft SQL Server

● Microsoft SQL Server is a relational database management system that


Microsoft has created. It is a database server, which is a software product
whose principal role is to store and retrieve data as required by other
software applications, which may run on the same computer or on a
networked computer (including the Internet).
● Microsoft SQL Server is available in at least a dozen different editions,
each geared at a different audience and suited to varied workloads ranging
from modest single-machine applications to huge Internet-facing systems
with many concurrent users.

Some features of Microsoft SQL Servers :


● Provides machine learning services.
● Provides replication of data.
● Provides integration service for data report, data integration and data
warehousing.

Database Languages : Insertion, deletion, updating, and alteration are all


examples of data manipulation after it has been saved or filled. For these
purposes, the database management system provides a set of languages (DBMS).
Database languages are used to read, update, and store data in databases.

List of some database languages :

● DDL(Data Definition Language)


● DML(Data Manipulation Language)
● DCL(Data Control Language)
● TCL(Transaction Control Language)
● DQL(Data Query Language)
● SCL(Structured Controlled Language)
1. DATA DEFINITION LANGUAGE

● The database schema is specified using DDL. It's used to build database
tables, schemas, indexes, and constraints, among other things.

Operations that can be performed on database using DDL :


● Create : To create the database instance.
● Alter : To alter the structure of the database.
● Truncate : To delete tables in a database instance.
● Drop : To drop database instances.
● Rename : To rename database instances.

2. DATA MANIPULATION LANGUAGE

DML is a programming language for accessing and altering data in databases.

Operations that can be performed on database using DML :

● Select : To read records from table(s).


● Update : Update the data in table(s).
● Insert : To insert record(s) into the table(s).
● Delete : Delete all the records from the table.

3. DATA CONTROL LANGUAGE

DCL is a programming language that is used to grant and revoke database user
access.
In practice, a data definition language, a data manipulation language, and a data
control language are all components of a single database language, such as SQL.

Operations that can be performed on database using DCL :

● Grant : To grant access to users.


● Revoke : To revoke access from the user.

4. Transaction Controlled Language

TCL is used to perform or rollback the modifications we made to the database


using DML commands.

Operations that can be performed on database using TCL :

● Commit : To persist the changes made by DML commands in database


● Rollback : To rollback the changes made to the database

5. Data Query Language


DQL statements are used to query the data contained in schema objects. The
DQL Command's goal is to obtain a schema relation based on the query supplied
to it.

Operations that can be performed on database using TCL :

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

LEARNING :
We've studied about the various database management systems (DBMS) that are
now in use. We also taught about database languages and the operations that go
along with them.

CONCLUSION :
Oracle is a well-known and extensively used database management system that
supports all four types of database languages, therefore we'll be using it to
conduct our experiment.
EXPERIMENT-3

AIM :
Introduction to ER Diagram, Symbol table.
THEORY :
ER Diagram: ENTITY RELATIONAL (ER) MODEL is a high-level conceptual
data model diagram. ER modeling helps you to analyze data requirements
systematically to produce a well-designed database. The Entity-Relation model
represents real- world entities and the relationship between them. It is considered
a best practice to complete ER modeling before implementing your database. ER
modeling helps you to analyze data requirements systematically to produce a
well-designed database. So It is considered a best practice to complete ER
modeling before implementing your database. It displays the relationships of
entity sets stored in a database. In other words, we can say that ER diagrams help
you to exp. the logical structure of databases. At first look an ER diagram looks
very similar to the flowchart. However ER Diagram includes many specialized
symbols, and its meanings make this model unique.
ER DIAGRAM

ADVANTAGES OF ER DIAGRAM :
● Here. are prime reasons for using the ER Diagram.
● Helps you to define terms mist. to entity relationship modeling ➢ Provide
a preview of how all your tables should connect , what fields are going to
be on each table.
● Helps to describe entities attributes Relationships.
● ER diagrams are translatable into relation tables which allows you to build
databases quickly.
● ER diagrams can be used by database designers as a blueprint for
implementing data in specific software applications.
● The database designer gains a better understanding of the ERD and allows
you to communicate with the logical structure of the database to users.

USES OF ENTITY RELATIONSHIP DIAGRAMS :


1.Database Design:
ER diagrams are used to model and design relational databases, in terms of logic
and business rules (in a logical data model) and in terms of the specific
technology to be implemented (in a physical data model.) In software
engineering, an ER diagram is often an initial step in determining requirements
for an information systems project. It’s also later used to model a particular
database or databases. A relational database has an equivalent relational table and
can potentially be expressed that way as needed.

2. Database Troubleshooting:
ER diagrams are used to analyze existing databases to find and resolve problems
in logic or deployment. Drawing the diagram should reveal where it’s going
wrong.

3. Business Information System:


The diagrams are used to design or analyze relational databases used in business
processes. Any business process that uses fielded data involving entities, actions
and interplay can potentially benefit from a relational database. It can streamline
processes, uncover information more easily and improve results.

4. Business Process re-engineering (BPR):


ER diagrams help in analyzing databases used in business process re-engineering
and in modeling a new database.

5. Education:
Databases are today’s method of storing relational information for educational
purposes and later retrieval, so ER Diagrams can be valuable in planning those
data structures.

6. Research:
Since so much research focuses on structured data, ER Diagram can play a key
role in setting up a useful database to analyze the data.

The Components and Features of an ER Diagram:


ER Diagrams are composed of entities, relationships and attributes. They also
depict cardinality, which defines relationships in terms of numbers. Entity A
definable thing—such as a person, object, concept or event—that can have data
stored about it. Think of entities as nouns. Examples: a customer, student, car or
product. Typically shown as a rectangle.

Entity type:
A group of definable things, such as students or athletes, whereas the entity
would be the specific student or athlete. Other examples: customers, cars or
products.
Entity set: Same as an entity type, but defined at a particular point in time, such
as students enrolled in a class on the first day. Other examples: Customers who
purchased last month, cars currently registered in Germany. A related term is
instance, in which the specific person or car would be an instance of the entity
set.

Entity categories:
Entities are categorized as strong, weak or associative. A strong entity can be
defined solely by its own attributes, while a weak entity cannot. An associative
entity associates entities (or elements) within an entity set.

Entity keys:
Refers to an attribute that uniquely defines an entity in an entity set. Entity keys
can be super, candidate or primary. Super key: A set of attributes (one or more)
that together define an entity in an entity set. Candidate key: A minimal super
key, meaning it has the least possible number of attributes to still be a super key.
An entity set may have more than one candidate key. Primary key: A candidate
key chosen by the database designer to uniquely identify the entity set. Foreign
key: Identifies the relationship between entities.

Relationship:
How entities act upon each other or are associated with each other. Think of
relationships as verbs. For example, the named student might register for a
course. The two entities would be the student and the course, and the relationship
depicted is the act of enrolling, connecting the two entities in that way.
Relationships are typically shown as diamonds or labels directly on the
connecting lines.
Recursive relationship:
The same entity participates more than once in the relationship.

Cardinality views:
Cardinality can be shown as look-across or same-side, depending on where the
symbols are shown.

Cardinality constraints:
The minimum or maximum numbers that apply to a relationship.

SYMBOL TABLE:

It is an important data structure created and maintained by the compiler in order


to keep track of semantics of variables i.e. it stores information about scope and
binding information about names, information about instances of various entities
such as variable and function names, classes, objects, etc.

● It is built in lexical and syntax analysis phases.

● The information is collected by the analysis phases of the compiler and is used
by synthesis phases of the compiler to generate code.

● It is used by compilers to achieve compile time efficiency.

It is used by various phases of the compiler as follows :-

Lexical Analysis: Creates new table entries in the table, examples like entries
about tokens.

Syntax Analysis: Adds information regarding attribute type, scope, dimension,


line of reference, use, etc in the table.

Semantic Analysis: Uses available information in the tab to check for semantics
i.e. to verify that expressions and assignments are semantically correct(type
checking) and update it accordingly.

Intermediate Code generation: Refers symbol table for knowing how much and
what type of run-time is allocated and the table helps in adding temporary
variable information.

Code Optimization: Uses information present in the symbol table for machine
dependent optimization.

Target Code generation: Generates code by using address information of the


identifier present in the table.
Operations of Symbol table –
The basic operations defined on a symbol table include:

LEARNING :
We've studied about the Entity-Relationship diagram . We also learnt about the
uses of entity-relationship diagrams along with its advantages.Also learnt about
the components and features of entity-relationship diagrams.

CONCLUSION :
Entity-Relationship Diagram is a great tool to represent the relational model and
schema.ER diagram helps us to find the relation between various entities and at
the same time define various attributes for each entity.
EXPERIMENT-4

AIM: Introduction to different types of constraint in SQL.

THEORY :
Constraints are the rules that we can apply on the type of data in a table. That is,
we can specify the limit on the type of data that can be stored in a particular
column in a table using constraints.
The available constraints in SQL are:

● NOT NULL:
This constraint tells us that we cannot store a null value in a column. That is, if a
column is specified as NOT NULL then we will not be able to store null in this
particular column any more.

● UNIQUE:
This constraint, when specified with a column, tells that all the values in the
column must be unique. That is, the values in any row of a column must not be
repeated.

● PRIMARY KEY:
A primary key is a field which can uniquely identify each row in a table. And this
constraint is used to specify a field in a table as the primary key.

● FOREIGN KEY:
A Foreign key is a field which can uniquely identify each row in another table.
And this constraint is used to specify a field as Foreign key.

● CHECK:
This constraint helps to validate the values of a column to meet a particular
condition. That is, it helps to ensure that the value stored in a column meets a
specific condition.

● DEFAULT:
This constraint specifies a default value for the column when a: value is specified
by the user.

NOT NULL:
Ensures that a column cannot have NULL value. By default, a column can hold
NULL values. If we don't enter any value in a particular column, it will store
NULL if the default value has not been specified. The NULL value is omitted in
various operations in a database. To ensure that a column does not contain a
NULL value, NOT NULL constraint is used. NOT NULL constraint makes sure
that a column does not hold NULL value. When we don't provide a value for a
particular column while inserting a record into a table, it takes a NULL value by
default. By specifying NULL constraint, we can be sure that a particular
column(s) cannot have NULL values.

UNIQUE :
Ensures that all values in a column are different. UNIQUE constraint
ensures that all the values stored in a column are different from each other. The
UNIQUE Constraint prevents two records from having identical values in a
column, i.e., the values must not be repeated. UNIQUE Constraint enforces a
column or set of columns to have unique values. If a has a unique constraint, it
means that particular column cannot have a duplicate value table.

DEFAULT :
Provides a default value for a column when none is specified. DEFAULT
constraint is used to
provide a default value for the fields of a table. The DEFAULT Constraint is used
to fill a column
with a default and fixed value. The value will be added to all new records when
no other value is
provided.

CHECK :
The CHECK constraint is used to limit the value range that can be placed in a
column. If you define a CHECK constraint on a single column it allows only
certain values for this column. If you define a CHECK constraint on a table it can
limit the values in certain columns based on values in other columns in the row.

PRIMARY KEY :
Uniquely identifies each row/record in a database table. A primary key constraint
uniquely identifies each row/record in a database table. Primary keys must
contain unique values. A primary key column cannot have NULL values. A table
can have only one primary key, which may consist of single or multiple fields.
When multiple fields are used as a primary key, they are called a composite key.

The field with a PRIMARY KEY constraint can be used to uniquely identify each
record of a table in various database operations.

This query will create a table Employees(Emp_Id, Emp_Name and Salary) with
Emp_Id field as PRIMARY KEY constraint.
To create a PRIMARY KEY constraint on the “EMP_ID” column when
Employees table already exists, use the following SQL syntax:

To drop PRIMARY KEY Constraints from a table :

FOREIGN KEY:
Uniquely identifies a row/record in any of the given database tables. Foreign Key
Constraint is used to link two tables. It is used to establish a relationship between
the data in two tables. A Foreign Key is a column or a combination of columns
whose values match a Primary Key in a different table. The table containing the
FOREIGN KEY is called the child table, and the table containing the candidate
key is called the parent table. FOREIGN KEY is used to enforce referential
integrity. It is used to prevent actions that would destroy links between tables. It
also prevents invalid data from being inserted into the foreign key column,
because it has to be one of the values contained in the table it points to.
This query creates a table Employees(Emp_Id, Emp_Name and Dept_Id) with
Dept_Id as FOREIGN KEY which links the Employees table to the Department
table.

To create a FOREIGN KEY constraint on the “Dept_Id” column when


Employees table already exists, use the following SQL syntax:

To drop FOREIGN KEY Constraints from a table :

KEY CONSTRAINTS :
● DOMAIN CONSTRAINTS: A set of rows and columns that contain data
Columns in the tables have a unique name, often referred to as attributes in
DBMS. A domain is a unique set of values permitted for an attribute in a
table. Domain constraints are user defined data type and we can define
them like this:

Domain Constraint = data type + Constraints (NOT NULL / UNIQUE /


PRIMARY KEY / FOREIGN KEY / CHECK / DEFAULT)

Example:
For example I want to create a table “student_info” with “stu_id” field having
value greater than 100, I can
create a domain and table like this:
INTEGRITY CONSTRAINT :
Integrity constraints are used to ensure accuracy and consistency of the data in a
relational database. Data integrity is handled in a relational database through the
concept of referential integrity. There are many types of integrity constraints that
play a role in Referential Integrity (RI). These constraints include Primary Key,
Foreign Key, Unique Constraints and other constraints which are mentioned
above.

LEARNING:
Learnt about different types of constraints in SQL with examples of commands
for each constraint.

CONCLUSION::
Constraints are the rules enforced on the data columns of a table. These are used
to limit the type of data that can go into a table. The purpose of constraints is to
maintain the data integrity during an update/delete/insert into a table.
EXPERIMENT-5

AIM :
CASE STUDY 1: Hospital Management System.

THEORY :
A good Hospital management system will help to keep account of immense data
related to its patients, departments, doctors, nurses and wards.

The database will have following tables :


● DEPARTMENT TABLE
It will contain dept_id, dept_name, contact_no, hod_no, hod_name.
● DOCTOR TABLE
It will contain doctor_id , doctor_name , doctor_salary , doctor_age,
doctor_gender.
● NURSE TABLE
It will contain nurse_id, nurse_name, nurse_salary, nurse_experience, nurse_age,
nurse_gender.
● WARDS TABLE
It will contain ward_id , ward_capacity , ward_quality, ward_name.
● PATIENT TABLE
It will contain patient_id , patient_name , patient_age, patient_gender, p_ward_id.

ASSUMPTIONS :

● A doctor may treat many patients but a single patient can be treated by
many doctors.
● A Department can have more than one doctor but a doctor can work in one
department only.
● Many patients are admitted in a single ward, each patient is admitted in
exactly one ward.
● A ward may have multiple wards but all nurses work in a specified ward
only.
● A patient may own reports from different departments.

LEARNING :
Learned about tables used to implement hospital management systems using
ER-diagrams and assumptions for the relations between different entities.

CONCLUSION :
The Hospital Management system can be implemented efficiently using the
ER-diagram with appropriate entities.
EXPERIMENT-6

AIM : Constructing Entity Relationship Diagram, Creating Entity Tables and


Relationship Tables.

ENTITIES WITH THEIR ATTRIBUTES :

● Department Table
Dept_id, contact no, dept_name, hod_name, hod_id
● Doctor Table
Doctor_id, doctor_name, doctor_age, doctor_salary, doctor_experience,
doctor_contact.
● Patient Table
patient_id, patient_name, patient_age.
● Ward Table
ward_id , ward_name , ward_capacity, ward_quality.
● Nurses Table
Nurse_id, nurse_name , nurse_experience, nurse_age, nurse_salary.

RELATIONSHIP BETWEEN DIFFERENT ENTITIES :

● Doctors:Departments(1:N)
● Nurse:Patients(1:N)
● Doctor:Patients(1:N)
● patient:ward(1:N)
● Nurses:Wards(M:N)

LEARNING :
Learned to implement the hospital management system using an ER diagram.
Also learnt how to allocate attributes to each entity and how to define
relationships between different entities.
CONCLUSION :
We successfully implemented the hospital management system using ER-diagram
and defined relations between different entities along with relation types.
TABLES (Pre-Requisite Data)

Department Table
create table department_266( dept_id int primary key, dept_name varchar(40) not
null, dept_hod_name varchar(40) not null, dept_contact int not null);
desc department_266;

Doctor Table
create table doctor_266(doctor_id int primary key,doctor_name varchar(40) not
null,doctor_salary int,doctor_gender varchar(10) not null,doctor_experience int not
null,doctor_specialisation varchar(40) not null);
desc doctor_266;

Patients Table
create table patients_266(patient_id int primary key,patient_name varchar(40) not
null,patient_gender varchar(10) not null,patient_age int not null,ward_id int);
desc patients_266;
Wards Table
create table wards_266(ward_id int primary key,ward_name varchar(40) not
null,ward_capacity int not null);
desc wards_266;

Nurses Table
create table nurses_266(nurse_id int primary key,nurse_name varchar(40) not null,
nurse_salary int,nurse_gender varchar(10) not null,nurse_experience int not null,
nurse_age int not null,nurse_contact int not null);
desc nurses_266;

Bill Table
create table bill_266(bill_id int primary key,patient_id int not null,doctor_id int not
null,ward_id int, bill_amount int not null);
desc bill_266;

WorksAt Table
create table worksat ( ward_id INT, nurse_id INT, PRIMARY KEY(ward_id,
nurse_id), FOREIGN KEY(ward_id) REFERENCES wards_266(ward_id) ON
DELETE CASCADE,FOREIGN KEY(nurse_id) REFERENCES
nurses_266(nurse_id) ON DELETE CASCADE);
desc worksat;
EXPERIMENT-7

AIM : Implementing DDL and DML commands.

THEORY :
DDL COMMANDS
In SQL, DDL means Data Definition Language. The Sql Server DDL commands are
used to create and modify the structure of a database and database objects.
CREATE :
Creates a database, table, triggers, index, functions, stored procedures, etc.
create table department_266( dept_id int primary key, dept_name varchar(40) not
null, dept_hod_name varchar(40) not null, dept_contact int not null);

DROP :
This SQL DDL command helps to delete objects. For example, delete tables, delete a
database, etc.
create table testing_table266 (test_id int, name varchar(20));
desc testing_table266;

drop table test_table266;


ALTER :
Used to alter the existing database or its object structures.
alter table patients_266 add(doctor int);
alter table patients_266 add foreign key(doctor) references doctor_266(doctor_id)
on delete set Null;

RENAME : Renaming the database objects.


rename worksat to works_At_266;
desc works_At_266;

TRUNCATE :
This SQL DDL command removes records from tables.
truncate table doctor_266;

DML COMMANDS
● DML means Data Manipulation Language in Sql Server. As its name suggests,
these Sql Server DML commands will perform data manipulation manipulate data
presented in the server).
SELECT :
This SQL DML command selects records or data from a table.

select * from doctor_266;


INSERT :
Insert data into a database table.

UPDATE :
This SQL DML command will update existing records within a table

update doctor_266 set doctor_contact=9654782210 where doctor_id=2;

DELETE :
Delete unwanted records from a table.

delete from doctor_266 where doctor_experience<3;


LEARNING :
Learned about DDL (data definition language) and DML(Data manipulation
language) . Also implemented the commands like create, select, insert, rename,
update etc. with the help of MYSQL.

CONCLUSION :
To implement the tables and manage the data in MYSQL , DDL and DML commands
are very important . DDL commands help to define the data and create tables, DML
commands help to manipulate the data and update it according to convenience of the
user. Hence, we can conclude that these commands are essential in DBMS.
EXPERIMENT-8

AIM : Implementation of simple Queries.

THEORY :
Simple Queries in SQL involves :
1. SQL Queries using logical operators and operations.
2. SQL Query using group by functions.
3. SQL Query for group by functions.

● SQL Queries using logical operators and operations.


An operator is a reserved word or a character used primarily in an SQL statement
WHERE clause to perform operation(s), such as comparisons and arithmetic
operations. These Operators are used to specify conditions in an SQL statement and
to serve as conjunctions for multiple conditions in a statement.
➔ Arithmetic operators
➔ Comparison operators
➔ Logical operators
➔ Operators used to negate conditions

Pre-requisite data :
DEPARTMENT TABLE
Queries
1.Name of the hod of the department whose dept_id is between
200 and 500.

select dept_head_name from department_266 where dept_id>200 and


dept_id<500;

2. Name of the department whose dept_name has the prefix “Or”.

select dept_name from department_266 where dept_name like 'Or%';

● SQL Query using group by functions.


The GROUP BY statement is often used with aggregate functions (COUNT, MAX,
MIN, SUM, AVG) to group the result-set by one or more columns.
Group BY syntax :
DEPARTMENT TABLE used for implementing query

QUERY
select count(doctor_id), doctor_specialisation from doctor_266 group by
doctor_specialisation;

● SQL Query for group by functions.


An SQL group function or aggregate functions performs an operation on a group of
rows and returns a single result. You may want to retrieve a group of item-prices and
return the total price. This type of scenario is where you would use a group function.
The following table is a summary of some SQL group function & query examples.
Pre-requisite Data :
Wards Table

Queries
1.Total capacity of all the wards combined.
select sum(ward_capacity) from wards_266;
2.Average capacity of all the wards in the hospital

3.Maximum capacity of a ward in the hospital

4.Minimum capacity of a ward in the hospital.

LEARNING :
Learned about different types of simple queries like using logical operators , group by
and aggregate functions and used oracle tables and commands to implement these
queries taking examples of tables from the university management system analyzed
earlier.

CONCLUSION :
Implementation of simple queries with the help of operators , group by and aggregate
functions is very necessary to completely understand and get grasp on basic concepts
before moving to complex queries and joins.
EXPERIMENT-9

AIM : Implementation of JOINS.

THEORY :
A JOIN clause is used to join rows from two or more tables together based on a
related column. To merge records from two or more tables in a database, use the SQL
Joins clause. A JOIN is a method of joining fields from two tables by using values
that are shared by both.
A SQL join clause combines columns from one or more tables in a relational
database. It creates a set that can be saved as a table or used as it is. A JOIN is a
means for combining columns from one (self-table) or more tables by using values
common to each. ANSI-standard SQL specifies five types of JOIN: INNER, LEFT
OUTER, RIGHT OUTER, FULL OUTER and CROSS. As a special case, a table
(base table, view, or joined table) can JOIN to itself in a self-join.
A programmer declares a JOIN statement to identify rows for joining. If the
evaluated
predicate is true, the combined row is then produced in the expected format, a row set
or a temporary table.
1.INNER JOIN
INNER JOIN returns records that have matching values in both Tables.

Syntax :
Table :

Final Table after implementation of INNER JOIN :

select * from patients_266 join wards_266 on patients_266.ward_id =


wards_266.ward_id;

2.LEFT JOIN
LEFT(OUTER) JOIN returns all records from the left table, and
the matched records from the right table.
Syntax :

Final Table after implementation of LEFT JOIN :

select * from patients_266 left join wards_266 on patients_266.ward_id =


wards_266.ward_id;

3. RIGHT JOIN
RIGHT JOIN returns all records from the right table, and the matched Records.

Syntax :
select * from patients_266 right join wards_266 on patients_266.ward_id =
wards_266.ward_id;

Table :

4. FULL JOIN
FULL JOIN returns all records when there is a match in either the left or the right
table. A FULL JOIN returns all the rows from the joined tables, whether they are
matched or not i.e. you can say a full join combines the functions of a LEFT JOIN
and a RIGHT JOIN. Full join is a type of outer join that's why it is also referred to as
full outer join.

Syntax :

select * from patients_266 full outer join wards_266 on patients_266.ward_id =


wards_266.ward_id;
Table :

LEARNING : Learned about working of various types of joins namely-inner join ,


left join , right join and full join. Also learned about their syntax and implementation.

CONCLUSION : Implementation of joins is very important because joins are used


to stitch the database back together to make it easy to read and use. Also joins helps
to reduce duplicate records in combinational results.
EXPERIMENT-10

Aim: Implementation of Aggregate functions.

Theory :

An SQL group function or aggregate functions performs an operation on a group


of rows and returns a single result. You may want to retrieve a group of
item-prices and return the total price. This type of scenario is where you would
use a group function. The following table is a summary of some SQL group
function & query examples.

Pre-requisite Data :

Count Command-Query
select count(patient_id), ward_id from patients_266 group by ward_id;
Pre-requisite Data :

Progress_report table

select * from wards_266;

Queries

1. Count Command-Query

select sum(ward_capacity) from wards_266;

2.Average marks scored by the class out of 100.

select avg(ward_capacity) from wards_266;

3.Maximum Marks scored by a student in the class.

select max(ward_capacity) from wards_266;


4.Minimum Marks scored by a student in the class.

select min(ward_capacity) from wards_266;

● Date and Time Queries

SQL Server comes with the following data types for storing a date or a date/time
value in the database:

select sysdate from dual;

select to_char(sysdate, 'Dy-Mon-YYYY HH12:MI:SS') as "Current Time" from


dual;
● String Queries

Table used

➔ Substring query ( SUBSTR() )

select dept_name, substr(dept_name, 1, 4) from department_266;

Output :

➔ Lower string query ( LOWER() )

select dept_name, lower(dept_name) from department_266;

Output :
➔ Length of string query (LENGTH())

select dept_name, length(dept_name) from department_266;

Output :

Learning :

Learned about aggregate function , date and time Queries and string queries with
proper implementation.

Conclusion :

Aggregate function,Date and time queries and String queries are important and
simple queries. These can be easily implemented using sql database.
EXPERIMENT-11

Aim : Implementation of Grant and revoke statements, views, and triggers.

Theory :

⮚ GRANT AND REVOKE

Data Control Language (DCL) is used to manage database rights. A user must
have rights to do any activity in the database, such as creating tables, sequences,
or views. GRANT and REVOKE commands are used to manage these
privileges. Only the database administrator has the authority to grant or revoke
these rights.

⮚ GRANT
GRANT is used to grant users access such as Select, All, and Execute on
database objects such as Tables, Views, Databases, and other objects in a SQL
Server.
⮚REVOKE

REVOKE is used to revoke a user's permissions or privileges on database


objects that were set by the Grant command.

⮚VIEW
In SQL, views are referred to as virtual tables. Rows and columns are also part
of a view. To build the view, we may choose fields from one or more tables in
the database. A view can contain either particular rows depending on criteria or
all of the rows in a table.

The Construct VIEW command may be used to create views.

1. Create a view:

2. Select view:
⮚TRIGGER
A trigger is a piece of procedural code, similar to a stored procedure, that is only
performed when a specific event occurs. A trigger can be triggered by a variety
of actions, such as adding, removing, or modifying a record.
To create a new trigger, use the CREATE TRIGGER command.
Triggers are classified into two types: before triggers, which execute the triggers
before the action is completed, and after triggers, which run the triggers after the
action is completed.

1. To create triggers:
2. To insert values in triggers

Learning :

Learned about grant and view command , view command and triggers.

Conclusion :

We learnt about the grant and revoke functions and how they work as a result of
this project. We also built views, learned how the trigger works, and successfully
implemented it in our hospital management system.

You might also like