SlideShare a Scribd company logo
12
Most read
16
Most read
18
Most read
UNIT-2
Constraints on Relational Database Model
In modeling the design of the relational database we can put some restrictions like what values are
allowed to be inserted in the relation, and what kind of modifications and deletions are allowed in
the relation. These are the restrictions we impose on the relational database.
In models like Entity-Relationship models, we did not have such features. Database Constraints can
be categorized into 3 main categories:
1. Constraints that are applied in the data model are called Implicit Constraints.
2. Constraints that are directly applied in the schemas of the data model, by specifying them in
the DDL(Data Definition Language). These are called Schema-Based Constraints or Explicit
Constraints.
3. Constraints that cannot be directly applied in the schemas of the data model. We call these
Application-based or Semantic Constraints.
So here we are going to deal with Implicit constraints.
Relational Constraints
These are the restrictions or sets of rules imposed on the database contents. It validates the quality
of the database. It validates the various operations like data insertion, updation, and other processes
that have to be performed without affecting the integrity of the data. It protects us against
threats/damages to the database. Mainly Constraints on the relational database are of 4 types
 Domain constraints
 Key constraints or Uniqueness Constraints
 Entity Integrity constraints
 Referential integrity constraints
Types of Relational Constraints
Let’s discuss each of the above constraints in detail.
1. Domain Constraints
 Every domain must contain atomic values(smallest indivisible units) which means composite
and multi-valued attributes are not allowed.
 We perform a datatype check here, which means when we assign a data type to a column we
limit the values that it can contain. Eg. If we assign the datatype of attribute age as int, we
can’t give it values other than int datatype.
Example:
EID Name Phone
01 Bikash Dutta
123456789
234456678
Explanation: In the above relation, Name is a composite attribute and Phone is a multi-values
attribute, so it is violating domain constraint.
2. Key Constraints or Uniqueness Constraints
 These are called uniqueness constraints since it ensures that every tuple in the relation
should be unique.
 A relation can have multiple keys or candidate keys(minimal superkey), out of which we
choose one of the keys as the primary key, we don’t have any restriction on choosing the
primary key out of candidate keys, but it is suggested to go with the candidate key with less
number of attributes.
 Null values are not allowed in the primary key, hence Not Null constraint is also part of the
key constraint.
Example:
EID Name Phone
01 Bikash 6000000009
02 Paul 9000090009
01 Tuhin 9234567892
Explanation: In the above relation, Name is a composite attribute and Phone is a multi-values
attribute, so it is violating domain constraint.
2. Key Constraints or Uniqueness Constraints
 These are called uniqueness constraints since it ensures that every tuple in the relation
should be unique.
 A relation can have multiple keys or candidate keys(minimal superkey), out of which we
choose one of the keys as the primary key, we don’t have any restriction on choosing the
primary key out of candidate keys, but it is suggested to go with the candidate key with less
number of attributes.
 Null values are not allowed in the primary key, hence Not Null constraint is also part of the
key constraint.
Example:
EID Name Phone
01 Bikash 6000000009
02 Paul 9000090009
01 Tuhin 9234567892
Explanation: In the above table, EID is the primary key, and the first and the last tuple have the same
value in EID ie 01, so it is violating the key constraint.
3. Entity Integrity Constraints
 Entity Integrity constraints say that no primary key can take a NULL value, since using
the primary key we identify each tuple uniquely in a relation.
Example:
EID Name Phone
01 Bikash 9000900099
02 Paul 600000009
NULL Sony 9234567892
Explanation: In the above relation, EID is made the primary key, and the primary key can’t take NULL
values but in the third tuple, the primary key is null, so it is violating Entity Integrity constraints.
4. Referential Integrity Constraints
 The Referential integrity constraint is specified between two relations or tables and used to
maintain the consistency among the tuples in two relations.
 This constraint is enforced through a foreign key, when an attribute in the foreign key of
relation R1 has the same domain(s) as the primary key of relation R2, then the foreign key of
R1 is said to reference or refer to the primary key of relation R2.
 The values of the foreign key in a tuple of relation R1 can either take the values of the
primary key for some tuple in relation R2, or can take NULL values, but can’t be empty.
Example:
EID Name DNO
01 Divine 12
02 Dino 22
04 Vivian 14
DNO Place
12 Jaipur
13 Mumbai
14 Delhi
Explanation: In the above tables, the DNO of Table 1 is the foreign key, and DNO in Table 2 is the
primary key. DNO = 22 in the foreign key of Table 1 is not allowed because DNO = 22 is not defined in
the primary key of table 2. Therefore, Referential integrity constraints are violated here.
Advantages of Relational Database Model
 It is simpler than the hierarchical model and network model.
 It is easy and simple to understand.
 Its structure can be changed anytime upon requirement.
 Data Integrity: The relational database model enforces data integrity through various
constraints such as primary keys, foreign keys, and unique constraints. This ensures that the
data in the database is accurate, consistent, and valid.
 Flexibility: The relational database model is highly flexible and can handle a wide range of
data types and structures. It also allows for easy modification and updating of the data
without affecting other parts of the database.
 Scalability: The relational database model can scale to handle large amounts of data by
adding more tables, indexes, or partitions to the database. This allows for better
performance and faster query response times.
 Security: The relational database model provides robust security features to protect the data
in the database. These include user authentication, authorization, and encryption of
sensitive data.
 Data consistency: The relational database model ensures that the data in the database is
consistent across all tables. This means that if a change is made to one table, the
corresponding changes will be made to all related tables.
 Query Optimization: The relational database model provides a query optimizer that can
analyze and optimize SQL queries to improve their performance. This allows for faster query
response times and better scalability.
Disadvantages of the Relational Model
 Few database relations have certain limits which can’t be expanded further.
 It can be complex and it becomes hard to use.
 Complexity: The relational model can be complex and difficult to understand, particularly for
users who are not familiar with SQL and database design principles. This can make it
challenging to set up and maintain a relational database.
 Performance: The relational model can suffer from performance issues when dealing with
large data sets or complex queries. In particular, joins between tables can be slow, and
indexing strategies can be difficult to optimize.
 Scalability: While the relational model is generally scalable, it can become difficult to
manage as the database grows in size. Adding new tables or indexes can be time-consuming,
and managing relationships between tables can become complex.
 Cost: Relational databases can be expensive to license and maintain, particularly for large-
