0% found this document useful (0 votes)
6 views61 pages

Dbms Notes

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 61

SQL Operator

There are various types of SQL operator:

SQL Arithmetic Operators

Let's assume 'variable a' and 'variable b'. Here, 'a' contains 20 and
'b' contains 10.

Operator Description Example

+ It adds the value of both operands. a+b will give


30

- It is used to subtract the right-hand operand from the a-b will give
left-hand operand. 10

* It is used to multiply the value of both operands. a*b will give


200
/ It is used to divide the left-hand operand by the right- a/b will give
hand operand. 2

% It is used to divide the left-hand operand by the right- a%b will give
hand operand and returns reminder. 0

SQL Comparison Operators:

Let's assume 'variable a' and 'variable b'. Here, 'a' contains 20 and
'b' contains 10.

Operator Description Example

= It checks if two operands values are equal or not, if (a=b) is not


the values are queal then condition becomes true. true

!= It checks if two operands values are equal or not, if (a!=b) is


values are not equal, then condition becomes true. true

<> It checks if two operands values are equal or not, if (a<>b) is


values are not equal then condition becomes true. true

> It checks if the left operand value is greater than right (a>b) is not
operand value, if yes then condition becomes true. true

< It checks if the left operand value is less than right (a<b) is true
operand value, if yes then condition becomes true.

>= It checks if the left operand value is greater than or (a>=b) is not
equal to the right operand value, if yes then condition true
becomes true.

<= It checks if the left operand value is less than or equal (a<=b) is
to the right operand value, if yes then condition true
becomes true.

!< It checks if the left operand value is not less than the (a!=b) is not
right operand value, if yes then condition becomes true
true.

!> It checks if the left operand value is not greater than (a!>b) is
the right operand value, if yes then condition true
becomes true.

SQL Logical Operators

There is the list of logical operator used in SQL:

Operator Description

ALL It compares a value to all values in another value set.

AND It allows the existence of multiple conditions in an SQL statement.

ANY It compares the values in the list according to the condition.

BETWEEN It is used to search for values that are within a set of values.

IN It compares a value to that specified list value.

NOT It reverses the meaning of any logical operator.

OR It combines multiple conditions in SQL statements.

EXISTS It is used to search for the presence of a row in a specified table.

LIKE It compares a value to similar values using wildcard operator.


SQL Table
o SQL Table is a collection of data which is organized in terms
of rows and columns. In DBMS, the table is known as relation
and row as a tuple.
o Table is a simple form of data storage. A table is also
considered as a convenient representation of relations.

EMP_ID EMP_NAME CITY PHONE_NO

1 Kristen Washington 7289201223

2 Anna Franklin 9378282882

3 Jackson Bristol 9264783838

4 Kellan California 7254728346

5 Ashley Hawaii 9638482678

Let's see an example of the EMPLOYEE table:

In the above table, "EMPLOYEE" is the table name, "EMP_ID",


"EMP_NAME", "CITY", "PHONE_NO" are the column names. The
combination of data of multiple columns forms a row, e.g., 1,
"Kristen", "Washington" and 7289201223 are the data of one row.

Operation on Table
1. Create table
2. Drop table
3. Delete table
4. Rename table

SQL Create Table


SQL create table is used to create a table in the database. To
define the table, you should define the name of the table and also
define its columns and column's data type.

Syntax

1. create table "table_name"


2. ("column1" "data type",
3. "column2" "data type",
4. "column3" "data type",
5. ...
6. "columnN" "data type");

Example

1. SQL> CREATE TABLE EMPLOYEE (


2. EMP_ID INT NOT NULL,
3. EMP_NAME VARCHAR (25) NOT NULL,
4. PHONE_NO INT NOT NULL,
5. ADDRESS CHAR (30),
6. PRIMARY KEY (ID)
7. );

If you create the table successfully, you can verify the table by
looking at the message by the SQL server. Else you can use DESC
command as follows:

Field Type Null Key Default Extra

EMP_ID int(11) NO PRI NULL

EMP_NAME varchar(25) NO NULL

PHONE_NO NO int(11) NULL

ADDRESS YES NULL char(30)


SQL> DESC EMPLOYEE;

o 4 rows in set (0.35 sec)

Now you have an EMPLOYEE table in the database, and you can
use the stored information related to the employees.

Drop table

A SQL drop table is used to delete a table definition and all the
data from a table. When this command is executed, all the
information available in the table is lost forever, so you have to
very careful while using this command.

Syntax

1. DROP TABLE "table_name";

Firstly, you need to verify the EMPLOYEE table using the following
command:

Field Type Null Key Default Extra

EMP_ID int(11) NO PRI NULL

EMP_NAME varchar(25) NO NULL

PHONE_NO NO int(11) NULL

ADDRESS YES NULL char(30)

1. SQL> DESC EMPLOYEE;


o 4 rows in set (0.35 sec)

This table shows that EMPLOYEE table is available in the


database, so we can drop it as follows:
1. SQL>DROP TABLE EMPLOYEE;

Now, we can check whether the table exists or not using the
following command:

1. Query OK, 0 rows affected (0.01 sec)

As this shows that the table is dropped, so it doesn't display it.

SQL DELETE table

In SQL, DELETE statement is used to delete rows from a table. We


can use WHERE condition to delete a specific row from a table. If
you want to delete all the records from the table, then you don't
need to use the WHERE clause.

Syntax

1. DELETE FROM table_name WHERE condition;

Example

Suppose, the EMPLOYEE table having the following records:

EMP_ID EMP_NAME CITY PHONE_NO SALARY

1 Kristen Chicago 9737287378 150000

2 Russell Austin 9262738271 200000

3 Denzel Boston 7353662627 100000

4 Angelina Denver 9232673822 600000

5 Robert Washington 9367238263 350000


6 Christian Los angels 7253847382 260000

The following query will DELETE an employee whose ID is 2.

1. SQL> DELETE FROM EMPLOYEE


2. WHERE EMP_ID = 3;

Now, the EMPLOYEE table would have the following records.

EMP_ID EMP_NAME CITY PHONE_NO SALARY

1 Kristen Chicago 9737287378 150000

