You are on page 1of 48

DELHI TECHNOLOGICAL UNIVERSITY

DEPARTMENT OF COMPUTER ENGINEERING

LAB FILE
DBMS
CO-202

Submitted by Submitted to
Kaustubh Reet Prof. Indu Singh
Roll No: 2K20/CO/231 COE Department
Batch: A4
CONTENTS
S.NO NAME OF EXPERIMENTS DATE OF SUBMISSION SIGNATURE

1 introduction to DBMS,DATABASE AND SQL 17/01/2022

2 Introduction to various software in DBMS and 24/01/2022


database languages.

3 introduction to ER diagram symbol table 31/01/2022

4 introduction to different types of constraint in SQL 7/02/2022

5 case study: University management system 14/02/2022

6 entity relationship diagram, creating entity tables 21/02/2022


and relationship tables

7 implementing DDL and DML commands 7/03/2022

8 performing simple queries 21/03/2022

9 implementation of joins 4/04/2022

10 implementation of Aggregate Queries, Date 11/04/2022


Queries and String Queries.

11 To implement grant and revoke statements, views, 18/04/2022


and triggers on university management system
Experiment-1
Aim: Introduction to SQL, DATABASE AND DATABASE MANAGEMENT
SYSTEM.
THEORY:
SQL:
Basically, SQL stands for Structured Query Language which is basically a language used by
databases. This language allows to handle the information using tables and shows a language
to query these tables and other objects related (views, functions, procedures, etc.). Most of
the databases like SQL Server, Oracle, PostgreSQL, MySQL, MariaDB handle this language
to handle the data.
SQL uses the terms table, row, and column for the formal relational model terms relation,
tuple, and attribute, respectively. The main SQL command for data definition is the
CREATE statement, which can be used to create schemas, tables (relations), types, and
domains, as well as other constructs such as views, assertions, and triggers.

SQL CAN DO
□ SQL can execute queries against a database
□ SQL can retrieve data from a database
□ SQL can insert, update, delete records in a database
□ SQL can create new databases
□ SQL can create new tables in a database
□ SQL can create stored procedures in a database
□ SQL can create views in a database
□ SQL can set permissions on tables, procedures, and views

Some of The Most Important SQL Commands


□ SELECT - extracts data from a database
□ UPDATE - updates data in a database
□ DELETE - deletes data from a database
□ INSERT INTO - inserts new data into a database
□ CREATE DATABASE - creates a new database
□ ALTER DATABASE - modifies a database
□ CREATE TABLE - creates a new table
□ ALTER TABLE - modifies a table
□ DROP TABLE - deletes a table

Database:
A database is an organized collection of data, so that it can be easily accessed and managed.
We can organize data into tables, rows, columns, and index it to make it easier to find
relevant information.

A database has the following implicit properties:

 A database represents some aspect of the real world, sometimes called the miniworld or
the universe of discourse (UoD). Changes to the miniworld are reflected in the database
o A database is a logically coherent collection of data with some inherent meaning. A
random assortment of data cannot correctly be referred to as a database.
 A database is designed, built, and populated with data for a specific purpose. It has an
intended group of users and some preconceived applications in which these users are
interested.
Database management system:
A database management system (DBMS) is a computerized system that enables users to
create and maintain a database. The DBMS is a general-purpose software system that
facilitates the processes of defining, constructing, manipulating, and sharing databases
among various users and applications. Defining a database involves specifying the data types,
structures, and constraints of the data to be stored in the database. The database definition or
descriptive information is also stored by the DBMS in the form of a database catalog or
dictionary; it is called meta-data. Sharing a database allows multiple users and programs to
access the database simultaneously.

Data Definition: helps in creation, modification and removal of definition that define the
organization of data in database.

Data updation: helps to insertion, modification and deletion of the actual data in the
database.

Data Retrieval: helps in retrieval of data from database which can be used by application
for various purposes.

User Administration: helps in registering and monitoring users, enforcing data security,
monitoring performance, maintaining data integrity, dealing with concurrency control and
recovering information corrupted by unexpected failure.
The main characteristics of the database approach are:

o Self-describing nature of a database system


o Insulation between programs and data, and data abstraction
o Support of multiple views of the data
o Sharing of data and multiuser transaction processing
o DBMS allows entities and relations among them to form tables.