scale deployments. Additionally, relational databases often require dedicated hardware and
specialized software to run, which can add to the cost.
 Limited flexibility: The relational model is designed to work with tables that have predefined
structures and relationships. This can make it difficult to work with data that does not fit
neatly into a table-based format, such as unstructured or semi-structured data.
 Data redundancy: In some cases, the relational model can lead to data redundancy, where
the same data is stored in multiple tables. This can lead to inefficiencies and can make it
difficult to ensure data consistency across the database.
INTRODUCTION TO SQL
is a standard language to write queries. It was developed under R Project by IBM. SQL has a basic
grammar and syntax. It was declared as a standard language to use by American Standard National
Institute(ANSI) and International Standard Organization(ISO). The functionality of SQL language is
virtually similar across the operating system platforms.
Using SQL doesn’t require programming experience, but programming experience helps one to
conceptualize what a particular SQL command will help to execute and retrieve SQL queries.
Characteristics and Benefits of Structured Query Language:
The ANSI SQL provides with:
 Specific syntax and semantics of SQL data definition and data manipulation languages.
 It also provides with basic data structure and operations for designing, assessing,
maintaining, controlling and protecting SQL databases.
 Portability of database definition and application is also provided. Applications can be moved
from one machine to another.
 IS professionals share a common language and reduce training costs.
 Professionals can become proficient in its use and increase the productivity.
 It provides with longevity.
 It provides with reduced dependence on single vendor.
Rules to write commands:
1. Table names cannot exceed 20 characters.
2. Name of the table must be unique.
3. Field names also must be unique.
4. The field list and filed length must be enclosed in parentheses.
5. The user must specify the field length and type.
6. The field definitions must be separated with commas.
7. SQL statements must end with a semicolon.
Advantages and Disadvantages of SQL
Structural Query Language (SQL) is a powerful and widely used programming language designed for
managing and manipulating relational databases. It was first developed in the 1970s by IBM
researchers, and has since become a standard language for managing and querying databases across
various platforms and industries. SQL enables users to perform complex operations such as querying,
inserting, updating, and deleting data in a database. Its simple and user-friendly syntax allows even
non-technical users to interact with databases and retrieve data without having to write lengthy lines
of code. SQL also provides a standardized way of communicating with databases, ensuring that data
is consistent and uniform across different systems. Its popularity and versatility have made it a must-
have skill for data professionals and developers, as it is used extensively in various applications such
as web development, data analytics, business intelligence, and more.
Need of SQL :
 It is widely used in the Business Intelligence tool.
 Data Manipulation and data testing are done through SQL.
 Data Science tools depend highly on SQL. Big data tools such as Spark, Impala are dependent
on SQL.
 It is one of the demanding industrial skills.
Advantages of SQL :
SQL has many advantages which makes it popular and highly demanded. It is a reliable and efficient
language used for communicating with the database. Some advantages of SQL are as follows:
1. Faster Query Processing: Large amount of data is retrieved quickly and efficiently.
Operations like Insertion, deletion, manipulation of data is also done in almost no time.
2. No Coding Skills: For data retrieval, large number of lines of code is not required. All basic
keywords such as SELECT, INSERT INTO, UPDATE, etc are used and also the syntactical rules
are not complex in SQL, which makes it a user-friendly language.
3. Standardized Language: Due to documentation and long establishment over years, it
provides a uniform platform worldwide to all its users.
4. Portable: It can be used in programs in PCs, server, laptops independent of any platform
(Operating System, etc). Also, it can be embedded with other applications as per
need/requirement/use.
5. Interactive Language : Easy to learn and understand, answers to complex queries can be
received in seconds.
6. Multiple data views : One of the advantages of SQL is its ability to provide multiple data
views. This means that SQL allows users to create different views or perspectives of the data
stored in a database, depending on their needs and permissions.
7. Scalability : SQL databases can handle large volumes of data and can be scaled up or down
as per the requirements of the application.
8. Security : SQL databases have built-in security features that help protect data from
unauthorized access, such as user authentication, encryption, and access control.
9. Data Integrity : SQL databases enforce data integrity by enforcing constraints such as unique
keys, primary keys, and foreign keys, which help prevent data duplication and maintain data
accuracy.
10. Backup and Recovery : SQL databases have built-in backup and recovery tools that help
recover data in case of system failures, crashes, or other disasters.
11. Data Consistency: SQL databases ensure consistency of data across multiple tables through
the use of transactions, which ensure that changes made to one table are reflected in all
related tables.
Disadvantages of SQL :
Although SQL has many advantages, still there are a few disadvantages.
Various Disadvantages of SQL are as follows:
1. Complex Interface : SQL has a difficult interface that makes few users uncomfortable while
dealing with the database.
2. Cost : Some versions are costly and hence, programmers cannot access it.
3. Partial Control : Due to hidden business rules, complete control is not given to the database.
4. Limited Flexibility: SQL databases are less flexible than NoSQL databases when it comes to
handling unstructured or semi-structured data, as they require data to be structured into
tables and columns.
5. Lack of Real-Time Analytics: SQL databases are designed for batch processing and do not
support real-time analytics, which can be a disadvantage for applications that require real-
time data processing.
6. Limited Query Performance: SQL databases may have limited query performance when
dealing with large datasets, as queries may take longer to process than in-memory
databases.
7. Complexity: SQL databases can be complex to set up and manage, requiring skilled database
administrators to ensure optimal performance and maintain data integrity.
SQL Data Types
A column’s data type is essentially the type of data format that will be used to store the data in each
cell; examples include any type of integer, character, money, date and time, binary, etc. We’ll acquire
in-depth information about SQL Data Types in this tutorial.
SQL Data Types
An SQL developer must know what data type will be stored inside each column while creating a
table. The data type guideline for SQL is to understand what type of data is expected inside each
column and it also identifies how SQL will interact with the stored data.
For every database, data types are primarily classified into three categories.
 Numeric Datatypes
 Date and Time Datatypes
 String Datatypes