2 Russell Austin 9262738271 200000

4 Angelina Denver 9232673822 600000

5 Robert Washington 9367238263 350000

6 Christian Los angels 7253847382 260000

If you don't specify the WHERE condition, it will remove all the
rows from the table.

1. DELETE FROM EMPLOYEE;

Now, the EMPLOYEE table would not have any records.

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.
Sample table:

Student_Detail

STU_ID NAME ADDRESS

1 Stephan Delhi

2 Kathrin Noida

3 David Ghaziabad

4 Alina Gurugram

Student_Marks

STU_ID NAME MARKS AGE

1 Stephan 97 19

2 Kathrin 86 21

3 David 74 18

4 Alina 90 20

5 John 96 18

1. Creating view

A view can be created using the CREATE VIEW statement. We can


create a view from a single table or multiple tables.

Syntax:
1. CREATE VIEW view_name AS
2. SELECT column1, column2.....
3. FROM table_name
4. WHERE condition;
2. Creating View from a single table

In this example, we create a View named DetailsView from the


table Student_Detail.

Query:

1. CREATE VIEW DetailsView AS


2. SELECT NAME, ADDRESS
3. FROM Student_Details
4. WHERE STU_ID < 4;

Just like table query, we can query the view to view the data.

1. SELECT * FROM DetailsView;

Output:

NAME ADDRESS

Stephan Delhi

Kathrin Noida

David Ghaziabad

3. Creating View from multiple tables

View from multiple tables can be created by simply include


multiple tables in the SELECT statement.

In the given example, a view is created named MarksView from


two tables Student_Detail and Student_Marks.

Query:
1. CREATE VIEW MarksView AS
2. SELECT Student_Detail.NAME, Student_Detail.ADDRESS, Student
_Marks.MARKS
3. FROM Student_Detail, Student_Mark
4. WHERE Student_Detail.NAME = Student_Marks.NAME;

To display data of View MarksView:

1. SELECT * FROM MarksView;


NAME ADDRESS MARKS

Stephan Delhi 97

Kathrin Noida 86

David Ghaziabad 74

Alina Gurugram 90

4. Deleting View

A view can be deleted using the Drop View statement.

Syntax

1. DROP VIEW view_name;

Example:

If we want to delete the View MarksView, we can do this as:

1. DROP VIEW MarksView;


SQL Index
o Indexes are special lookup tables. It is used to retrieve data
from the database very fast.
o An Index is used to speed up select queries and where
clauses. But it shows down the data input with insert and
update statements. Indexes can be created or dropped
without affecting the data.
o An index in a database is just like an index in the back of a
book.
o For example: When you reference all pages in a book that
discusses a certain topic, you first have to refer to the index,
which alphabetically lists all the topics and then referred to
one or more specific page numbers.

1. Create Index statement

It is used to create an index on a table. It allows duplicate value.

Syntax

1. CREATE INDEX index_name


2. ON table_name (column1, column2, ...);

Example

1. CREATE INDEX idx_name


2. ON Persons (LastName, FirstName);
2. Unique Index statement

It is used to create a unique index on a table. It does not allow


duplicate value.

Syntax

1. CREATE UNIQUE INDEX index_name


2. ON table_name (column1, column2, ...);

Example

1. CREATE UNIQUE INDEX websites_idx


2. ON websites (site_name);
3. Drop Index Statement

It is used to delete an index in a table.


Syntax

1. DROP INDEX index_name;

Example

1. DROP INDEX websites_idx;


SQL ORDER BY Clause
o Whenever we want to sort the records based on the columns
stored in the tables of the SQL database, then we consider
using the ORDER BY clause in SQL.
o The ORDER BY clause in SQL will help us to sort the records
based on the specific column of a table. This means that all
the values stored in the column on which we are applying
ORDER BY clause will be sorted, and the corresponding
column values will be displayed in the sequence in which we
have obtained the values in the earlier step.
o Using the ORDER BY clause, we can sort the records in
ascending or descending order as per our requirement. The
records will be sorted in ascending order whenever the ASC
keyword is used with ORDER by clause. DESC keyword will
sort the records in descending order.
o If no keyword is specified after the column based on which
we have to sort the records, in that case, the sorting will be
done by default in the ascending order.

Before writing the queries for sorting the records, let us


understand the syntax.

Syntax to sort the records in ascending order:

1. SELECT ColumnName1,...,ColumnNameN FROM TableName ORD


ER BY ColumnName ASC;

Syntax to sort the records in descending order:

1. SELECT ColumnName1,...,ColumnNameN FROM TableName ORD


ER BY ColumnNameDESC;
Syntax to sort the records in ascending order without using ASC
keyword:

1. SELECT ColumnName1,...,ColumnNameN FROM TableName ORD


ER BY ColumnName;

Let us explore more on this topic with the help of examples. We


will use the MySQL database for writing the queries in examples.

Consider we have customers table with the following records:

ID NAME AGE ADDRESS SALARY

2 Shiva Tiwari 22 Bhopal 21000

3 Ajeet Bhargav 45 Meerut 65000

4 Ritesh Yadav 36 Azamgarh 26000

5 Balwant Singh 45 Varanasi 36000

6 Mahesh Sharma 26 Mathura 22000

7 Rohit Shrivastav 19 Ahemdabad 38000

8 Neeru Sharma 29 Pune 40000

9 Aakash Yadav 32 Mumbai 43500

10 Sahil Sheikh 35 Aurangabad 68800

Example 1:

Write a query to sort the records in the ascending order of the


customer names stored in the customers table.
Query:

1. mysql> SELECT *FROM customers ORDER BY Name ASC;

Here in a SELECT query, an ORDER BY clause is applied on the


column 'Name' to sort the records. ASC keyword will sort the
records in ascending order.

You will get the following output:

ID NAME AGE ADDRESS SALARY

9 Aakash Yadav 32 Mumbai 43500

3 Ajeet Bhargav 45 Meerut 65000

5 Balwant Singh 45 Varanasi 36000

1 Himani Gupta 21 Modinagar 22000

6 Mahesh Sharma 26 Mathura 22000

8 Neeru Sharma 29 Pune 40000

