0% found this document useful (0 votes)
32 views22 pages

Unit 2 - Lecture 9 - RDBMS

This document discusses additional basic operations in SQL including rename operations and string operations. It also covers set operations like union, intersect, and except. Finally, it discusses null values and how they are handled in comparisons and set operations. Examples are provided for each topic.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views22 pages

Unit 2 - Lecture 9 - RDBMS

This document discusses additional basic operations in SQL including rename operations and string operations. It also covers set operations like union, intersect, and except. Finally, it discusses null values and how they are handled in comparisons and set operations. Examples are provided for each topic.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Unit -2

Additional Basic Operations – Set Operations –


Null Values

Lecture 09

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


Review of Previous Class Topic

• Basic Structure

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


Topic Outcome

• Additional Basic Operations – Set Operations –


Null Values

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


Additional Basic Operations

There are number of additional basic operations that are


supported in SQL

The Rename Operation

old-name as new-name

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


Additional Basic Operations

The Rename Operation

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


String Operations

SQL specifies strings by enclosing them in single quotes, for


example, ’Computer’. A single quote character that is part of a
string can be specified by using two single quote characters;
for example, the string “It’s right” can be specified by “It”s
right”.

Pattern matching can be performed on strings, using the


operator like. We describe patterns by using two special
characters:

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


String Operations

Patterns are case sensitive; that is, uppercase characters do


not match lowercase characters, or vice versa. To illustrate
pattern matching, we consider the following examples:

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


Where Clause Predicates

SQL includes a between comparison operator to simplify


where clauses that specify that a value be less than or equal
to some value and greater than or equal to some other value.
If we wish to find the names of instructors with salary
amounts between $90,000 and $100,000, we can use the
between comparison to write

instead of:
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Set Operations

The SQL operations union, intersect, and except operate on


relations and correspond to the mathematical set-theory
operations ∪, ∩, and −. We shall now construct queries
involving the union, intersect, and except operations over two
sets.
The set of all courses taught in the Fall 2009 semester:

The set of all courses taught in the Fall 2009 semester:

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


The Union Operation
To find the set of all courses taught either in Fall 2009 or in
Spring 2010, or both, we write:

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


The Union all Operation
If we want to retain all duplicates, we must write union all in
place of union:

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


The Intersect Operation
To find the set of all courses taught in the Fall 2009 as well as
in Spring 2010 we write:

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


The Except Operation
To find all courses taught in the Fall 2009 semester but not in
the Spring 2010 semester, we write:

All duplicates

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


Null Values
Null values present special problems in relational operations,
including arithmetic operations, comparison operations, and
set operations.

Since the predicate in a where clause can involve Boolean


operations such as and, or, and not on the results of
comparisons, the definitions of the Boolean operations are
extended to deal with the value unknown

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


Null Values

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


Try it yourself

• Create table department with following fields


department name, building, budget.

• In this table department name should be


primary key

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


Solution

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


Try it yourself

• Create table course with following field course


id, title, department name, credits.

• In this table Course id should be primary key


• And also, department name should be foreign
key.

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


Solution

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


Question

Expand DML __________________


a. Data-Definition Language
b. Data-Manipulation Language
c. Data Maintain Language
d. All of these

What is a foreign key?


A. A foreign key is a primary key of a relation which is an attribute in
another relation
B. A foreign key is a superkey of a relation which is an attribute in more
than one other relations
C. A foreign key is an attribute of a relation that is a primary key of
another relation..
D. A foreign key is the primary key of a relation that does not occur
anywhere else in the schema

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


Evaluation Questionnaires

1. What is SQL?
2. What is DML?

3. What is Primary Key?


4. What foreign Key?

5. Define Check Constraints.

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23


Next topic for Lect. 10

• Aggregate Functions – Nested Sub


queries

21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23

You might also like