Like in other programming languages, SQL also has certain datatypes available. A brief idea of all the
datatypes is discussed below.
Numeric Data Types in MYSQL
Exact Numeric Datatype
There are nine subtypes which are given below in the table. The table contains the range of data in a
particular type.
Data Type From To
BigInt
-263 (-
9,223,372,036,854,775,808)
263 -1 (9,223,372,036,854,775,807)
Int -231 (-2,147,483,648) 231-1 (2,147,483,647)
smallint -215 (-32,768) 215-1 (32,767)
tinyint 0 28-1 (255)
bit 0 1
decimal -1038+1 1038-1
numeric -1038+1 1038-1
money -922,337,203,685,477.5808 922,337,203,685,477.5807
smallmoney -214,748.3648 214,748.3647
Approximate Numeric Datatype
The subtypes of this datatype are given in the table with the range.
Data
Type From To
Float -1.79E+308 1.79E+308
Real -3.40E+38 3.40E+38
String Data Types in MYSQL
Character String Datatype
The subtypes are given in below table –
Data Type Description
char The maximum length of 8000 characters.(Fixed-Length non-Unicode Characters)
varchar
The maximum length of 8000 characters.(Variable-Length non-Unicode
Characters)
varchar(max)
The maximum length of 231 characters(SQL Server 2005 only).(Variable Length
non-Unicode data)
text
The maximum length of 2,127,483,647 characters(Variable Length non-Unicode
data)
SQL commands are extensively used to interact with databases, enabling users to perform a wide
range of actions on database systems. Understanding these commands is crucial for effectively
managing and manipulating data.
This guide will introduce you to the various SQL sublanguage commands, including Data Definition
Language (DDL), Data Query Language (DQL), Data Manipulation Language (DML), Data Control
Language (DCL), and Transaction Control Language (TCL)
Here we covered all Important SQL commands, including their syntax and examples.
Table of Content
 Short Overview of SQL
 DDL (Data Definition Language)
 DQL (Data Query Language)
 DML (Data Manipulation Language)
 DCL (Data Control Language)
 TCL (Transaction Control Language)
 Important SQL Commands
 SQL Commands With Examples
But before heading to the SQL command section, let’s briefly introduce SQL.
Short Overview of SQL
Structured Query Language (SQL), as we all know, is the database language by which we can perform
certain operations on the existing database, and we can also use this language to create a database.
SQL uses certain commands like CREATE, DROP, INSERT, etc. to carry out the required tasks.
SQL Commands are like instructions to a table. It is used to interact with the database with some
operations. It is also used to perform specific tasks, functions, and queries of data. SQL can perform
various tasks like creating a table, adding data to tables, dropping the table, modifying the table, set
permission for users.
SQL Commands are mainly categorized into five categories:
1. DDL – Data Definition Language
2. DQL – Data Query Language
3. DML – Data Manipulation Language
4. DCL – Data Control Language
5. TCL – Transaction Control Language
Lets see all of these in detail.
DDL (Data Definition Language)
DDL or Data Definition Language actually consists of the SQL commands that can be used to define
the database schema. It simply deals with descriptions of the database schema and is used to create
and modify the structure of database objects in the database.
DDL is a set of SQL commands used to create, modify, and delete database structures but not data.
These commands are normally not used by a general user, who should be accessing the database via
an application.
List of DDL Commands:
Here are all the main DDL (Data Definition Language) commands along with their syntax:
Command Description Syntax
CREATE
Create database or its objects
(table, index, function, views,
store procedure, and triggers)
CREATE TABLE table_name (column1
data_type, column2 data_type, ...);
Command Description Syntax
DROP
Delete objects from the
database
DROP TABLE table_name;
ALTER
Alter the structure of the
database
ALTER TABLE table_name ADD
COLUMN column_name data_type;
TRUNCATE
Remove all records from a table,
including all spaces allocated for
the records are removed
TRUNCATE TABLE table_name;
COMMENT
Add comments to the data
dictionary
COMMENT 'comment_text' ON TABLE
table_name;
SQL Operators
SQL Operators perform arithmetic, comparison, and logical operations to manipulate and retrieve
data from databases.
In this article, we will discuss Operators in SQL with examples, and understand how they work in SQL.
Operators in SQL
Operators in SQL are symbols that help us to perform specific mathematical and logical computations
on operands. An operator can either be unary or binary.
The unary operator operates on one operand, and the binary operator operates on two operands.
Types of Operators in SQL
Different types of operators in SQL are:
 Arithmetic operator
 Comparison operator
 Logical operator
 Bitwise Operators
 Compound Operators