4 Ritesh Yadav 36 Azamgarh 26000

7 Rohit Shrivastav 19 Ahemdabad 38000

10 Sahil Sheikh 35 Aurangabad 68800

2 Shiva Tiwari 22 Bhopal 21000

All the records present in the customers table are displayed in the
ascending order of the customer's name.

Example 2:
Write a query to sort the records in the ascending order of the
addresses stored in the customers table.

Query:

1. mysql> SELECT *FROM customers ORDER BY Address;

Here in a SELECT query, an ORDER BY clause is applied to the


'Address' column to sort the records. No keyword is used after the
ORDER BY clause. Hence, the records, by default, will be sorted in
ascending order.

You will get the following output:

ID NAME AGE ADDRESS SALARY

7 Rohit Shrivastav 19 Ahemdabad 38000

10 Sahil Sheikh 35 Aurangabad 68800

4 Ritesh Yadav 36 Azamgarh 26000

2 Shiva Tiwari 22 Bhopal 21000

6 Mahesh Sharma 26 Mathura 22000

3 Ajeet Bhargav 45 Meerut 65000

1 Himani Gupta 21 Modinagar 22000

9 Aakash Yadav 32 Mumbai 43500

8 Neeru Sharma 29 Pune 40000

5 Balwant Singh 45 Varanasi 36000


All the records present in the customers table are displayed in the
ascending order of the customer's address.

Example 3:

Write a query to sort the records in the descending order of the


customer salary stored in the customers table.

Query:

1. mysql> SELECT *FROM customers ORDER BY Salary DESC;

Here in a SELECT query, an ORDER BY clause is applied on the


column ?Salary? to sort the records. DESC keyword will sort the
records in descending order.

You will get the following output:

ID NAME AGE ADDRESS SALARY

10 Sahil Sheikh 35 Aurangabad 68800

3 Ajeet Bhargav 45 Meerut 65000

9 Aakash Yadav 32 Mumbai 43500

8 Neeru Sharma 29 Pune 40000

7 Rohit Shrivastav 19 Ahemdabad 38000

5 Balwant Singh 45 Varanasi 36000

4 Ritesh Yadav 36 Azamgarh 26000

6 Mahesh Sharma 26 Mathura 22000


1 Himani Gupta 21 Modinagar 22000

2 Shiva Tiwari 22 Bhopal 21000

All the records present in the customers table are displayed in the
descending order of the customer's salary.

Example 4:

Write a query to sort the records in the descending order of the


customer age stored in the customers table.

Query:

1. mysql> SELECT *FROM customers ORDER BY Age DESC;

Here in a SELECT query, an ORDER BY clause is applied on the


column 'Age' to sort the records. DESC keyword will sort the
records in descending order.

You will get the following output:

ID NAME AGE ADDRESS SALARY

3 Ajeet Bhargav 45 Meerut 65000

5 Balwant Singh 45 Varanasi 36000

4 Ritesh Yadav 36 Azamgarh 26000

10 Sahil Sheikh 35 Aurangabad 68800

9 Aakash Yadav 32 Mumbai 43500

8 Neeru Sharma 29 Pune 40000


6 Mahesh Sharma 26 Mathura 22000

2 Shiva Tiwari 22 Bhopal 21000

1 Himani Gupta 21 Modinagar 22000

7 Rohit Shrivastav 19 Ahemdabad 38000

All the records present in the customers table are displayed in the
descending order of the customer's age.

Consider we have another table named agents with the following


records:

AID Name WorkArea Profit_Percent ContactNumber Salary

1 Gurpreet Bangalore 1 9989675432 43000


Singh

2 Sakshi Kumari Chennai 5 8190567342 25000

3 Prachi Desai Mumbai 2 9056123432 60000

4 Shivani More Pune 3 8894236789 35500

5 Pallavi Singh Delhi 4 7798092341 38700

6 Rohini Ambala 8 7890945612 25670


Kulkarni

7 Shweta Dixit Chandigarh 6 8898786453 31670

8 Sonakshi Udaipur 2 9809453421 25050


Tiwari

9 Anushka Ujjain 9 8909124326 38000


Tripathi

10 Devika Sharma Goa 7 7864523145 44050

Example 1:

Write a query to sort the records in the ascending order of the


agent names stored in the agents table.

Query:

1. mysql> SELECT *FROM agents ORDER BY Name ASC;

Here in a SELECT query, an ORDER BY clause is applied on the


column 'Name' to sort the records. ASC keyword will sort the
records in ascending order.

You will get the following output:

AID Name WorkArea Profit_Percent ContactNumber Salary

9 Anushka Ujjain 9 8909124326 38000


Tripathi

10 Devika Sharma Goa 7 7864523145 44050

1 Gurpreet Bangalore 1 9989675432 43000


Singh

5 Pallavi Singh Delhi 4 7798092341 38700

3 Prachi Desai Mumbai 2 9056123432 60000


6 Rohini Ambala 8 7890945612 25670
Kulkarni

2 Sakshi Kumari Chennai 5 8190567342 25000

4 Shivani More Pune 3 8894236789 35500

7 Shweta Dixit Chandigarh 6 8898786453 31670

8 Sonakshi Udaipur 2 9809453421 25050


Tiwari

All the records present in the agents table are displayed in the
ascending order of the agent's name.

Example 2:

Write a query to sort the records in the descending order of the


work area stored in the agents table.

Query:

1. mysql> SELECT *FROM agents ORDER BY WorkArea DESC;

Here in a SELECT query, an ORDER BY clause is applied on the


column 'WorkArea' to sort the records. DESC keyword will sort the
records in descending order.

You will get the following output:

AID Name WorkArea Profit_Percent ContactNumber Salary

9 Anushka Ujjain 9 8909124326 38000


Tripathi

8 Sonakshi Udaipur 2 9809453421 25050


Tiwari

4 Shivani More Pune 3 8894236789 35500

3 Prachi Desai Mumbai 2 9056123432 60000

10 Devika Sharma Goa 7 7864523145 44050

5 Pallavi Singh Delhi 4 7798092341 38700

2 Sakshi Kumari Chennai 5 8190567342 25000