Advantages of DBMS
 Controlling Redundancy
 Restricting Unauthorized Access
 Providing Persistent Storage for Program Objects
 Providing Storage Structures and Search Techniques for Efficient Query Processing
 Providing Backup and Recovery
 Providing Multiple User Interfaces
 Representing Complex Relationships among Data
 Enforcing Integrity Constraints
 Permitting Inferencing and Actions Using Rules and Triggers
Experiment-2
Aim: Introduction to various software of database management system and data
base language.
Theory:
DBMS Software:
 Mysql
 Microsoft Access
 Oracle
 PostgreSQL
 dBASE
 SQLite
 IBM DB2
 LibreOffice Base
 MarieDB
 Microsoft SQL Server etc.

Mysql
MySQL is a relational database management system (RDBMS) based on the SQL (Structured
Query Language) queries. It is one of the most popular languages for accessing and
managing the records in the table. MySQL is open-source and free software under the GNU
license. Oracle Company supports it. SQL is a language programmers use to create, modify
and extract data from the relational database, as well as control user access to the database. In
addition to relational databases and SQL, an RDBMS like MySQL works with an operating
system to implement a relational databasein a computer's storagesystem, managesusers, allows
fornetwork access and facilitates testing database integrity and creation of backups.
Oracle
Oracle Database (Oracle DB) is a relational database management system (RDBMS) from
Oracle Corporation. Originally developed in 1977 by Lawrence Ellison and other developers,
Oracle DB is one of the most trusted and widely used relational database engines for storing,
organizing and retrieving data by type while still maintaining relationships between the
various types.

Oracle DB is also known as Oracle RDBMS and, sometimes, simply as Oracle.

SQLite
SQLite is a relational database management system (RDBMS) contained in
a C library. In contrast to many other database management systems, SQLite is not a client–
server database engine. Rather, it is embedded into the end program.
SQLite generally follows PostgreSQL syntax but does not enforce type checking. This
means that one can, for example, insert a string into a column defined as an integer.

PostgreSQL
PostgreSQL is a powerful, open-source object-relational database system that uses and extends
the SQL language combined with many features that safely store and scale the most
complicated data workloads. PostgreSQL has earned a strong reputation for its proven
architecture, reliability, data integrity, robust feature set, extensibility, and the dedication of the
open-source community behind the software to consistently deliver performant and innovative
solutions.

IBM DB2
IBM Db2 is a family of data management products, including the Db2 relational database.
The products feature AI-powered capabilities to help you modernize the management of both
structured and unstructured data across on-premises and multi- cloud environments.
Db2 Database is a relational database that delivers advanced data management and analytics
capabilities for transactional workloads. This operational database is designed to deliver high
performance, actionable insights, data availability and reliability, and it is supported across
Linux, Unix and Windows operating systems.
dBASE
Data storage in DBase format is widely accepted and supported by numerous database
management systems. DBase uses procedural functions and commands similar to the BASIC
language. It uses simple commands for data manipulation like USE and GO TOP to traverse
records, STR() and SUBSTR() for string manipulation, and REPLACE AND STORE for
field value manipulation. Other commands like STORE, DO, APPEND, and MODIFY are
also used.

DBase has many outstanding features that contribute to its prominence among database
management systems and tools, such as: A just in time (JIT) compiler, which converts the source
language into machine language
□ A linker to create DBase applications (.exe files)
□ A runtime engine installer for Web servers and machines that need to execute DBase
runtime applications
□ Preprocessors for reading the program source file and producing
preprocessed files as output, which is fed into the compiler
□ An integrated development environment with a command window and navigator
□ Two-way graphical user interface (GUI) design tools, which possess the ability to switch
back and forth between using a GUI design tool and a code editor
□ A source code editor, which allows for the manual editing and entry of code.
MariaDB
It is a fork of the MySQL database management system. The RDBMS offers data processing
capabilities for both small and enterprise tasks. This DBMS is an improved version of
MySQL. It comes with numerous inbuilt powerful features and many usability, security and
performance improvements that you cannot find in MySQL.

Benefits of using Maria DB.

□ It operates under GPL, BSD, or LGPL licenses.


□ MariaDB supports a popular and standard querying language.
□ It comes with many storage engines, including the high-performance ones that can be
integrated with other relational database management systems.
□ It offers the advance Galera cluster technology.
□ MariaDB supports PHP, a popular language for web development. Important