SQL Arithmetic Operators
Arithmetic operators in SQL are used to perform mathematical operations on numeric values in
queries. Some common arithmetic operators are:
Operator Description
+ The addition is used to perform an addition operation on the data values.
– This operator is used for the subtraction of the data values.
/ This operator works with the ‘ALL’ keyword and it calculates division operations.
* This operator is used for multiplying data values.
% Modulus is used to get the remainder when data is divided by another.
SQL Arithmetic Operators Example
In this example, we will retrieve all records from the “employee” table where the “emp_city” column
does not start with the letter ‘A’.
Query:
SELECT * FROM employee WHERE emp_city NOT LIKE 'A%';
Output:
SQL Comparison Operators
Comparison Operators in SQL are used to compare one expression’s value to other expressions. SQL
supports different types of comparison operator, which are described below:
Operato
r Description
= Equal to.
Operato
r Description
> Greater than.
< Less than.
>= Greater than equal to.
<= Less than equal to.
<> Not equal to.
SQL Comparison Operators Example
In this example, we will retrieve all records from the “MATHS” table where the value in the “MARKS”
column is equal to 50.
Query:
SELECT * FROM MATHS WHERE MARKS=50;
Output:
SQL Logical Operators
Logical Operators in SQL are used to combine or manipulate conditions in SQL queries to retrieve or
manipulate data based on specified criteria..
Operato
r Description
AND
Logical AND compares two Booleans as expressions and returns true when both
expressions are true.
OR
Logical OR compares two Booleans as expressions and returns true when one of the
expressions is true.
NOT
Not takes a single Boolean as an argument and change its value from false to true or
from true to false.
SQL Logical Operators Example
In this example, retrieve all records from the “employee” table where the “emp_city” column is
equal to ‘Allahabad’ and the “emp_country” column is equal to ‘India’.
SELECT * FROM employee WHERE emp_city =
'Allahabad' AND emp_country = 'India';
Output:
SQL Bitwise Operators
Bitwise operators in SQL are used to perform bitwise operations on binary values in SQL queries,
manipulating individual bits to perform logical operations at the bit level. Some SQL Bitwise
Operators are:
Operato
r Description
& Bitwise AND operator
| Bitwise OR operator
Operato
r Description
^ Bitwise XOR (exclusive OR) operator
~ Bitwise NOT (complement) operator
<< Left shift operator
>> Right shift operator
SQL Compound Operators
Compound operator in SQL are used to perform an operation and assign the result to the original
value in a single line. Some Compound operators are:
Operato
r Description
+= Add and assign
-= Subtract and assign
*= Multiply and assign
/= Divide and assign
%= Modulo and assign
&= Bitwise AND and assign
^= Bitwise XOR and assign
|= Bitwise OR and assign
SQL Special Operators
Special operators are used in SQL queries to perform specific operations like comparing values,
checking for existence, and filtering data based on certain conditions.
Operators Description
ALL
ALL is used to select all records of a SELECT STATEMENT. It compares a value to
every value in a list of results from a query. The ALL must be preceded by the
comparison operators and evaluated to TRUE if the query returns no rows.
ANY
ANY compares a value to each value in a list of results from a query and
evaluates to true if the result of an inner query contains at least one row.
BETWEEN
The SQL BETWEEN operator tests an expression against a range. The range
consists of a beginning, followed by an AND keyword and an end expression.
IN
The IN operator checks a value within a set of values separated by commas
and retrieves the rows from the table that match.
EXISTS
The EXISTS checks the existence of a result of a subquery. The EXISTS
subquery tests whether a subquery fetches at least one row. When no data is
returned then this operator returns ‘FALSE’.
SOME
SOME operator evaluates the condition between the outer and inner tables
and evaluates to true if the final result returns any one row. If not, then it
evaluates to false.
UNIQUE The UNIQUE operator searches every unique row of a specified table.
SQL Special Operator Example
In this example, we will retrieve all records from the “employee” table where the “emp_id” column
has a value that falls within the range of 101 to 104 (inclusive).
SELECT * FROM employee WHERE emp_id BETWEEN 101 AND 104;
Output:
Conclusion
SQL Operators are used to perform various operations on the data using SQL queries. These
operators simplify arithmetic, comparison , logical, and bitwise operations on the data.
https://theintactone.com/2022/02/27/tables-views-and-indexes-in-sql/
TABLES, VIEWS, INDEX IN SQL – REFER TO ABOVE LINK
About Queries and Subqueries
A query is an operation that retrieves data from one or more tables or views. In this reference, a top-
level SELECT statement is called a query, and a query nested within another SQL statement is called
a subquery.
This section describes some types of queries and subqueries and how to use them. The top level of
the syntax is shown in this chapter. Refer to SELECT for the full syntax of all the clauses and the
semantics of this statement.
select::=
subquery::=
SQL Aggregate Functions
An aggregate function is a function that performs a calculation on a set of values, and returns a single
value.
Aggregate functions are often used with the GROUP BY clause of the SELECT statement. The GROUP
BY clause splits the result-set into groups of values and the aggregate function can be used to return
a single value for each group.
The most commonly used SQL aggregate functions are:
 MIN() - returns the smallest value within the selected column
 MAX() - returns the largest value within the selected column
 COUNT() - returns the number of rows in a set
 SUM() - returns the total sum of a numerical column
 AVG() - returns the average value of a numerical column
Aggregate functions ignore null values (except for COUNT()).
nsert, Update, and Delete (CRUD) operations are used to manage and manipulate data in a database:
 Insert: Adds new records or rows to a table
 Update: Modifies existing records in a table
 Delete: Removes records from a table
Here are some examples of how to use these operations:
 Insert
To create a new record in a table, use the statement INSERT INTO table_name (column1, column2,
column3, ...) VALUES (value1, value2, value3, ...)
 Update
To modify a record, use the statement UPDATE table_name SET column1 = value1, column2 = value2,
... WHERE condition
 Delete
To remove a record, use the statement DELETE FROM table_name WHERE condition
Joins, unions, intersections, minus, cursors, and triggers are all related to SQL, and are used for
different purposes:
 Joins
There are various types of joins in SQL, including equi joins, outer joins, cartesian joins, and self
joins.
 Unions, intersections, and minus
These are set operators that combine the results of multiple queries:
 UNION: Combines all distinct rows from either query, eliminating duplicates
 UNION ALL: Combines all rows from either query, including duplicates
 INTERSECT: Combines only the rows that are common to both queries
 MINUS: Combines all rows that are in the first query but not in the second
 Cursors
A cursor is used to retrieve and manipulate data row by row.
 Triggers
A trigger is automatically executed when a data modification operation, such as an INSERT, UPDATE,
or DELETE operation, occurs. There are three types of triggers:
 DML triggers: Automatically fired when an INSERT, UPDATE, or DELETE event occurs
on a table
 DDL triggers: Automatically invoked when a CREATE, ALTER, or DROP event occurs in
a database
 Logon triggers: Invoked when a LOGON event is raised when a user session is
established

More Related Content

PPTX
introduction to relational model and codds rule.pptx
PDF
unit-3_Chapter1_RDRA.pdf
PPTX
Lecture 2 - Database Management System.pptx
PDF
SQL Server Interview Questions PDF By ScholarHat
PPTX
Unit 2 DBMS.pptx
DOCX
Database testing
DOCX
Dbms important questions and answers
DOCX
Dbms interview ques
introduction to relational model and codds rule.pptx
unit-3_Chapter1_RDRA.pdf
Lecture 2 - Database Management System.pptx
SQL Server Interview Questions PDF By ScholarHat
Unit 2 DBMS.pptx
Database testing
Dbms important questions and answers
Dbms interview ques

Similar to DBMS UNIT 2 NOTES.docx AKTU SYLLABUS DBMS UNIT 2 NOTES.docx AKTU SYLLABUSDBMS UNIT 2 NOTES.docx AKTU SYLLABUS (20)