7 Shweta Dixit Chandigarh 6 8898786453 31670

1 Gurpreet Bangalore 1 9989675432 43000


Singh

6 Rohini Ambala 8 7890945612 25670


Kulkarni

All the records present in the agents table are displayed in the
descending order of the customer's work area.

Example 3:

Write a query to sort the records in the ascending order of the


agent salary stored in the agents table.

Query:

1. mysql> SELECT *FROM agents ORDER BY Salary;

Here in a SELECT query, an ORDER BY clause is applied on the


column 'Salary' to sort the records. No keyword is used after the
ORDER BY clause. Hence, the records, by default, will be sorted in
ascending order.
You will get the following output:

AID Name WorkArea Profit_Percent ContactNumber Salary

2 Sakshi Kumari Chennai 5 8190567342 25000

8 Sonakshi Udaipur 2 9809453421 25050


Tiwari

6 Rohini Ambala 8 7890945612 25670


Kulkarni

7 Shweta Dixit Chandigarh 6 8898786453 31670

4 Shivani More Pune 3 8894236789 35500

9 Anushka Ujjain 9 8909124326 38000


Tripathi

5 Pallavi Singh Delhi 4 7798092341 38700

1 Gurpreet Bangalore 1 9989675432 43000


Singh

10 Devika Sharma Goa 7 7864523145 44050

3 Prachi Desai Mumbai 2 9056123432 60000

All the records present in the agents table are displayed in the
ascending order of the customer's salary.

Example 4:

Write a query to sort the records in the descending order of the


agent salary stored in the agents table.
Query:

1. mysql> SELECT *FROM agents ORDER BY Salary DESC;

Here in a SELECT query, an ORDER BY clause is applied on the


column 'Salary' to sort the records. DESC keyword will sort the
records in descending order.

You will get the following output:

AID Name WorkArea Profit_Percent ContactNumber Salary

3 Prachi Desai Mumbai 2 9056123432 60000

10 Devika Sharma Goa 7 7864523145 44050

1 Gurpreet Bangalore 1 9989675432 43000


Singh

5 Pallavi Singh Delhi 4 7798092341 38700

9 Anushka Ujjain 9 8909124326 38000


Tripathi

4 Shivani More Pune 3 8894236789 35500

7 Shweta Dixit Chandigarh 6 8898786453 31670

6 Rohini Ambala 8 7890945612 25670


Kulkarni

8 Sonakshi Udaipur 2 9809453421 25050


Tiwari

2 Sakshi Kumari Chennai 5 8190567342 25000


All the records present in the agents table are displayed in the
descending order of the customer's address.

SQL Sub Query

A Subquery is a query within another SQL query and embedded


within the WHERE clause.

Important Rule:

o A subquery can be placed in a number of SQL clauses like


WHERE clause, FROM clause, HAVING clause.
o You can use Subquery with SELECT, UPDATE, INSERT,
DELETE statements along with the operators like =, <, >, >=,
<=, IN, BETWEEN, etc.
o A subquery is a query within another query. The outer query
is known as the main query, and the inner query is known as
a subquery.
o Subqueries are on the right side of the comparison operator.
o A subquery is enclosed in parentheses.
o In the Subquery, ORDER BY command cannot be used. But
GROUP BY command can be used to perform the same
function as ORDER BY command.

1. Subqueries with the Select Statement

SQL subqueries are most frequently used with the Select


statement.

Syntax

1. SELECT column_name
2. FROM table_name
3. WHERE column_name expression operator
4. ( SELECT column_name from table_name WHERE ... );

Example

Consider the EMPLOYEE table have the following records:


ID NAME AGE ADDRESS SALARY

1 John 20 US 2000.00

2 Stephan 26 Dubai 1500.00

3 David 27 Bangkok 2000.00

4 Alina 29 UK 6500.00

5 Kathrin 34 Bangalore 8500.00

6 Harry 42 China 4500.00

7 Jackson 25 Mizoram 10000.00

The subquery with a SELECT statement will be:

1. SELECT *
2. FROM EMPLOYEE
3. WHERE ID IN (SELECT ID
4. FROM EMPLOYEE
5. WHERE SALARY > 4500);

This would produce the following result:

ID NAME AGE ADDRESS SALARY

4 Alina 29 UK 6500.00

5 Kathrin 34 Bangalore 8500.00

7 Jackson 25 Mizoram 10000.00


2. Subqueries with the INSERT Statement
o SQL subquery can also be used with the Insert statement. In
the insert statement, data returned from the subquery is
used to insert into another table.
o In the subquery, the selected data can be modified with any
of the character, date functions.

Syntax:

1. INSERT INTO table_name (column1, column2, column3....)


2. SELECT *
3. FROM table_name
4. WHERE VALUE OPERATOR

Example

Consider a table EMPLOYEE_BKP with similar as EMPLOYEE.

Now use the following syntax to copy the complete EMPLOYEE


table into the EMPLOYEE_BKP table.

1. INSERT INTO EMPLOYEE_BKP


2. SELECT * FROM EMPLOYEE
3. WHERE ID IN (SELECT ID
4. FROM EMPLOYEE);
3. Subqueries with the UPDATE Statement

The subquery of SQL can be used in conjunction with the Update


statement. When a subquery is used with the Update statement,
then either single or multiple columns in a table can be updated.

Syntax

1. UPDATE table
2. SET column_name = new_value
3. WHERE VALUE OPERATOR
4. (SELECT COLUMN_NAME
5. FROM TABLE_NAME
6. WHERE condition);
Example

Let's assume we have an EMPLOYEE_BKP table available which is


backup of EMPLOYEE table. The given example updates the
SALARY by .25 times in the EMPLOYEE table for all employee
whose AGE is greater than or equal to 29.

1. UPDATE EMPLOYEE
2. SET SALARY = SALARY * 0.25

ID NAME AGE ADDRESS SALARY

1 John 20 US 2000.00

2 Stephan 26 Dubai 1500.00

3 David 27 Bangkok 2000.00

4 Alina 29 UK 1625.00

5 Kathrin 34 Bangalore 2125.00

6 Harry 42 China 1125.00

