Professional Documents
Culture Documents
43.darpan (It-2) - 09315003119 - DBMS
43.darpan (It-2) - 09315003119 - DBMS
Name: DARPAN
Class: IT-
2(4thSem)
S No. : 43
Enrollment No. : 09315003119
INDEX
S No. Experiment Date Page No.
1. Introduction to DBMS and SQL. 30/03/21 1-13
THEORY
Characteristics:
● It can provide a clear and logical view of the process that manipulates
data.
Applications:
Banking
For customer information,
account activities, payments,
deposits, loans, etc.
Airlines
For reservations and
schedule information.
Universities
For student information,
course registrations, colleges
and grades.
Telecommunication
It helps to keep call records,
monthly bills, maintaining
balances, etc.
Finance
For storing information
about stock, sales, and
purchases of financial
instruments like stocks and
bonds.
Database languages:
DATA DEFINITION LANGUAGE (DDL):
These statements are used to classify the database structure or schema. It is a
type of language that allows the DBA or user to depict and name those entities,
attributes, and relationships that are required for the application along with any
associated integrity and security constraints. Here are the lists of tasks that come
under DDL-
Data Models:
A Database model defines the logical design and structure of a database and
defines how data will be stored, accessed and updated in a database
management system. While the Relational Model is the most widely used
database model, there are other models too: -Hierarchical Model
- Network Model
- Entity-relationship Model
- Relational Model
HIERARCHIAL MODEL
This database model organises data into a tree-like structure, with a single
root, to which all the other data is linked. The hierarchy starts from the Root
data, and expands like a tree, adding child nodes to the parent nodes.
In this model, a child node will only have a single parent node.
This model efficiently describes many real-world relationships like index of a
book, recipes etc.
In hierarchical model, data is organised into treelike structure with one one-
to-many relationship between two different types of data, for example, one
department can have many courses, many professors and of-course many
students.
NETWORK MODEL
Concepts
Tables − In relational data model, relations are saved in the format of
Tables. This format stores the relation among entities. A table has rows
and columns, where rows represents records and columns represent the
attributes.
Tuple − A single row of a table, which contains a single record for that
relation is called a tuple.
Relation instance − A finite set of tuples in the relational database
system represents relation instance. Relation instances do not have
duplicate tuples.
Relation schema − A relation schema describes the relation name
tablename, attributes, and their names.
Relation key − Each row has one or more attributes, known as relation
key, which can identify the row in the relation table uniquely.
Attribute domain − Every attribute has some pre-defined value scope,
known as attribute domain.
SQL
SQL is a language to operate databases; it includes database creation,
deletion, fetching rows, modifying rows, etc. SQL is an ANSI
(American National Standards Institute) standard language, but there
are many different versions of the SQL language.
SQL is widely popular because it offers the following advantages −
• Allows users to define the data in a database and manipulate that data.
• Allows to embed within other languages using SQL modules, libraries &
pre-compilers.
EXAMPLE:-
EXAMPLE:-
EXAMPLE:-
• INSERT INTO Deposit Table:-
• INSERT INTO Branch:-
EXAMPLE:-
When to select particular column from a table.
SYNTAX:- SELECT column1, column2, ...
FROM table_name;
EXAMPLE:-
EXPERIMENT-3
AIM:- Apply the constraints like primary key, foreign key, NOT NULL to the
tables.
1) Primary Key:- A primary key is a column or a set of columns that uniquely
identifies each row in the table.
SYNTAX:-
CREATE TABLE tablename(
Primary_key_column datatype PRIMARY KEY,
…
…
);
EXAMPLE:-
2) NOT NULL:- The NOT NULL constraint is a column constraint that ensures
values stored in a column are not NULL.
SYNTAX:-
column_name data_type NOT NULL;
3) FOREIGN KEY:- A foreign key is a column or group of columns in a table
that links to a column or group of columns in another table. The foreign key
places constraints on data in the related tables, which allows MySQL to
maintain referential integrity.
SYNTAX:-
[CONSTRAINT constraint_name]
FOREIGN KEY [foreign_key_name] (column_name, ...)
REFERENCES parent_table(colunm_name,...)
[ON DELETE reference_option]
[ON UPDATE reference_option]
EXAMPLE:-
FUNCTIONING:-
INSERTION
DISPLAYING THE CONTENT
DISPLAYING
EXAMPLE:-
EXAMPLE:-
2) UPDATE statement:- The SQL UPDATE Query is used to modify the
existing records in a table.
EXAMPLE:-
3) DELETE statement:- The SQL DELETE Query is used to delete the existing
records from a table.
EXAMPLE:-
EXPERIMENT-5
AIM:- Write the queries for implementing the following functions: MAX (),
MIN (),AVG (),COUNT ().
1) MAX():-The MAX() function returns the largest value of the selected
column.
EXAMPLE:-
2) MIN():-The MIN() function returns the smallest value of the selected
column.
EXAMPLE:-
3) AVG():-The AVG() function returns the average value of a numeric column.
EXAMPLE:-
4) COUNT():-The COUNT() function returns the number of rows that matches
a specified criterion.
EXAMPLE:-
EXPERIMENT-6
AIM:- Write the queries to implement the joins.
A relational database consists of multiple related tables linking together using
common columns which are known as foreign key columns. Because of this,
data in each table is incomplete from the business perspective.
1) INNER JOIN
SYNTAX:
SELECT
select_list
FROM t1
INNER JOIN t2 ON join_condition1
INNER JOIN t3 ON join_condition2
...;
EXAMPLE:
2) LEFT JOIN
SYNTAX:
SELECT
select_list
FROM
t1
LEFT JOIN t2 ON
join_condition;
EXAMPLE:
3) RIGHT JOIN
SYNTAX:
SELECT
select_list
FROM t1
RIGHT JOIN t2 USING (column_name);
EXAMPLE:
4) CROSS JOIN
SYNTAX:
SELECT * FROM t1
CROSS JOIN t2
WHERE t1.id = t2.id;
EXAMPLE:
EXPERIMENT-7
AIM:- Write queries to implement the concept of Integrity constraints.
MySQL constraints
NOT NULL constraint – introduce you to the NOT NULL constraint and show
you how to declare a NOT NULL column or add a NOT NULL constraint to an
existing column.
Primary key constraint – guide you on how to use the primary key constraint to
create the primary key for a table.
Foreign key constraint – introduce you to the foreign key and show you step by
step how to create and drop foreign keys.
UNIQUE constraint – show you how to use UNIQUE constraint to enforce the
uniqueness of values in a column or a group of columns in a table.
CHECK constraint – learn how to create CHECK constraints to ensure data
integrity.
1) NOT NULL
2) PRIMARY KEY
3) FOREIGN KEY
4) UNIQUE
5) CHECK CONSTRAINT
EXPERIMENT-8
AIM 3:- Write queries to create the views
Table for reference:-
s1000 n n
EXPERIMENT-9
AIM:- Perform the queries for triggers
MySQL triggers
Create triggers – describe steps of how to create a trigger in MySQL.
Drop triggers – show you how to drop a trigger.
Create a BEFORE INSERT trigger – show you how to create a BEFORE
INSERT trigger to maintain a summary table from another table.
Create an AFTER INSERT trigger – describe how to create an AFTER INSERT
trigger to insert data into a table after inserting data into another table.
Create a BEFORE UPDATE trigger – learn how to create a BEFORE UPDATE
trigger that validates data before it is updated to the table.
Create an AFTER UPDATE trigger – show you how to create an AFTER
UPDATE trigger to log the changes of data in a table.
Create a BEFORE DELETE trigger – show how to create a BEFORE DELETE
trigger.
Create an AFTER DELETE trigger – describe how to create an AFTER
DELETE trigger.
1) CREATE TRIGGERS
The CREATE TRIGGER statement creates a new trigger.
2) DROP TRIGGERS
'r.'orkCentens
ro'.•‹count
20000
EXPERIMENT-10
AIM:- Perform the following operation for demonstrating the insertion ,
updation and deletion using the referential integrity constants.
1) Insertion
2) Updation
3) Deletion