PPTX
Introduction DBMS, RDBMS and SQL
PPTX
Relational Model and Relational Algebra.pptx
PDF
Adeshhazra_DBMS_ca1_bca4thsem.pdf
PPTX
Codds rules & keys
PPTX
Bank mangement system
PPTX
Previous question papers of Database Management System (DBMS) By SHABEEB
PDF
Sql Interview Questions
PDF
Sql
PDF
PDF
153680 sqlinterview
PDF
PPTX
codd rules of dbms given by E F codd who is called father of dbms
PPTX
Relational Data Model for computer science.pptx
PDF
Dbms interview questions
PPTX
PPT
DBMS unit 3.ppt semester 4 btech aktu 2024
PDF
Data Mining And Data Warehousing Laboratory File Manual
PPTX
DBMS for beginners with examples.pptx
PPT
Database Technology Teaching Material For Learn
PDF
Top DBMS Interview Questions and Answers.pdf
Introduction DBMS, RDBMS and SQL
Relational Model and Relational Algebra.pptx
Adeshhazra_DBMS_ca1_bca4thsem.pdf
Codds rules & keys
Bank mangement system
Previous question papers of Database Management System (DBMS) By SHABEEB
Sql Interview Questions
Sql
153680 sqlinterview
codd rules of dbms given by E F codd who is called father of dbms
Relational Data Model for computer science.pptx
Dbms interview questions
DBMS unit 3.ppt semester 4 btech aktu 2024
Data Mining And Data Warehousing Laboratory File Manual
DBMS for beginners with examples.pptx
Database Technology Teaching Material For Learn
Top DBMS Interview Questions and Answers.pdf
Ad

Recently uploaded (20)

PPTX
Current and future trends in Computer Vision.pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
composite construction of structures.pdf
PPTX
Safety Seminar civil to be ensured for safe working.
PPT
Project quality management in manufacturing
PPT
Mechanical Engineering MATERIALS Selection
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPT
introduction to datamining and warehousing
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Well-logging-methods_new................
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
DOCX
573137875-Attendance-Management-System-original
PPTX
Artificial Intelligence
Current and future trends in Computer Vision.pptx
CYBER-CRIMES AND SECURITY A guide to understanding
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
composite construction of structures.pdf
Safety Seminar civil to be ensured for safe working.
Project quality management in manufacturing
Mechanical Engineering MATERIALS Selection
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
bas. eng. economics group 4 presentation 1.pptx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
introduction to datamining and warehousing
R24 SURVEYING LAB MANUAL for civil enggi
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Operating System & Kernel Study Guide-1 - converted.pdf
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Well-logging-methods_new................
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
573137875-Attendance-Management-System-original
Artificial Intelligence
Ad