7 Jackson 25 Mizoram 10000.00

3. WHERE AGE IN (SELECT AGE FROM CUSTOMERS_BKP


4. WHERE AGE >= 29);

This would impact three rows, and finally, the EMPLOYEE table
would have the following records.

4. Subqueries with the DELETE Statement

The subquery of SQL can be used in conjunction with the Delete


statement just like any other statements mentioned above.

Syntax
1. DELETE FROM TABLE_NAME
2. WHERE VALUE OPERATOR
3. (SELECT COLUMN_NAME
4. FROM TABLE_NAME
5. WHERE condition);

Example

Let's assume we have an EMPLOYEE_BKP table available which is


backup of EMPLOYEE table. The given example deletes the
records from the EMPLOYEE table for all EMPLOYEE whose AGE
is greater than or equal to 29.

1. DELETE FROM EMPLOYEE


2. WHERE AGE IN (SELECT AGE FROM EMPLOYEE_BKP
3. WHERE AGE >= 29 );
This would impact three rows, and finally, the EMPLOYEE table
would have the following records.

ID NAME AGE ADDRESS SALARY

1 John 20 US 2000.00

2 Stephan 26 Dubai 1500.00

3 David 27 Bangkok 2000.00

7 Jackson 25 Mizoram 10000.00

PL/SQL Exception Handling


What is Exception

An error occurs during the program execution is called Exception


in PL/SQL.

PL/SQL facilitates programmers to catch such conditions using


exception block in the program and an appropriate action is taken
against the error condition.
There are two type of exceptions:

o System-defined Exceptions
o User-defined Exceptions

PL/SQL Exception Handling

Syntax for exception handling:

Following is a general syntax for exception handling:

1. DECLARE
2. <declarations section>
3. BEGIN
4. <executable command(s)>
5. EXCEPTION
6. <exception handling goes here >
7. WHEN exception1 THEN
8. exception1-handling-statements
9. WHEN exception2 THEN
10. exception2-handling-statements
11. WHEN exception3 THEN
12. exception3-handling-statements
13. ........
14. WHEN others THEN
15. exception3-handling-statements
16. END;
Example of exception handling

Let's take a simple example to demonstrate the concept of


exception handling. Here we are using the already created
CUSTOMERS table.

SELECT* FROM COUSTOMERS;

ID NAME AGE ADDRESS SALARY

1 Ramesh 23 Allahabad 20000


2 Suresh 22 Kanpur 22000

3 Mahesh 24 Ghaziabad 24000

4 Chandan 25 Noida 26000

5 Alex 21 Paris 28000

6 Sunita 20 Delhi 30000

1. DECLARE
2. c_id customers.id%type := 8;
3. c_name customers.name%type;
4. c_addr customers.address%type;
5. BEGIN
6. SELECT name, address INTO c_name, c_addr
7. FROM customers
8. WHERE id = c_id;
9. DBMS_OUTPUT.PUT_LINE ('Name: '|| c_name);
10. DBMS_OUTPUT.PUT_LINE ('Address: ' || c_addr);
11. EXCEPTION
12. WHEN no_data_found THEN
13. dbms_output.put_line('No such customer!');
14. WHEN others THEN
15. dbms_output.put_line('Error!');
16. END;
17. /

After the execution of above code at SQL Prompt, it produces the


following result:

No such customer!
PL/SQL procedure successfully completed.

The above program should show the name and address of a


customer as result whose ID is given. But there is no customer
with ID value 8 in our database, so the program raises the run-time
exception NO_DATA_FOUND, which is captured in EXCEPTION
block.

Note: You get the result "No such customer" because the
customer_id used in the above example is 8 and there is no
cutomer having id value 8 in that table.

If you use the id defined in the above table (i.e. 1 to 6), you will get
a certain result. For a demo example: here, we are using the id 5.

1. DECLARE
2. c_id customers.id%type := 5;
3. c_name customers.name%type;
4. c_addr customers.address%type;
5. BEGIN
6. SELECT name, address INTO c_name, c_addr
7. FROM customers
8. WHERE id = c_id;
9. DBMS_OUTPUT.PUT_LINE ('Name: '|| c_name);
10. DBMS_OUTPUT.PUT_LINE ('Address: ' || c_addr);
11. EXCEPTION
12. WHEN no_data_found THEN
13. dbms_output.put_line('No such customer!');
14. WHEN others THEN
15. dbms_output.put_line('Error!');
16. END;
17. /

After the execution of above code at SQL prompt, you will get the
following result:

Name: alex
Address: paris
PL/SQL procedure successfully completed.
Raising Exceptions

In the case of any internal database error, exceptions are raised


by the database server automatically. But it can also be raised
explicitly by programmer by using command RAISE.
Syntax for raising an exception:

1. DECLARE
2. exception_name EXCEPTION;
3. BEGIN
4. IF condition THEN
5. RAISE exception_name;
6. END IF;
7. EXCEPTION
8. WHEN exception_name THEN
9. statement;
10. END;
PL/SQL User-defined Exceptions

PL/SQL facilitates their users to define their own exceptions


according to the need of the program. A user-defined exception
can be raised explicitly, using either a RAISE statement or the
procedure DBMS_STANDARD.RAISE_APPLICATION_ERROR.

Syntax for user define exceptions

1. DECLARE
2. my-exception EXCEPTION;
PL/SQL Pre-defined Exceptions

There are many pre-defined exception in PL/SQL which are


executed when any database rule is violated by the programs.

For example: NO_DATA_FOUND is a pre-defined exception which


is raised when a SELECT INTO statement returns no rows.

Following is a list of some important pre-defined exceptions:

Exception Oracle SQL Description


Error Code

ACCESS_INTO_NULL 06530 -6530 It is raised when a NULL object is


automatically assigned a value.
CASE_NOT_FOUND 06592 -6592 It is raised when none of the
choices in the "WHEN" clauses of a
CASE statement is selected, and
there is no else clause.

COLLECTION_IS_NULL 06531 -6531 It is raised when a program


attempts to apply collection
methods other than exists to an
uninitialized nested table or varray,
or the program attempts to assign
values to the elements of an
uninitialized nested table or varray.