features of Maria DB are:

□ Offers Backward Compatibility


□ Open-source Software
□ It is based on the MySQL Community Version
□ New Storage Engine (PBXT, XtraDB, Maria, FederatedX)
□ Percona Server (Based on MySQL Server, Other MySQL Fork Version)

Types of DBMS Languages:


1. Data Definition Language (DDL) − Create, Drop, Truncate, Rename.
2. Data Manipulation language (DML) − Select, Insert, Delete, Update.
3. Data Control Language (DCL) − Revoke, Grant.
4. Transaction Control Language (TCL) − Rollback, Commit.

Data Definition Language (DDL)


It is a language that allows the user to define the data and their relationship to other types of
data. The DDL commands are: Create, Alter, Rename, Drop, Truncate.

Data Manipulation Language (DML)


It is a language that provides a set of operations to support the basic data manipulation
operation on data held in the database. The DML commands are: Insert, delete, update, select,
merge, call.
Data Control Language (DCL)
DCL is used to access the stored data. It is mainly used for revoke and grant the user access to a
database. The DCL commands are: Grant, Revoke.

Transaction Control Language (TCL)


TCL is a language which manages the transactions within the database. It is used to execute the
changes made by the data manipulation language statements. The TCL commands are: Commit,
Rollback.

FINDING/LEARNING:
We learned about different types of software used for storing the database and how they use the
query language. We have seen the advantages and features of databases.

Conclusion:
Oracle is a popular and widely used software which supports all 4 types of languages. All
databases have their own features, security, popularity, languages used, hence we can’t say that
only one dbms software will work best on every server.
Experiment-3
Aim: Introduction to ER diagram and symbol tables.
Theory:
ER Diagram stands for Entity Relationship Diagram, also known as ERD is a diagram that
displays the relationship of entity sets stored in a database. In other words, ER diagrams help
to explain the logical structure of databases. ER diagrams are created based on three basic
concepts: entities, attributes and relationships.

ER Modeling helps to analyze data requirements systematically to produce a well-designed


database. So, it is considered a best practice to complete ER modeling before implementing
database.

Example: ER Diagram of Company


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
An entity may be an object, place, person, or an event which stores data in the database. In
an entity-relationship diagram, an entity is represented by a rectangle. Student, course,
manager, employee, patient, etc. are examples of an entity.
Entity type: An entity type is a collection or a set of entities having some common attributes.
In a database, each entity type is described by a name and list of attributes.
Entity set: It is a set (or collection) of entities of the same type which
share the similar properties, or attributes. An entity can be characterized into two types:
1. Strong entity: This type of entity has a primary key attribute which uniquely
identifies each record in a table. In the ER diagram, a strong entity is usually
represented by a single rectangle.
2. Weak entity: An entity does not have a primary key attribute and depends on
another strong entity via foreign key attribute. In the ER diagram, a weak entity is
usually represented by a double rectangle.

2. Attributes
An attribute in an Entity-Relationship Model describes the properties or characteristics of an
entity. It is represented by an oval or ellipse shape in the ER diagram. Every oval shape
represents one attribute and is directly connected to its entity which is in the rectangle in shape.
In the ER model, an attribute can be characterized into the following types:
1. Simple attribute: An attribute which contains an atomic value and cannot be
divided further is called a simple attribute. For example Salary of a person. It is also
represented by an oval.
2. Key attribute: An attribute which can uniquely identify an entity in an entity set is
called a key attribute. It represents a primary key in the ER diagram. In an Entity-
Relationship diagram, the key attribute is denoted by an oval with an underlying line.
3. Composite attribute: An attribute which is a combination of two or more simple
attributes is called a composite attribute. In an Entity- Relationship diagram, it is
represented by an ellipse, and that ellipse comprises of other ellipses.
4. Derived attribute: An attribute which can be derived from other attributes is
called a derived attribute. In an entity-relationship diagram, these attributes are
represented by a dashed oval shape.
5. Multi-valued attribute: An attribute which contains more than one value for a
given entity.
Following are the main components and its symbols in ER Diagrams:

 Rectangles: This Entity Relationship Diagram symbol represents entity types


 Ellipses: Symbol represent attributes
 Diamonds: This symbol represents relationship types
 Lines: It links attributes to entity types and entity types with other