DBMS UNIT 2 NOTES.docx AKTU SYLLABUS DBMS UNIT 2 NOTES.docx AKTU SYLLABUSDBMS UNIT 2 NOTES.docx AKTU SYLLABUS

  • 1. UNIT-2 Constraints on Relational Database Model In modeling the design of the relational database we can put some restrictions like what values are allowed to be inserted in the relation, and what kind of modifications and deletions are allowed in the relation. These are the restrictions we impose on the relational database. In models like Entity-Relationship models, we did not have such features. Database Constraints can be categorized into 3 main categories: 1. Constraints that are applied in the data model are called Implicit Constraints. 2. Constraints that are directly applied in the schemas of the data model, by specifying them in the DDL(Data Definition Language). These are called Schema-Based Constraints or Explicit Constraints. 3. Constraints that cannot be directly applied in the schemas of the data model. We call these Application-based or Semantic Constraints. So here we are going to deal with Implicit constraints. Relational Constraints These are the restrictions or sets of rules imposed on the database contents. It validates the quality of the database. It validates the various operations like data insertion, updation, and other processes that have to be performed without affecting the integrity of the data. It protects us against threats/damages to the database. Mainly Constraints on the relational database are of 4 types  Domain constraints  Key constraints or Uniqueness Constraints  Entity Integrity constraints  Referential integrity constraints
  • 2. Types of Relational Constraints Let’s discuss each of the above constraints in detail. 1. Domain Constraints  Every domain must contain atomic values(smallest indivisible units) which means composite and multi-valued attributes are not allowed.  We perform a datatype check here, which means when we assign a data type to a column we limit the values that it can contain. Eg. If we assign the datatype of attribute age as int, we can’t give it values other than int datatype. Example: EID Name Phone 01 Bikash Dutta 123456789 234456678 Explanation: In the above relation, Name is a composite attribute and Phone is a multi-values attribute, so it is violating domain constraint. 2. Key Constraints or Uniqueness Constraints  These are called uniqueness constraints since it ensures that every tuple in the relation should be unique.  A relation can have multiple keys or candidate keys(minimal superkey), out of which we choose one of the keys as the primary key, we don’t have any restriction on choosing the primary key out of candidate keys, but it is suggested to go with the candidate key with less number of attributes.  Null values are not allowed in the primary key, hence Not Null constraint is also part of the key constraint. Example: EID Name Phone 01 Bikash 6000000009 02 Paul 9000090009 01 Tuhin 9234567892
  • 3. Explanation: In the above relation, Name is a composite attribute and Phone is a multi-values attribute, so it is violating domain constraint. 2. Key Constraints or Uniqueness Constraints  These are called uniqueness constraints since it ensures that every tuple in the relation should be unique.  A relation can have multiple keys or candidate keys(minimal superkey), out of which we choose one of the keys as the primary key, we don’t have any restriction on choosing the primary key out of candidate keys, but it is suggested to go with the candidate key with less number of attributes.  Null values are not allowed in the primary key, hence Not Null constraint is also part of the key constraint. Example: EID Name Phone 01 Bikash 6000000009 02 Paul 9000090009 01 Tuhin 9234567892 Explanation: In the above table, EID is the primary key, and the first and the last tuple have the same value in EID ie 01, so it is violating the key constraint. 3. Entity Integrity Constraints  Entity Integrity constraints say that no primary key can take a NULL value, since using the primary key we identify each tuple uniquely in a relation. Example: EID Name Phone 01 Bikash 9000900099 02 Paul 600000009 NULL Sony 9234567892
  • 4. Explanation: In the above relation, EID is made the primary key, and the primary key can’t take NULL values but in the third tuple, the primary key is null, so it is violating Entity Integrity constraints. 4. Referential Integrity Constraints  The Referential integrity constraint is specified between two relations or tables and used to maintain the consistency among the tuples in two relations.  This constraint is enforced through a foreign key, when an attribute in the foreign key of relation R1 has the same domain(s) as the primary key of relation R2, then the foreign key of R1 is said to reference or refer to the primary key of relation R2.  The values of the foreign key in a tuple of relation R1 can either take the values of the primary key for some tuple in relation R2, or can take NULL values, but can’t be empty. Example: EID Name DNO 01 Divine 12 02 Dino 22 04 Vivian 14 DNO Place 12 Jaipur 13 Mumbai 14 Delhi Explanation: In the above tables, the DNO of Table 1 is the foreign key, and DNO in Table 2 is the primary key. DNO = 22 in the foreign key of Table 1 is not allowed because DNO = 22 is not defined in the primary key of table 2. Therefore, Referential integrity constraints are violated here. Advantages of Relational Database Model  It is simpler than the hierarchical model and network model.  It is easy and simple to understand.  Its structure can be changed anytime upon requirement.
  • 5.  Data Integrity: The relational database model enforces data integrity through various constraints such as primary keys, foreign keys, and unique constraints. This ensures that the data in the database is accurate, consistent, and valid.  Flexibility: The relational database model is highly flexible and can handle a wide range of data types and structures. It also allows for easy modification and updating of the data without affecting other parts of the database.  Scalability: The relational database model can scale to handle large amounts of data by adding more tables, indexes, or partitions to the database. This allows for better performance and faster query response times.  Security: The relational database model provides robust security features to protect the data in the database. These include user authentication, authorization, and encryption of sensitive data.  Data consistency: The relational database model ensures that the data in the database is consistent across all tables. This means that if a change is made to one table, the corresponding changes will be made to all related tables.  Query Optimization: The relational database model provides a query optimizer that can analyze and optimize SQL queries to improve their performance. This allows for faster query response times and better scalability. Disadvantages of the Relational Model  Few database relations have certain limits which can’t be expanded further.  It can be complex and it becomes hard to use.  Complexity: The relational model can be complex and difficult to understand, particularly for users who are not familiar with SQL and database design principles. This can make it challenging to set up and maintain a relational database.  Performance: The relational model can suffer from performance issues when dealing with large data sets or complex queries. In particular, joins between tables can be slow, and indexing strategies can be difficult to optimize.  Scalability: While the relational model is generally scalable, it can become difficult to manage as the database grows in size. Adding new tables or indexes can be time-consuming, and managing relationships between tables can become complex.  Cost: Relational databases can be expensive to license and maintain, particularly for large- scale deployments. Additionally, relational databases often require dedicated hardware and specialized software to run, which can add to the cost.  Limited flexibility: The relational model is designed to work with tables that have predefined structures and relationships. This can make it difficult to work with data that does not fit neatly into a table-based format, such as unstructured or semi-structured data.  Data redundancy: In some cases, the relational model can lead to data redundancy, where the same data is stored in multiple tables. This can lead to inefficiencies and can make it difficult to ensure data consistency across the database.
  • 6. INTRODUCTION TO SQL is a standard language to write queries. It was developed under R Project by IBM. SQL has a basic grammar and syntax. It was declared as a standard language to use by American Standard National Institute(ANSI) and International Standard Organization(ISO). The functionality of SQL language is virtually similar across the operating system platforms. Using SQL doesn’t require programming experience, but programming experience helps one to conceptualize what a particular SQL command will help to execute and retrieve SQL queries. Characteristics and Benefits of Structured Query Language: The ANSI SQL provides with:  Specific syntax and semantics of SQL data definition and data manipulation languages.  It also provides with basic data structure and operations for designing, assessing, maintaining, controlling and protecting SQL databases.  Portability of database definition and application is also provided. Applications can be moved from one machine to another.  IS professionals share a common language and reduce training costs.  Professionals can become proficient in its use and increase the productivity.  It provides with longevity.  It provides with reduced dependence on single vendor. Rules to write commands: 1. Table names cannot exceed 20 characters. 2. Name of the table must be unique. 3. Field names also must be unique. 4. The field list and filed length must be enclosed in parentheses. 5. The user must specify the field length and type. 6. The field definitions must be separated with commas. 7. SQL statements must end with a semicolon. Advantages and Disadvantages of SQL Structural Query Language (SQL) is a powerful and widely used programming language designed for managing and manipulating relational databases. It was first developed in the 1970s by IBM researchers, and has since become a standard language for managing and querying databases across various platforms and industries. SQL enables users to perform complex operations such as querying, inserting, updating, and deleting data in a database. Its simple and user-friendly syntax allows even non-technical users to interact with databases and retrieve data without having to write lengthy lines of code. SQL also provides a standardized way of communicating with databases, ensuring that data is consistent and uniform across different systems. Its popularity and versatility have made it a must-
  • 7. have skill for data professionals and developers, as it is used extensively in various applications such as web development, data analytics, business intelligence, and more. Need of SQL :  It is widely used in the Business Intelligence tool.  Data Manipulation and data testing are done through SQL.  Data Science tools depend highly on SQL. Big data tools such as Spark, Impala are dependent on SQL.  It is one of the demanding industrial skills. Advantages of SQL : SQL has many advantages which makes it popular and highly demanded. It is a reliable and efficient language used for communicating with the database. Some advantages of SQL are as follows: 1. Faster Query Processing: Large amount of data is retrieved quickly and efficiently. Operations like Insertion, deletion, manipulation of data is also done in almost no time. 2. No Coding Skills: For data retrieval, large number of lines of code is not required. All basic keywords such as SELECT, INSERT INTO, UPDATE, etc are used and also the syntactical rules are not complex in SQL, which makes it a user-friendly language. 3. Standardized Language: Due to documentation and long establishment over years, it provides a uniform platform worldwide to all its users. 4. Portable: It can be used in programs in PCs, server, laptops independent of any platform (Operating System, etc). Also, it can be embedded with other applications as per need/requirement/use. 5. Interactive Language : Easy to learn and understand, answers to complex queries can be received in seconds. 6. Multiple data views : One of the advantages of SQL is its ability to provide multiple data views. This means that SQL allows users to create different views or perspectives of the data stored in a database, depending on their needs and permissions. 7. Scalability : SQL databases can handle large volumes of data and can be scaled up or down as per the requirements of the application. 8. Security : SQL databases have built-in security features that help protect data from unauthorized access, such as user authentication, encryption, and access control. 9. Data Integrity : SQL databases enforce data integrity by enforcing constraints such as unique keys, primary keys, and foreign keys, which help prevent data duplication and maintain data accuracy. 10. Backup and Recovery : SQL databases have built-in backup and recovery tools that help recover data in case of system failures, crashes, or other disasters.
  • 8. 11. Data Consistency: SQL databases ensure consistency of data across multiple tables through the use of transactions, which ensure that changes made to one table are reflected in all related tables. Disadvantages of SQL : Although SQL has many advantages, still there are a few disadvantages. Various Disadvantages of SQL are as follows: 1. Complex Interface : SQL has a difficult interface that makes few users uncomfortable while dealing with the database. 2. Cost : Some versions are costly and hence, programmers cannot access it. 3. Partial Control : Due to hidden business rules, complete control is not given to the database. 4. Limited Flexibility: SQL databases are less flexible than NoSQL databases when it comes to handling unstructured or semi-structured data, as they require data to be structured into tables and columns. 5. Lack of Real-Time Analytics: SQL databases are designed for batch processing and do not support real-time analytics, which can be a disadvantage for applications that require real- time data processing. 6. Limited Query Performance: SQL databases may have limited query performance when dealing with large datasets, as queries may take longer to process than in-memory databases. 7. Complexity: SQL databases can be complex to set up and manage, requiring skilled database administrators to ensure optimal performance and maintain data integrity. SQL Data Types A column’s data type is essentially the type of data format that will be used to store the data in each cell; examples include any type of integer, character, money, date and time, binary, etc. We’ll acquire in-depth information about SQL Data Types in this tutorial. SQL Data Types An SQL developer must know what data type will be stored inside each column while creating a table. The data type guideline for SQL is to understand what type of data is expected inside each column and it also identifies how SQL will interact with the stored data. For every database, data types are primarily classified into three categories.  Numeric Datatypes  Date and Time Datatypes  String Datatypes Like in other programming languages, SQL also has certain datatypes available. A brief idea of all the datatypes is discussed below. Numeric Data Types in MYSQL
  • 9. Exact Numeric Datatype There are nine subtypes which are given below in the table. The table contains the range of data in a particular type. Data Type From To BigInt -263 (- 9,223,372,036,854,775,808) 263 -1 (9,223,372,036,854,775,807) Int -231 (-2,147,483,648) 231-1 (2,147,483,647) smallint -215 (-32,768) 215-1 (32,767) tinyint 0 28-1 (255) bit 0 1 decimal -1038+1 1038-1 numeric -1038+1 1038-1 money -922,337,203,685,477.5808 922,337,203,685,477.5807 smallmoney -214,748.3648 214,748.3647 Approximate Numeric Datatype The subtypes of this datatype are given in the table with the range. Data Type From To Float -1.79E+308 1.79E+308 Real -3.40E+38 3.40E+38
  • 10. String Data Types in MYSQL Character String Datatype The subtypes are given in below table – Data Type Description char The maximum length of 8000 characters.(Fixed-Length non-Unicode Characters) varchar The maximum length of 8000 characters.(Variable-Length non-Unicode Characters) varchar(max) The maximum length of 231 characters(SQL Server 2005 only).(Variable Length non-Unicode data) text The maximum length of 2,127,483,647 characters(Variable Length non-Unicode data) SQL commands are extensively used to interact with databases, enabling users to perform a wide range of actions on database systems. Understanding these commands is crucial for effectively managing and manipulating data. This guide will introduce you to the various SQL sublanguage commands, including Data Definition Language (DDL), Data Query Language (DQL), Data Manipulation Language (DML), Data Control Language (DCL), and Transaction Control Language (TCL) Here we covered all Important SQL commands, including their syntax and examples. Table of Content  Short Overview of SQL  DDL (Data Definition Language)  DQL (Data Query Language)  DML (Data Manipulation Language)  DCL (Data Control Language)  TCL (Transaction Control Language)  Important SQL Commands  SQL Commands With Examples
  • 11. But before heading to the SQL command section, let’s briefly introduce SQL. Short Overview of SQL Structured Query Language (SQL), as we all know, is the database language by which we can perform certain operations on the existing database, and we can also use this language to create a database. SQL uses certain commands like CREATE, DROP, INSERT, etc. to carry out the required tasks. SQL Commands are like instructions to a table. It is used to interact with the database with some operations. It is also used to perform specific tasks, functions, and queries of data. SQL can perform various tasks like creating a table, adding data to tables, dropping the table, modifying the table, set permission for users. SQL Commands are mainly categorized into five categories: 1. DDL – Data Definition Language 2. DQL – Data Query Language 3. DML – Data Manipulation Language 4. DCL – Data Control Language 5. TCL – Transaction Control Language Lets see all of these in detail.
  • 12. DDL (Data Definition Language) DDL or Data Definition Language actually consists of the SQL commands that can be used to define the database schema. It simply deals with descriptions of the database schema and is used to create and modify the structure of database objects in the database. DDL is a set of SQL commands used to create, modify, and delete database structures but not data. These commands are normally not used by a general user, who should be accessing the database via an application. List of DDL Commands: Here are all the main DDL (Data Definition Language) commands along with their syntax: Command Description Syntax CREATE Create database or its objects (table, index, function, views, store procedure, and triggers) CREATE TABLE table_name (column1 data_type, column2 data_type, ...);
  • 13. Command Description Syntax DROP Delete objects from the database DROP TABLE table_name; ALTER Alter the structure of the database ALTER TABLE table_name ADD COLUMN column_name data_type; TRUNCATE Remove all records from a table, including all spaces allocated for the records are removed TRUNCATE TABLE table_name; COMMENT Add comments to the data dictionary COMMENT 'comment_text' ON TABLE table_name; SQL Operators SQL Operators perform arithmetic, comparison, and logical operations to manipulate and retrieve data from databases. In this article, we will discuss Operators in SQL with examples, and understand how they work in SQL. Operators in SQL Operators in SQL are symbols that help us to perform specific mathematical and logical computations on operands. An operator can either be unary or binary. The unary operator operates on one operand, and the binary operator operates on two operands. Types of Operators in SQL Different types of operators in SQL are:  Arithmetic operator  Comparison operator  Logical operator  Bitwise Operators  Compound Operators SQL Arithmetic Operators Arithmetic operators in SQL are used to perform mathematical operations on numeric values in queries. Some common arithmetic operators are:
  • 14. Operator Description + The addition is used to perform an addition operation on the data values. – This operator is used for the subtraction of the data values. / This operator works with the ‘ALL’ keyword and it calculates division operations. * This operator is used for multiplying data values. % Modulus is used to get the remainder when data is divided by another. SQL Arithmetic Operators Example In this example, we will retrieve all records from the “employee” table where the “emp_city” column does not start with the letter ‘A’. Query: SELECT * FROM employee WHERE emp_city NOT LIKE 'A%'; Output: SQL Comparison Operators Comparison Operators in SQL are used to compare one expression’s value to other expressions. SQL supports different types of comparison operator, which are described below: Operato r Description = Equal to.
  • 15. Operato r Description > Greater than. < Less than. >= Greater than equal to. <= Less than equal to. <> Not equal to. SQL Comparison Operators Example In this example, we will retrieve all records from the “MATHS” table where the value in the “MARKS” column is equal to 50. Query: SELECT * FROM MATHS WHERE MARKS=50; Output: SQL Logical Operators Logical Operators in SQL are used to combine or manipulate conditions in SQL queries to retrieve or manipulate data based on specified criteria..
  • 16. Operato r Description AND Logical AND compares two Booleans as expressions and returns true when both expressions are true. OR Logical OR compares two Booleans as expressions and returns true when one of the expressions is true. NOT Not takes a single Boolean as an argument and change its value from false to true or from true to false. SQL Logical Operators Example In this example, retrieve all records from the “employee” table where the “emp_city” column is equal to ‘Allahabad’ and the “emp_country” column is equal to ‘India’. SELECT * FROM employee WHERE emp_city = 'Allahabad' AND emp_country = 'India'; Output: SQL Bitwise Operators Bitwise operators in SQL are used to perform bitwise operations on binary values in SQL queries, manipulating individual bits to perform logical operations at the bit level. Some SQL Bitwise Operators are: Operato r Description & Bitwise AND operator | Bitwise OR operator
  • 17. Operato r Description ^ Bitwise XOR (exclusive OR) operator ~ Bitwise NOT (complement) operator << Left shift operator >> Right shift operator SQL Compound Operators Compound operator in SQL are used to perform an operation and assign the result to the original value in a single line. Some Compound operators are: Operato r Description += Add and assign -= Subtract and assign *= Multiply and assign /= Divide and assign %= Modulo and assign &= Bitwise AND and assign ^= Bitwise XOR and assign |= Bitwise OR and assign
  • 18. SQL Special Operators Special operators are used in SQL queries to perform specific operations like comparing values, checking for existence, and filtering data based on certain conditions. Operators Description ALL ALL is used to select all records of a SELECT STATEMENT. It compares a value to every value in a list of results from a query. The ALL must be preceded by the comparison operators and evaluated to TRUE if the query returns no rows. ANY ANY compares a value to each value in a list of results from a query and evaluates to true if the result of an inner query contains at least one row. BETWEEN The SQL BETWEEN operator tests an expression against a range. The range consists of a beginning, followed by an AND keyword and an end expression. IN The IN operator checks a value within a set of values separated by commas and retrieves the rows from the table that match. EXISTS The EXISTS checks the existence of a result of a subquery. The EXISTS subquery tests whether a subquery fetches at least one row. When no data is returned then this operator returns ‘FALSE’. SOME SOME operator evaluates the condition between the outer and inner tables and evaluates to true if the final result returns any one row. If not, then it evaluates to false. UNIQUE The UNIQUE operator searches every unique row of a specified table. SQL Special Operator Example In this example, we will retrieve all records from the “employee” table where the “emp_id” column has a value that falls within the range of 101 to 104 (inclusive). SELECT * FROM employee WHERE emp_id BETWEEN 101 AND 104; Output:
  • 19. Conclusion SQL Operators are used to perform various operations on the data using SQL queries. These operators simplify arithmetic, comparison , logical, and bitwise operations on the data. https://theintactone.com/2022/02/27/tables-views-and-indexes-in-sql/ TABLES, VIEWS, INDEX IN SQL – REFER TO ABOVE LINK About Queries and Subqueries A query is an operation that retrieves data from one or more tables or views. In this reference, a top- level SELECT statement is called a query, and a query nested within another SQL statement is called a subquery. This section describes some types of queries and subqueries and how to use them. The top level of the syntax is shown in this chapter. Refer to SELECT for the full syntax of all the clauses and the semantics of this statement. select::= subquery::= SQL Aggregate Functions An aggregate function is a function that performs a calculation on a set of values, and returns a single value. Aggregate functions are often used with the GROUP BY clause of the SELECT statement. The GROUP BY clause splits the result-set into groups of values and the aggregate function can be used to return a single value for each group.
  • 20. The most commonly used SQL aggregate functions are:  MIN() - returns the smallest value within the selected column  MAX() - returns the largest value within the selected column  COUNT() - returns the number of rows in a set  SUM() - returns the total sum of a numerical column  AVG() - returns the average value of a numerical column Aggregate functions ignore null values (except for COUNT()). nsert, Update, and Delete (CRUD) operations are used to manage and manipulate data in a database:  Insert: Adds new records or rows to a table  Update: Modifies existing records in a table  Delete: Removes records from a table Here are some examples of how to use these operations:  Insert To create a new record in a table, use the statement INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...)  Update To modify a record, use the statement UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition  Delete To remove a record, use the statement DELETE FROM table_name WHERE condition Joins, unions, intersections, minus, cursors, and triggers are all related to SQL, and are used for different purposes:  Joins There are various types of joins in SQL, including equi joins, outer joins, cartesian joins, and self joins.  Unions, intersections, and minus These are set operators that combine the results of multiple queries:  UNION: Combines all distinct rows from either query, eliminating duplicates  UNION ALL: Combines all rows from either query, including duplicates  INTERSECT: Combines only the rows that are common to both queries  MINUS: Combines all rows that are in the first query but not in the second  Cursors
  • 21. A cursor is used to retrieve and manipulate data row by row.  Triggers A trigger is automatically executed when a data modification operation, such as an INSERT, UPDATE, or DELETE operation, occurs. There are three types of triggers:  DML triggers: Automatically fired when an INSERT, UPDATE, or DELETE event occurs on a table  DDL triggers: Automatically invoked when a CREATE, ALTER, or DROP event occurs in a database  Logon triggers: Invoked when a LOGON event is raised when a user session is established