DUP_VAL_ON_INDEX 00001 -1 It is raised when duplicate values


are attempted to be stored in a
column with unique index.

INVALID_CURSOR 01001 -1001 It is raised when attempts are made


to make a cursor operation that is
not allowed, such as closing an
unopened cursor.

INVALID_NUMBER 01722 -1722 It is raised when the conversion of a


character string into a number fails
because the string does not
represent a valid number.

LOGIN_DENIED 01017 -1017 It is raised when s program


attempts to log on to the database
with an invalid username or
password.

NO_DATA_FOUND 01403 +100 It is raised when a select into


statement returns no rows.
NOT_LOGGED_ON 01012 -1012 It is raised when a database call is
issued without being connected to
the database.

PROGRAM_ERROR 06501 -6501 It is raised when PL/SQL has an


internal problem.

ROWTYPE_MISMATCH 06504 -6504 It is raised when a cursor fetches


value in a variable having
incompatible data type.

SELF_IS_NULL 30625 - It is raised when a member method


30625 is invoked, but the instance of the
object type was not initialized.

STORAGE_ERROR 06500 -6500 It is raised when PL/SQL ran out of


memory or memory was corrupted.

TOO_MANY_ROWS 01422 -1422 It is raised when a SELECT INTO


statement returns more than one
row.

VALUE_ERROR 06502 -6502 It is raised when an arithmetic,


conversion, truncation, or size-
constraint error occurs.

ZERO_DIVIDE 01476 1476 It is raised when an attempt is made


to divide a number by zero.

PL/SQL Procedure

The PL/SQL stored procedure or simply a procedure is a PL/SQL


block which performs one or more specific tasks. It is just like
procedures in other programming languages.

The procedure contains a header and a body.


o Header: The header contains the name of the procedure and
the parameters or variables passed to the procedure.
o Body: The body contains a declaration section, execution
section and exception section similar to a general PL/SQL
block.

How to pass parameters in procedure:

When you want to create a procedure or function, you have to


define parameters .There is three ways to pass parameters in
procedure:

1. IN parameters: The IN parameter can be referenced by the


procedure or function. The value of the parameter cannot be
overwritten by the procedure or the function.
2. OUT parameters: The OUT parameter cannot be referenced
by the procedure or function, but the value of the parameter
can be overwritten by the procedure or function.
3. INOUT parameters: The INOUT parameter can be referenced
by the procedure or function and the value of the parameter
can be overwritten by the procedure or function.

A procedure may or may not return any value.


PL/SQL Create Procedure

Syntax for creating procedure:

1. CREATE [OR REPLACE] PROCEDURE procedure_name


2. [ (parameter [,parameter]) ]
3. IS
4. [declaration_section]
5. BEGIN
6. executable_section
7. [EXCEPTION
8. exception_section]
9. END [procedure_name];
Create procedure example

In this example, we are going to insert record in user table. So you


need to create user table first.

Table creation:

1. create table user(id number(10) primary key,name varchar2(100))


;

Now write the procedure code to insert record in user table.

Procedure Code:

1. create or replace procedure "INSERTUSER"


2. (id IN NUMBER,
3. name IN VARCHAR2)
4. is
5. begin
6. insert into user values(id,name);
7. end;
8. /

Output:

Procedure created.
PL/SQL program to call procedure

Let's see the code to call above created procedure.

1. BEGIN
2. insertuser(101,'Rahul');
3. dbms_output.put_line('record inserted successfully');
4. END;
5. /

Now, see the "USER" table, you will see one record is inserted.

ID Name
101 Rahul

PL/SQL Drop Procedure

Syntax for drop procedure

1. DROP PROCEDURE procedure_name;


Example of drop procedure
1. DROP PROCEDURE pro1;

PL/SQL - Packages
In this chapter, we will discuss the Packages in PL/SQL. Packages
are schema objects that groups logically related PL/SQL types,
variables, and subprograms.
A package will have two mandatory parts −
 Package specification
 Package body or definition
Package Specification
The specification is the interface to the package. It
just DECLARES the types, variables, constants, exceptions,
cursors, and subprograms that can be referenced from outside
the package. In other words, it contains all information about the
content of the package, but excludes the code for the
subprograms.
All objects placed in the specification are called public objects.
Any subprogram not in the package specification but coded in the
package body is called a private object.
The following code snippet shows a package specification having
a single procedure. You can have many global variables defined
and multiple procedures or functions inside a package.
CREATE PACKAGE cust_sal AS
PROCEDURE find_sal(c_id customers.id%type);
END cust_sal;
/
When the above code is executed at the SQL prompt, it produces
the following result −
Package created.
Package Body
The package body has the codes for various methods declared in
the package specification and other private declarations, which
are hidden from the code outside the package.
The CREATE PACKAGE BODY Statement is used for creating the
package body. The following code snippet shows the package
body declaration for the cust_sal package created above. I
assumed that we already have CUSTOMERS table created in our
database as mentioned in the PL/SQL - Variables chapter.
CREATE OR REPLACE PACKAGE BODY cust_sal AS

PROCEDURE find_sal(c_id customers.id%TYPE) IS


c_sal customers.salary%TYPE;
BEGIN
SELECT salary INTO c_sal
FROM customers
WHERE id = c_id;
dbms_output.put_line('Salary: '|| c_sal);
END find_sal;
END cust_sal;
/
When the above code is executed at the SQL prompt, it produces
the following result −
Package body created.
Using the Package Elements
The package elements (variables, procedures or functions) are
accessed with the following syntax −
package_name.element_name;
Consider, we already have created the above package in our
database schema, the following program uses the find_sal method
of the cust_sal package −
DECLARE
code customers.id%type := &cc_id;
BEGIN
cust_sal.find_sal(code);
END;
/
When the above code is executed at the SQL prompt, it prompts to
enter the customer ID and when you enter an ID, it displays the
corresponding salary as follows −
Enter value for cc_id: 1
Salary: 3000

PL/SQL procedure successfully completed.


Example
The following program provides a more complete package. We will
use the CUSTOMERS table stored in our database with the
following records −
Select * from customers;