relationship types
 Primary key: attributes are underlined
 Double Ellipses: Represent multi-valued attributes

Advantages of ER diagram:
 Conceptually it is very simple
 Better visual representation
 Effective communication tool
 Highly integrated with relational model
 Easy conversion to any data model

Disadvantage of ER Diagram
 Loss of information content
 Limited relationship representation
 No representation of data manipulation
 Popular for high level design

LEARNING AND FINDINGS:


 We learned about ER diagrams its components, advantages of using an ER diagram,
meaning of symbols used in ER diagram.
 We learned about types of relationships and cardinalities.

RESULT:
We learned about Entity Relationship Model, what its importance and where we can use it.
Experiment-4
AIM: Introduction to different types of constraints 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 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 anymore.
□ 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 value for a particular column while inserting a record into a table, it takes
NULL value by default. By specifying NULL constraint, we can be sure that a particular
column(s) cannot have NULL values.
Example:
CREATE TABLE STUDENT (
ROLL_NO INT NOT NULL,
STU_NAME VARCHAR (35) NOT NULL,
STU_AGE INT NOT NULL)
UNIQUE:
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. It enforces a column or set of columns to
have unique values. If a has a unique constraint, it means that column cannot have a
duplicate value table.

CREATE TABLE PERSONS ( ID


INT NOT NULL UNIQUE,
LASTNAME VARCHAR(255) NOT NULL, FIRSTNAME
VARCHAR(255) );

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.
Example:

CREATE TABLE PERSONS ( ID


NUMBER NOT NULL, NAME
VARCHAR(255),
COUNTRY VARCHAR(255) DEFAULT ‘INDIA’
);

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.
Example:

CREATE TABLE PERSONS ( ID


INT NOT NULL,
LASTNAME VARCHAR(255) NOT NULL, FIRSTNAME
VARCHAR(255),
AGE INT,
CHECK (AGE>=18));
PRIMARY KEY:
Primary Key is a field which uniquely identifies each row in the table. If a field in a
table as primary key, then the field will not be able to contain NULL values as well as
all the rows should have unique values for this field. So, in other words we can say that
this is combination of NOT NULL and UNIQUE constraints.
A table can have only one field as primary key. Below query will create a table named
Student and specifies the field ID as primary key.

CREATE TABLE STUDENT(


ID NUMBER NOT NULL UNIQUE,
NAME VARCHAR(10),
ADDRESS VARCHAR(20),
PRIMARY KEY(ID)
);

FOREIGN KEY:
Foreign Key is a field in a table which uniquely identifies each row of another table.
That is, this field points to primary key of another table. This usually creates a kind of
link between the tables.

CREATE TABLE Employees (


Emp_Id NUMBER PRIMARY
KEY, Emp_Name VARCHAR(30),
Dept_Id INT(5) REFERENCES
Department(Dept_Id)
);

This query creates a table Employees (Emp_Id, Emp_Name and Dept_Id) with
Dept_Id as FOREIGN KEY which links Employees table to Department table.

Domain Constraints
Domain Constraints are user-defined columns that help the user to enter the value
according to the data type. And if it encounters a wrong input it gives the message to
the user that the column is not fulfilled properly. Or in other words, it is an attribute
that specifies all the possible values that the attribute can hold like integer, character,
date, time, string, etc. It defines the domain or the set of values for an attribute and
ensures that the value taken by the attribute must be an atomic value(Can’t be divided)
from its domain.

Integrity Constraints:
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.

RESULT:
After completing this experiment, we get to learn the different SQL constraint.
Experiment:5
AIM: Case Study on University Management System.
THEORY:
A good University management system will help to keep account of immense data
related to a university, its students, departments, courses offered, subjects and faculty.
The database will have the following tables:
1. COLLEGE TABLE
It will maintain the information about the college like college_id, college_name,
address, contact_no.

2. DEPARTMENT TABLE
It will maintain information about the departments like dept_id, dept_name,
contact_no, hod_no and dept_hod.

3. STUDENT TABLE
It will maintain information about students like stud_id, stud_name, contact_no
admission_year and year.

4. COURSES TABLE
It will maintain information about the courses like course_id, course_title and year.

5. FACULTY TABLE
It will maintain information about the faculty like fac_id, fac_name, contact_no,
qualification, address and designation