+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 3000.00 |
| 2 | Khilan | 25 | Delhi | 3000.00 |
| 3 | kaushik | 23 | Kota | 3000.00 |
| 4 | Chaitali | 25 | Mumbai | 7500.00 |
| 5 | Hardik | 27 | Bhopal | 9500.00 |
| 6 | Komal | 22 | MP | 5500.00 |
+----+----------+-----+-----------+----------+
The Package Specification
CREATE OR REPLACE PACKAGE c_package AS
-- Adds a customer
PROCEDURE addCustomer(c_id customers.id%type,
c_name customers.Name%type,
c_age customers.age%type,
c_addr customers.address%type,
c_sal customers.salary%type);

-- Removes a customer
PROCEDURE delCustomer(c_id customers.id%TYPE);
--Lists all customers
PROCEDURE listCustomer;

END c_package;
/
When the above code is executed at the SQL prompt, it creates
the above package and displays the following result −
Package created.
Creating the Package Body
CREATE OR REPLACE PACKAGE BODY c_package AS
PROCEDURE addCustomer(c_id customers.id%type,
c_name customers.Name%type,
c_age customers.age%type,
c_addr customers.address%type,
c_sal customers.salary%type)
IS
BEGIN
INSERT INTO customers (id,name,age,address,salary)
VALUES(c_id, c_name, c_age, c_addr, c_sal);
END addCustomer;

PROCEDURE delCustomer(c_id customers.id%type) IS


BEGIN
DELETE FROM customers
WHERE id = c_id;
END delCustomer;

PROCEDURE listCustomer IS
CURSOR c_customers is
SELECT name FROM customers;
TYPE c_list is TABLE OF customers.Name%type;
name_list c_list := c_list();
counter integer :=0;
BEGIN
FOR n IN c_customers LOOP
counter := counter +1;
name_list.extend;
name_list(counter) := n.name;
dbms_output.put_line('Customer(' ||counter||
')'||name_list(counter));
END LOOP;
END listCustomer;

END c_package;
/
The above example makes use of the nested table. We will discuss
the concept of nested table in the next chapter.
When the above code is executed at the SQL prompt, it produces
the following result −
Package body created.
Using The Package
The following program uses the methods declared and defined in
the package c_package.
DECLARE
code customers.id%type:= 8;
BEGIN
c_package.addcustomer(7, 'Rajnish', 25, 'Chennai', 3500);
c_package.addcustomer(8, 'Subham', 32, 'Delhi', 7500);
c_package.listcustomer;
c_package.delcustomer(code);
c_package.listcustomer;
END;
/
When the above code is executed at the SQL prompt, it produces
the following result −
Customer(1): Ramesh
Customer(2): Khilan
Customer(3): kaushik
Customer(4): Chaitali
Customer(5): Hardik
Customer(6): Komal
Customer(7): Rajnish
Customer(8): Subham
Customer(1): Ramesh
Customer(2): Khilan
Customer(3): kaushik
Customer(4): Chaitali
Customer(5): Hardik
Customer(6): Komal
Customer(7): Rajnish

PL/SQL procedure successfully completed


DBMS Architecture
o The DBMS design depends upon its architecture. The basic
client/server architecture is used to deal with a large number
of PCs, web servers, database servers and other
components that are connected with networks.
o The client/server architecture consists of many PCs and a
workstation which are connected via the network.
o DBMS architecture depends upon how users are connected
to the database to get their request done.

Types of DBMS Architecture

Database architecture can be seen as a single tier or multi-tier.


But logically, database architecture is of two types like: 2-tier
architecture and 3-tier architecture.

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

2-Tier Architecture

o The 2-Tier architecture is same as basic client-server. In the


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

3-Tier Architecture

o The 3-Tier architecture contains another layer between the


client and server. In this architecture, client can't directly
communicate with the server.
o The application on the client-end interacts with an
application server which further communicates with the
database system.
o End user has no idea about the existence of the database
beyond the application server. The database also has no idea
about any other user beyond the application.
o The 3-Tier architecture is used in case of large web
application.
Fig: 3-tier Architecture

Data Models

Data Model is the modeling of the data description, data


semantics, and consistency constraints of the data. It provides the
conceptual tools for describing the design of a database at each
level of data abstraction. Therefore, there are following four data
models used for understanding the structure of the database:
1) Relational Data Model: This type of model designs the data in
the form of rows and columns within a table. Thus, a relational
model uses tables for representing data and in-between in
relationships.
nships. Tables are also called relations. This model was
initially described by Edgar F. Codd, in 1969. The relational data
model is the widely used model which is primarily used by
commercial data processing applications.

2) Entity-Relationship
Relationship Data Model
Model: An ER model is the logical
representation of data as objects and relationships among them.
These objects are known as entities, and relationship is an
association among these entities. This model was designed by
Peter Chen and published in 1976 papers. IItt was widely used in
database designing. A set of attributes describe the entities. For
example, student_name, student_id describes the 'student' entity.
A set of the same type of entities is known as an 'Entity set', and
the set of the same type of relati
relationships
onships is known as 'relationship
set'.

3) Object-based
based Data Model: An extension of the ER model with
notions of functions, encapsulation, and object identity, as well.
This model supports a rich type system that includes structured
and collection types. Thus,
Thus, in 1980s, various database systems
following the object-oriented
oriented approach were developed. Here, the
objects are nothing but the data carrying its properties.
4) Semistructured Data Model: This type of data model is different
from the other three data models (explained above). The
semistructured data model allows the data specifications at
places where the individual data items of the same type may have
different attributes sets. The Extensible Markup Language, also
known as XML, is widely used for representing the semistructured
data. Although XML was initially designed for including the markup
information to the text document, it gains importance because of
its application in the exchange of data.

ER (Entity Relationship) Diagram 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.
Component of ER Diagram

1. Entity:

An entity may be any object, class, person or place. In the ER


diagram, an entity can be represented as rectangles.

Consider an organization as an example- manager, product,


employee, department etc. can be taken as an entity.
a. Weak Entity

An entity that depends on another entity called a weak entity. The


weak entity doesn't contain any key attribute of its own. The weak
entity is represented by a double rectangle.

2. Attribute

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