6. PROGRESS_REPORT TABLE:
It will maintain information about the reports of all the students like grade, rank and
report_id.

ASSUMPTIONS:
 A College can have many departments but a department can have only one
College.
 A department has many courses but a course has only one department.
 A Department can have more than one than one course included but
a course can only be taught by one department only.
 Many students’ studies in a single department.
 A Department can have more than one faculty member but a
faculty member can only work in one department only.
 A Faculty can teach many courses and a single course can be
taught by many faculty members.
 A student owns more than one progress report for different courses.
 Universities need to pay many staff but a staff needs to be
paid by only one department.

RESULT:
From this experiment, we learnt about the different entities and their
relationships in a University Management System.
Experiment-6
AIM: Constructing Entity Relationship diagram, creating entity tables and
relationship tables.
ER DIAGRAM:
ENTITIES:
1. STUDENT TABLE:
STU_ID, STU_NAME, STU_ADDRESS, STU_AGE, STU_YEAR.

2. FACULTY TABLE:
FACULTY_NAME, FACULTY_ID, COURSE_ID, CONTACT_NO.

3. COURSE TABLE:
COURSE_ID,COURSE_NAME.

4. SUBJECT TABLE:
SUBJECT_ID , SUBJECT_NAME, FACULTY_ID.

CARDINALITIES:
1. College:Departments – 1:M
2. Departments:Falculty – 1:M
3. Faculty:Courses – M:N
4. Departments:Courses – 1:M
5. Departments:Student – 1:N
6. Student:Progress_Report – 1:N

RELATIONSHIP TABLES:
1. HAS – Between COLLEGE and DEPARTMENTS
2. HAVE – Between DEPARTMENTS and COLLEGE
3. ENROLLED_STUDENTS – Between STUDENTS and
DEPARTMENTS.
4. TEACHES – Between FACULTY and COURSES
5. RESULT- Between STUDENT and PROGRESS_REPORT.

LEARNINGS AND FINDINGS:


We learned how to construct a Entity Relationship diagram and how to show
cardinality of relations and to decide entity tables with the help of ER diagram.
RESULT:
Using ER Diagram, we established the entities and relationship among those
entities.
Experiment-7
AIM: Implementing DDL and DML statements.
THEORY:
DDL STATEMENTS
A. CREATE TABLE: The Create Table statement is used to create a new table in
database
SYNTAX
CREATE table table_name
(COLUMN1 DATATYPE CONSTRAINTS, COLUMN2
DATATYPE)

B. ALTER TALBLE: The ALTER table statement is used to add, modify, or delete
columns in an existing table.
It is also used to add and drop various constraints on existing table.

SYNTAX
ALTER table table_name
DROP COLUMN
column_name

C. DROP TABLE: The DROP table command is used to remove a table definition
and all data, indexes, triggers, constraints, and permission specifications for that
table.

SYNTAX
DROP table table_name

D. TRUNCATE: The TRUNCATE command is used to delete all the data from an
existing table.

SYNTAX
TRUNCATE table table_name

DML STATEMENTS
A. INSERT: This command is used to insert values in an existing table.
SYNTAX
INSERT INTO table table_name
VALUES(col1value, col2value, col3value…)

B. SELECT: The SELECT statement is used to retrieve data from a table.

SYNTAX
SELECT column_name(s) FROM table_name

C. DELETE: The DELETE statement is used to delete records from a database


table.
SYNTAX
DELETE FROM
table_name WHERE
some_condition

D. UPDATE: The UPDATE statement is used to update in an existing table.

SYNTAX
UPDATE table_name
SET column1=value1, column2=value2….
WHERE some_condition

Implementing DDL statements:


1. CREATE:
Courses TABLE
DEPARTMENT TABLE

FACULTY TABLE:
STUDENT TABLE
PROGRESS_REPORT

College table
Has_dept table

HAVE_FACU table:
TEACH TABLE:

ENROLLED TABLE:

RESULT TABLE:
ALTER:

TRUNCATE:

IMPLEMENTING DML STATEMENTS:


1. INSERT:
COLLEGE TABLE:

DEPARTMENT TABLE
PROGRESS_REPORT TABLE:
INSERT INTO PROGRESS_REPORT VALUES (18 ,'B+', 5 ,17,25);

2. SELECT:

DELETE
LEARNINGS AND FINDINGS:
 We learned about creating, selecting, deleting a table and to insert
records in a database and to modify those records, delete or update
them.
 We learned to create primary keys and foreign keys in a relation.

RESULT: The DML and DDL commands were successfully understood


and implemented on University Management Database in the
experiment.
EXPERIMENT-8
AIM: To implement Simple Queries.
THEORY:
A database most often contains one or more tables. Each table is identified
by a name. Tables contain records (rows) with data.
Some database systems require a semicolon at the end of each SQL
statement. Semicolon is the standard way to separate each SQL statement in
database systems that allow more than one SQL statement to be executed in
the same call to the server.
Some simple SQL queries are:

1. select * from PROGRESS_REPORT WHERE GRADE='A+';

2. select collge_name from COLLEGE where COLLGE_NAME LIKE '%D%';


3. select COLLEGE_ID,COLLGE_NAME from COLLEGE ORDER BY
COLLEGE_ID DESC ;

4. select DEPT_NAME from DEPARTMENT WHERE HOD_NO>=(SELECT


AVG(HOD_NO) FROM DEPARTMENT);

LEARNINGS AND FINDINGS:


 We learned to implement various Simple Queries using DML
statements like SELECT statement on various relations.
 We learned how to implement aggregate functions like AVG on
relations.
 We learned how to retrieve the required records using some SQL
queries.

RESULT:
Various Simple Queries were implemented on the database and
learned the syntax for those queries in the experiment.
EXPERIMENT-9
AIM: Implementation of Joins.
THEORY:
A SQL Join statement is used to combine data or rows from two or more tables
based on a common field between them. Different types of Joins are:
1. INNER JOIN: The INNER JOIN keyword selects all rows from both the
tables if the condition satisfies. This keyword will create the result-set by
combining all rows from both the tables where the condition satisfies i.e.,
value of the common field will be same.

Inner Join

2. LEFT JOIN: This join returns all the rows of the table on the left side of the
join and matching rows for the table on the right side of join. The rows for
which there is no matching row on right side, the result-set will contain null.
LEFT JOIN is also known as LEFT OUTER JOIN.

Left Join

3. RIGHT JOIN: RIGHT JOIN is like LEFT JOIN. This join returns all the rows
of the table on the right side of the join and matching rows for the table on the
left side of join. The rows for which there is no matching row on left side, the
result-set will contain null. RIGHT JOIN is also known as RIGHT OUTER
JOIN.
Right Join

4. FULL JOIN: FULL JOIN creates the result-set by combining result of both
LEFT JOIN and RIGHT JOIN. The result-set will contain all the rows from
both the tables. The rows for which there is no matching, the result-set will
contain NULL values.

Full Join
INNER JOIN:

SYNTAX
SELECT columns FROM table1 INNER
JOIN table2 ON table1.column =
table2.column;
LEFT JOIN:

SYNTAX
SELECT columns FROM table1 LEFT JOIN
table2 ON table1.column = table2.column;

RIGHT JOIN:

SYNTAX
SELECT columns FROM table1 RIGHT
JOIN table2 ON table1.column =
table2.column;
FULL JOIN:

SYNTAX
SELECT columns FROM table1 FULL JOIN
table2 ON table1.column = table2.column;

LEARNINGS AND FINDINGS:

 We learned about various JOIN clauses and their working.


 learned how to implement various JOINS and learned their syntax.

SYNTAX
SELECT columns FROM table1 FULL JOIN
table2 ON table1.column = table2.column;

RESULT:
Various JOINS (inner, left, right, full) were implemented and were verified in
the experiment.
Experiment-10
Aim: implementation of Aggregate Queries, Date Queries and String Queries.

Theory:

Aggregate Queries:
Aggregation groups the data from multiple documents and provides the summed up results, the
average value from a large result set, min/max value from a large result set, etc.

String Queries:
SQL string functions are used primarily for string manipulation. CHAR() interprets each
argument N as an integer and returns a string consisting of the characters given by the code
values of those integers. NULL values are skipped. MID(str,pos,len) is a synonym for
SUBSTRING(str,pos,len).

Date Queries:
SQL Server comes with the following data types for storing a date or a date/time value in the
database:
 DATE - format YYYY-MM-DD
 DATETIME - format: YYYY-MM-DD HH:MI:SS
 SMALLDATETIME - format: YYYY-MM-DD HH:MI:SS
 TIMESTAMP - format: a unique number