is used to represent an attribute.

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

a. Key Attribute

The key attribute is used to represent the main characteristics of


an entity. It represents a primary key. The key attribute is
represented by an ellipse with the text underlined.
b. Composite Attribute

An attribute that composed of many other attributes is known as a


composite attribute. The composite attribute is represented by an
ellipse, and those ellipses are connected with an ellipse.

c. Multivalued Attribute

An attribute can have more than one value. These attributes are
known as a multivalued attribute. The double oval is used to
represent multivalued attribute.
For example, a student can have more than one phone number.

d. Derived Attribute

An attribute that can be derived from other attribute is known as a


derived attribute. It can be represented by a dashed ellipse.

For example, A person's age changes over time and can be


derived from another attribute like Date of birth.

3. Relationship

A relationship is used to describe the relation between entities.


Diamond or rhombus is used to represent the relationship.
Types of relationship are as follows:

a. One-to-One Relationship

When only one instance of an entity is associated with the


relationship, then it is known as one to one relationship.

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

b. One-to-many relationship

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

For example, Scientist can invent many inventions, but the


invention is done by the only specific scientist.

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

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

d. Many-to-many relationship

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

For example, Employee can assign by many projects and project


can have many employees.

Mapping Constraints
o A mapping constraint is a data constraint that expresses the
number of entities to which another entity can be related via
a relationship set.
o It is most useful in describing the relationship sets that
involve more than two entity sets.
o For binary relationship set R on an entity set A and B, there
are four possible mapping cardinalities. These are as
follows:
1. One to one (1:1)
2. One to many (1:M)
3. Many to one (M:1)
4. Many to many (M:M)

One-to-one

In one-to-one mapping, an entity in E1 is associated with at most


one entity in E2, and an entity in E2 is associated with at most one
entity in E1.

One-to-many

In one-to-many mapping, an entity in E1 is associated with any


number of entities in E2, and an entity in E2 is associated with at
most one entity in E1.

Many-to-one

In one-to-many mapping, an entity in E1 is associated with at most


one entity in E2, and an entity in E2 is associated with any number
of entities in E1.
Many-to-many

In many-to-many mapping, an entity in E1 is associated with any


number of entities in E2, and an entity in E2 is associated with any
number of entities in E1.

Generalization
o Generalization is like a bottom-up approach in which two or
more entities of lower level combine to form a higher level
entity if they have some attributes in common.
o In generalization, an entity of a higher level can also combine
with the entities of the lower level to form a further higher
level entity.
o Generalization is more like subclass and superclass system,
but the only difference is the approach. Generalization uses
the bottom-up approach.
o In generalization, entities are combined to form a more
generalized entity, i.e., subclasses are combined to make a
superclass.

For example, Faculty and Student entities can be generalized and


create a higher level entity Person.
Specialization
o Specialization is a top-down approach, and it is opposite to
Generalization. In specialization, one higher level entity can
be broken down into two lower level entities.
o Specialization is used to identify the subset of an entity set
that shares some distinguishing characteristics.
o Normally, the superclass is defined first, the subclass and its
related attributes are defined next, and relationship set are
then added.

For example: In an Employee management system, EMPLOYEE


entity can be specialized as TESTER or DEVELOPER based on
what role they play in the company.
Data Dictionary in DBMS

Till now, we learned and understood about relations and its


representation. In the relational database system, it maintains all
information of a relation or table, from its schema to the applied
constraints. All the metadata is stored. In general, metadata
refers to the data about data. So, storing the relational schemas
and other metadata about the relations in a structure is known
as Data Dictionary or System Catalog.

A data dictionary is like the A-Z dictionary of the relational


database system holding all information of each relation in the
database.

The types of information a system must store are:

o Name of the relations


o Name of the attributes of each relation
o Lengths and domains of attributes
o Name and definitions of the views defined on the database
o Various integrity constraints
With this, the system also keeps the following data based on users
of the system:

o Name of authorized users


o Accounting and authorization information about users.
o The authentication information for users, such as passwords
or other related information.

In addition to this, the system may also store some statistical and
descriptive data about the relations, such as:

o Number of tuples in each relation


o Method of storage for each relation, such as clustered or
non-clustered.

A system may also store the storage organization, whether


sequential, hash, or heap. It also notes the location where each
relation is stored:

o If relations are stored in the files of the operating system, the


data dictionary note, and stores the names of the file.
o If the database stores all the relations in a single file, the data
dictionary notes and store the blocks containing records of
each relation in a data structure similar to a linked list.

At last, it also stores the information regarding each index of all


the relations:

o Name of the index.


o Name of the relation being indexed.
o Attributes on which the index is defined.
o The type of index formed.

All the above information or metadata is stored in a data


dictionary. The data dictionary also maintains updated information
whenever they occur in the relations. Such metadata constitutes a
miniature database. Some systems store the metadata in the form
of a relation in the database itself. The system designers design
the way of representation of the data dictionary. Also, a data
dictionary stores the data in a non-formalized manner. It does not
use any normal form so as to fastly access the data stored in the
dictionary.

For example, in the data dictionary, it uses underline below the


value to represent that the following field contains a primary key.

So, whenever the database system requires fetching records from


a relation, it firstly finds in the relation of data dictionary about the
location and storage organization of the relation. After confirming
the details, it finally retrieves the required record from the
database.

Inclusion Dependency
o Multivalued dependency and join dependency can be used to
guide database design although they both are less common
than functional dependencies.
o Inclusion dependencies are quite common. They typically
show little influence on designing of the database.
o The inclusion dependency is a statement in which some
columns of a relation are contained in other columns.
o The example of inclusion dependency is a foreign key. In one
relation, the referring relation is contained in the primary key
column(s) of the referenced relation.
o Suppose we have two relations R and S which was obtained
by translating two entity sets such that every R entity is also
an S entity.
o Inclusion dependency would be happen if projecting R on its
key attributes yields a relation that is contained in the
relation obtained by projecting S on its key attributes.
o In inclusion dependency, we should not split groups of
attributes that participate in an inclusion dependency.
o In practice, most inclusion dependencies are key-based that
is involved only keys.

You might also like