Implementation of queries
Aggregate queries
SUM()

MAX()

MIN()
AVG()

COUNT()

ROUND_AVG()

VARIANCE()
STRING QUERIES

SUBSTR()

LOWER()

UPPER()
UPPER(),LOWER()
SQL Worksheet

LENGTH()

DATE QUERIES
SYSDATE
To_char(sysdate)

CONCLUSION:
We have learnt about different queries included aggregate queries,string queries and date
queries and implemented them using oracle software. Implemented it using queries in our
UNIVERSITY MANAGEMENT system.
Experiment-11
Aim: To implement Grant and Revoke statements, views, and Triggers on University
Management System.

Theory
Triggers
A trigger is a set of SQL statements that reside in system memory with unique names. It is a
specialized category of stored procedure that is called automatically when a database server
event occurs. Each trigger is always associated with a table.
The following are the main characteristics that distinguish triggers from stored procedures:
o We cannot manually execute/invoked triggers.
o Triggers have no chance of receiving parameters.
o A transaction cannot be committed or rolled back inside a trigger.

Benefits of Triggers
o Triggers set database object rules and roll back if any change does not satisfy those rules.
The trigger will inspect the data and make changes if necessary.
o Triggers help us to validate data before inserted or updated, enforce data integrity
o Triggers help us to keep a log of records.
o Triggers increase SQL queries' performance because they do not need to compile each time
they are executed.
o Triggers reduce the client-side code that saves time and effort.
o Triggers are easy to maintain.

Syntax
create trigger [trigger_name]
[before | after]
{insert | update | delete}
on [table_name]
[for each row]
[trigger_body]

1. CREATE TRIGGER: These two keywords specify that a triggered block is going to be
declared.
2. TRIGGER_NAME: It creates or replaces an existing trigger with the Trigger_name. The
trigger name should be unique.
3. BEFORE | AFTER: It specifies when the trigger will be initiated i.e., before the ongoing
event or after the ongoing event.
4. INSERT | UPDATE | DELETE: These are the DML operations and we can use either of
them in a given trigger.
5. ON[TABLE_NAME]: It specifies the name of the table on which the trigger is going to be
applied.
6. FOR EACH ROW: Row-level trigger gets executed when any row value of any column
changes.
7. TRIGGER BODY: It consists of queries that need to be executed when the trigger is
called.

Grant
 It is a DCL command.
 It grants permissions to users on database objects.
 It can also be used to assign access rights to users.
 For every user, the permissions need to be specified.
 When the access is decentralized, permission granting is easier.
Syntax:
grant privilege_name on object_name
to {user_name | public | role_name}

Revoke
 It is a DCL command.
 It removes permissions if they are granted to users on database objects.
 It takes away/revokes the rights of the users.
 If access for a user is removed, all specific permissions provided by that user to others will
be removed.
 If decentralized access is used, it would be difficult to remove granted permissions.
Syntax
revoke privilege_name on object_name
from {user_name | public | role_name}

Views in SQL
o Views in SQL are considered as a virtual table. A view also contains rows and columns.
o To create the view, we can select the fields from one or more tables present in the database.
o A view can either have specific rows based on certain condition or all the rows of a table.

Creating view
CREATE VIEW view_name AS
SELECT column1, column2.....
FROM table_name
WHERE condition;

Delete view
DROP VIEW view_name;

Updating Views
CREATE OR REPLACE VIEW view_name AS
SELECT column1,coulmn2,..
FROM table_name
WHERE condition;

Inserting a row in view


INSERT INTO view_name(column1, column2 , column3,..)
VALUES(value1, value2, value3..);
Deleting a row from a View
DELETE FROM view_name
WHERE condition;

GRANT USER QUERIES


CREATING USER:

GRANTING PRIVELEGES

REVOKE PRIVILEGES
VIEWS
SQL WORKSHEET

TRIGGER CREATION:
SQL Worksheet

INSERTION

TRIGGER IN ACTION
Conclusion:

As a result of this experiment, we learnt about the grant and revoke functions and how they
work. We also built views and learnt how to use triggers and successfully integrated it in our
UNIVERSITY MANAGEMENT system.

You might also like