This document discusses the relational data model and SQL. It begins with an overview of relational database design using ER-to-relational mapping. It then discusses relational model concepts such as relations, attributes, tuples, domains and keys. It also covers integrity constraints and SQL components like data definition, data types, and retrieval, modification and deletion queries. The document outlines topics such as relational algebra, calculus, and features of SQL like views, triggers and transactions. It provides learning objectives and expected outcomes of understanding these concepts.
Database normalization is the process of refining the data in accordance with a series of normal forms. This is done to reduce data redundancy and improve data integrity. This process divides large tables into small tables and links them using relationships.
Here is the link of full article: https://www.support.dbagenesis.com/post/database-normalization
● Data Modeling and Data Models.
● Business Rules (Translating Business Rules into Data Model Components).
● Emerging Data Models: Big Data and NoSQL.
● Degrees of Data Abstraction (External, Conceptual, Internal and Physical model).
Database normalization is the process of refining the data in accordance with a series of normal forms. This is done to reduce data redundancy and improve data integrity. This process divides large tables into small tables and links them using relationships.
Here is the link of full article: https://www.support.dbagenesis.com/post/database-normalization
● Data Modeling and Data Models.
● Business Rules (Translating Business Rules into Data Model Components).
● Emerging Data Models: Big Data and NoSQL.
● Degrees of Data Abstraction (External, Conceptual, Internal and Physical model).
Database systems that were based on the object data model were known originally as object-oriented databases (OODBs).These are mainly used for complex objects
This presentation discusses the following topics:
Object Oriented Databases
Object Oriented Data Model(OODM)
Characteristics of Object oriented database
Object, Attributes and Identity
Object oriented methodologies
Benefit of object orientation in programming language
Object oriented model vs Entity Relationship model
Advantages of OODB over RDBMS
What is Normalization in Database Management System (DBMS) ?
What is the history of the system of normalization?
Types of Normalizations,
and why this is needed all details in the presentation.
Database systems that were based on the object data model were known originally as object-oriented databases (OODBs).These are mainly used for complex objects
This presentation discusses the following topics:
Object Oriented Databases
Object Oriented Data Model(OODM)
Characteristics of Object oriented database
Object, Attributes and Identity
Object oriented methodologies
Benefit of object orientation in programming language
Object oriented model vs Entity Relationship model
Advantages of OODB over RDBMS
What is Normalization in Database Management System (DBMS) ?
What is the history of the system of normalization?
Types of Normalizations,
and why this is needed all details in the presentation.
Relations can be represented as two-dimensional data tables with rows and columns. The rows of a relation are called tuples.
The columns of a relation are called attributes. The attributes draw values from a domain (a legal pool of values).
Overview of the fundamental roles in Hydropower generation and the components involved in wider Electrical Engineering.
This paper presents the design and construction of hydroelectric dams from the hydrologist’s survey of the valley before construction, all aspects and involved disciplines, fluid dynamics, structural engineering, generation and mains frequency regulation to the very transmission of power through the network in the United Kingdom.
Author: Robbie Edward Sayers
Collaborators and co editors: Charlie Sims and Connor Healey.
(C) 2024 Robbie E. Sayers
Saudi Arabia stands as a titan in the global energy landscape, renowned for its abundant oil and gas resources. It's the largest exporter of petroleum and holds some of the world's most significant reserves. Let's delve into the top 10 oil and gas projects shaping Saudi Arabia's energy future in 2024.
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Dr.Costas Sachpazis
Terzaghi's soil bearing capacity theory, developed by Karl Terzaghi, is a fundamental principle in geotechnical engineering used to determine the bearing capacity of shallow foundations. This theory provides a method to calculate the ultimate bearing capacity of soil, which is the maximum load per unit area that the soil can support without undergoing shear failure. The Calculation HTML Code included.
About
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
• Remote control: Parallel or serial interface.
• Compatible with MAFI CCR system.
• Compatible with IDM8000 CCR.
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
• Easy in configuration using DIP switches.
Technical Specifications
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
Key Features
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
• Remote control: Parallel or serial interface
• Compatible with MAFI CCR system
• Copatiable with IDM8000 CCR
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
Application
• Remote control: Parallel or serial interface.
• Compatible with MAFI CCR system.
• Compatible with IDM8000 CCR.
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
• Easy in configuration using DIP switches.
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...Amil Baba Dawood bangali
Contact with Dawood Bhai Just call on +92322-6382012 and we'll help you. We'll solve all your problems within 12 to 24 hours and with 101% guarantee and with astrology systematic. If you want to take any personal or professional advice then also you can call us on +92322-6382012 , ONLINE LOVE PROBLEM & Other all types of Daily Life Problem's.Then CALL or WHATSAPP us on +92322-6382012 and Get all these problems solutions here by Amil Baba DAWOOD BANGALI
#vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore#blackmagicformarriage #aamilbaba #kalajadu #kalailam #taweez #wazifaexpert #jadumantar #vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore #blackmagicforlove #blackmagicformarriage #aamilbaba #kalajadu #kalailam #taweez #wazifaexpert #jadumantar #vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore #Amilbabainuk #amilbabainspain #amilbabaindubai #Amilbabainnorway #amilbabainkrachi #amilbabainlahore #amilbabaingujranwalan #amilbabainislamabad
Final project report on grocery store management system..pdfKamal Acharya
In today’s fast-changing business environment, it’s extremely important to be able to respond to client needs in the most effective and timely manner. If your customers wish to see your business online and have instant access to your products or services.
Online Grocery Store is an e-commerce website, which retails various grocery products. This project allows viewing various products available enables registered users to purchase desired products instantly using Paytm, UPI payment processor (Instant Pay) and also can place order by using Cash on Delivery (Pay Later) option. This project provides an easy access to Administrators and Managers to view orders placed using Pay Later and Instant Pay options.
In order to develop an e-commerce website, a number of Technologies must be studied and understood. These include multi-tiered architecture, server and client-side scripting techniques, implementation technologies, programming language (such as PHP, HTML, CSS, JavaScript) and MySQL relational databases. This is a project with the objective to develop a basic website where a consumer is provided with a shopping cart website and also to know about the technologies used to develop such a website.
This document will discuss each of the underlying technologies to create and implement an e- commerce website.
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)MdTanvirMahtab2
This presentation is about the working procedure of Shahjalal Fertilizer Company Limited (SFCL). A Govt. owned Company of Bangladesh Chemical Industries Corporation under Ministry of Industries.
Immunizing Image Classifiers Against Localized Adversary Attacksgerogepatton
This paper addresses the vulnerability of deep learning models, particularly convolutional neural networks
(CNN)s, to adversarial attacks and presents a proactive training technique designed to counter them. We
introduce a novel volumization algorithm, which transforms 2D images into 3D volumetric representations.
When combined with 3D convolution and deep curriculum learning optimization (CLO), itsignificantly improves
the immunity of models against localized universal attacks by up to 40%. We evaluate our proposed approach
using contemporary CNN architectures and the modified Canadian Institute for Advanced Research (CIFAR-10
and CIFAR-100) and ImageNet Large Scale Visual Recognition Challenge (ILSVRC12) datasets, showcasing
accuracy improvements over previous techniques. The results indicate that the combination of the volumetric
input and curriculum learning holds significant promise for mitigating adversarial attacks without necessitating
adversary training.
Water scarcity is the lack of fresh water resources to meet the standard water demand. There are two type of water scarcity. One is physical. The other is economic water scarcity.
2. www.company.com
UNIT – III
RELATIONAL DATA MODEL & SQL
• Relational Database Design Using ER-to-Relational
Mapping, Mapping EER Model Constructs to Relations,
Relational Model Concepts, Relational Model Constraints
and Relational Database Schemas, Update Operations,
Transactions and Dealing with Constraint Violations, SQL
Data Definition and Data Types, Specifying Constraints in
SQL, Basic Retrieval Queries in SQL, INSERT, DELETE
and UPDATE Statements in SQL, Complex SQL Retrieval
Queries, Specifying Constraints as Assertions and Actions as
Triggers, Views (Virtual Tables) in SQL, Relational
Algebra.
Syllabus:
CS201-DBMS Dept of CSE
3. www.company.com
UNIT – III
RELATIONAL DATA MODEL & SQL
• To know how the data will be stored.
• To know how to specify the constraints that
need to be satisfied while storing the data.
• To know How to create Databases and
Tables.
• To know How to insert the data into the tables
and how to delete the data
• To know how to modify the existing Tables.
• To understand how to employ the Triggers.
Objectives:
CS201-DBMS Dept of CSE
4. www.company.com
UNIT – III
RELATIONAL DATA MODEL & SQL
• Students will be able to query the database for
finding out any information from database
systems.
• Students will able to create the databases, tables
• They can specify what type of constraints the data
needs to satisfy before it is going to store in
database
• They can also modify the structure of the tables
with the help of alter command.
• Students can apply the Triggers, which are useful
when to keep track of certain insertions,
updations, and deletions.
Expected
Outcomes:
CS201-DBMS Dept of CSE
5. www.company.com
Contents
1. INTRODUCTION TO RELATIONAL MODEL
2. Relational Model Concepts
3. Integrity Constraints over Relations
• Domain Constraints
• Key Constraints
• Entity Integrity
• Referential Integrity and Foreign Keys
4. ER-TO-RELATIONAL MAPPING
5. SQL Introduction
6. SQL Data Types
7. SQL Basics
Venata Rami Reddy Ch Dept of CSE
Topics:
CS201-DBMS Dept of CSE
6. www.company.com
Contents
8. Relational Algebra
• Unary Relational Operations:
• Relational Algebra Operations from Set Theory
• Binary Relational Operations: JOIN and DIVISION
9. Relational Calculus
• The Tuple Relational Calculus
• The Domain Relational Calculus
Topics:
CS201-DBMS Dept of CSE
7. www.company.com
RELATIONAL MODEL
:
The relational model is very simple and elegant
Relational database is a collection of one or more
relations, where each relation is a table with rows
and columns.
This simple tabular representation enables even
novice users to understand the contents of a
database, and it permits the use of simple, high-level
languages to query the data.
.
INTRODUCTION TO
RELATIONAL
MODEL
CS201-DBMS Dept of CSE
8. www.company.com
RELATIONAL MODEL
:
The major advantages of the relational model
over the older data models are its simple data
representation and the ease with which even
complex queries can be expressed
The relational model uses Data Definition
Language (DDL) and Data Manipulation
Language (DML), the standard languages for
creating, accessing, manipulation and querying
(i.e. retrieving) data in a relational DBMS.
INTRODUCTION
TO RELATIONAL
MODEL:
CS201-DBMS Dept of CSE
9. www.company.com
RELATIONAL MODEL
• The main construct for representing data in the
relational model is a relation.
• A relation consists of a relation schema and a
relation instance.
• The relation instance is a table, and the relation
schema describes the column heads for the
table.
• The schema specifies the relation's name, the
name of each field (or column, or attribute), and
the domain of each field.
INTRODUCTION
TO RELATIONAL
MODEL:
CS201-DBMS Dept of CSE
11. www.company.com
Domain:
Relational Model
Concepts :
• A domain D is the original sets of atomic
values used to model data.
• By a atomic, we mean that each value in the
domain is indivisible as far as the relational
model is concerned.
• A domain is a pool of the values from where
one or more attributes ( or columns) can draw
their actual values.
• For Examples: The domain of name is the set
of character strings that represents names of
person.
CS201-DBMS Dept of CSE
12. www.company.com
Tuple:
Relational Model
Concepts :
• According to the model, every relation or
table is made up of many tuples.
• They are also called the records.
• They are the rows that a table is made up
of.
CS201-DBMS Dept of CSE
13. www.company.com
Relation
Relational Model
Concepts :
• A relation is a subset of the Cartesian
product of a list of domains characterized by
a name.
• Given ‘n’ domains denoted by D1, D2, ...,
Dn, R is a relation defined on the these
domains if R ≤ D1 * D2 * ... *Dn.
• Relation can be viewed as a “table”.
• In that table, each row represents a tuple of
data values and each column represents an
attribute.
CS201-DBMS Dept of CSE
14. www.company.com
Attribute
Relational Model
Concepts :
• A column of a relation designated by
name.
• The name associated should be
meaningful.
• Each attributes associates with a domain.
• A relation schema denoted by R is a list of
attributes (A1, A2,...., An).
CS201-DBMS Dept of CSE
15. www.company.com
The Degree of the Relation
Relational Model
Concepts :
• The degree of the relation is the number of
attributes of its relation schema.
• The degree of the relation of the below
Table is 5.
CS201-DBMS Dept of CSE
16. www.company.com
The Cardinality of the Relation
Relational Model
Concepts :
• The cardinality of the relation is the number
of tuples in the relation.
• The cardinality of the relation of the below
Table is 6.
CS201-DBMS Dept of CSE
17. www.company.com
Characteristic of Relations
Relational Model
Concepts :
A tuple is a set of values.
A relation is a set of tuples.
Since a relation is a set, there is no ordering on
rows.
The order of attributes and their values within a
relation is not important as long as the
correspondence between attributes and values
is maintained.
Each value in a tuple is atomic.
That means each value cannot be divided into
smaller components.
Hence, the composite and multi-valued
attributes are not allowed in a relation.
CS201-DBMS Dept of CSE
18. www.company.com
Integrity Constraints over Relations
Integrity
Constraints over
Relations:
• An integrity constraint (IC) is a condition specified
on a database schema and restricts the data that
can be stored in an instance of the database.
• If a database instance satisfies all the integrity
constraints specifies on the database schema, it
is a legal instance.
• A DBMS permits only legal instances to be
stored in the database.
CS201-DBMS Dept of CSE
19. www.company.com
Integrity Constraints over Relations
Integrity
Constraints over
Relations:
1. Domain Constraints
2. Key Constraints
3. Entity Integrity
4. Referential Integrity and Foreign Keys
CS201-DBMS Dept of CSE
20. www.company.com
Constraints:
Integrity
Constraints over
Relations:
• Many kinds of integrity constraints can be
specified in the relational model
• A relation schema specifies the domain of each
field in the relation instance.
• These domain constraints in the schema
specify the condition that each instance of the
relation has to satisfy
• The values that appear in a column must be
drawn from the domain associated with that
column.
• Thus, the domain of a field is essentially the
type of that field.
CS201-DBMS Dept of CSE
21. www.company.com
Key Constraints:
Integrity
Constraints over
Relations:
• A Key Constraint is a statement that a certain
minimal subset of the fields of a relation is a unique
identifier for a tuple.
Super Key:
An attribute or set of attributes that uniquely
identifies a tuple within a relation.
However, a super key may contain additional
attributes that are not necessary for a unique
identification.
Ex: The customer_id of the relation customer is
sufficient to distinguish one tuple from other. Thus,
customer_id is a super key.
Similarly, the combination of customer_id and
customer_name is a super key for the relation
customer.
CS201-DBMS Dept of CSE
22. www.company.com
Cont …
Integrity
Constraints over
Relations:
Primary key:
It is an unique value attribute in a table to enforce
entity integrity and it identifies rows in the table
uniquely.
Features of the primary key:
i. Primary key will not allow duplicate values.
ii. Primary key will not allow null values.
iii. Only one primary key is allowed per table.
Ex: For the student relation, we can choose
student_id as the primary key.
Candidate key:
Sometimes 2 or more independent attribute or
attributes can be used to identify the rows uniquely
Eg :( vech no, veng no, purchase date)
CS201-DBMS Dept of CSE
23. www.company.com
Referential Integrity and Foreign Keys
Venkata Rami Reddy Ch Dept of CSE
Integrity
Constraints over
Relations:
Foreign Key:
Foreign keys represent the relationships between
tables.
A foreign key is a column (or a group of columns)
whose values are derived from the primary key of
some other table.
The table in which foreign key is defined is called a
Foreign table or Details table.
The table that defines the primary key and is
referenced by the foreign key is called the Primary
table or Master table.
CS201-DBMS Dept of CSE
24. www.company.com
Referential Integrity and Foreign Keys
Venkata Rami Reddy Ch Dept of CSE
Integrity
Constraints over
Relations:
Features of foreign key:
• Records cannot be inserted into a detail table, if
corresponding records in the master table do
not exist.
• Records of the master table cannot be deleted
or updated if corresponding records in the detail
table actually exist.
CS201-DBMS Dept of CSE
25. www.company.com
ER to Relation Mapping
Venkata Rami Reddy Ch Dept of CSE
ER to Relation
Mapping:
Step 1: Mapping of Regular Entity Types
Step 2: Mapping of Weak Entity Types
STEP 3: MAP BINARY 1:1 RELATIONSHIP
TYPES
Step 4: Mapping of Binary 1 :N or N:1
Relationship Types
Step 5: Mapping of Binary M: N Relationship
Types:
STEP 6: MAP MULTIVALUED
ATTRIBUTES
Step 7: Mapping n-ary relationship types
CS201-DBMS Dept of CSE
27. www.company.com
Step 1: Mapping of Regular Entity Types
ER to Relation
Mapping:
For each regular (strong) entity type E in the ER
schema, create a relation R that includes all the
simple attributes of E.
Include only the simple component attributes of
a composite attribute.
Choose one of the key attributes of E as primary
key for R.
In our example, we create the relations
EMPLOYEE, DEPARTMENT, and PROJECT in
Figure to correspond to the regular entity types
EMPLOYEE, DEPARTMENT, and PROJ ECT from
Figure
CS201-DBMS Dept of CSE
29. www.company.com
Step 2: Mapping of Weak Entity Types
ER to Relation
Mapping:
For each weak entity type W in the ER schema
with owner entity type E, create a relation R and
include all simple attributes of W as attributes of R.
In addition, include foreign key attributes in R
the primary key Attribute(s) of the owner entity.
In our example, we create the relation
DEPENDENT in this step to correspond to the
weak entity type DEPENDENT.
We include the primary key empno of the
EMPLOYEE relation-which corresponds to the
owner entity type-as a foreign key attribute of
DEPENDENT
CS201-DBMS Dept of CSE
30. www.company.com
STEP 3: MAP BINARY 1:1 RELATIONSHIP
TYPES
ER to Relation
Mapping:
For each binary 1:1 relationship type R, identify relation
schemas that correspond to entity types participating in R
Apply one of three possible approaches:
Foreign key approach
Add primary key of one participating relation as foreign
key attribute of the other, which will also represent R
If only one side is total, choose it to represent R
Declare foreign key attribute as unique
CS201-DBMS Dept of CSE
31. www.company.com
STEP 3: MAP BINARY 1:1 RELATIONSHIP
TYPES
ER to Relation
Mapping:
Merged relationship approach :
An alternative mapping of a 1:1 relationship type is
possible by merging the two entity types and the
relationship into a single relation.
This may be appropriate when both participations are
total.
Relationship relation approach :
Create new relation schema for R with two foreign key
attributes being copies of both primary keys
Declare one of the attributes as primary key and the
other one as unique
Add single-valued attributes of relationship type as
attributes of R
CS201-DBMS Dept of CSE
32. www.company.com
Step 4: Mapping of Binary 1 :N Relationship
Types:
ER to Relation
Mapping:
For each regular binary l:N relationship type R,
identify the relation S that represents the
participating entity type at the N-side of the
relationship type.
Include foreign key in S the primary key of the
relation T that represents the other entity type
participating in R
Include any simple attributes of the I:N
relationship type as attributes of S.
CS201-DBMS Dept of CSE
33. www.company.com
STEP 6: MAP MULTIVALUED
ATTRIBUTES
ER to Relation
Mapping:
For each multivalued attribute Create new relation R
with attribute to hold multivalued attribute values
If multivalued attribute is composite, include its simple
components
Add attribute(s) for primary key of relation schema for
entity or relationship type to be foreign key for R
CS201-DBMS Dept of CSE
34. www.company.com
SQL
Venkata Rami Reddy Ch Dept of CSE
SQL Introduction
SQL stands for “Structured Query Language”
and can be pronounced as “SQL” or “sequel –
(Structured English Query Language)”.
It is a query language used for accessing and
modifying information in the database.
IBM first developed SQL in 1970s.
Also it is an ANSI/ISO standard.
It has become a Standard Universal Language
used by most of the relational database
management systems (RDBMS).
CS201-DBMS Dept of CSE
35. www.company.com
SQL
Venkata Rami Reddy Ch Dept of CSE
SQL Introduction
Some of the RDBMS systems are: Oracle, Microsoft SQL
server, Sybase etc.
Most of these have provided their own implementation
thus enhancing it's feature and making it a powerful tool.
Few of the sql commands used in sql programming are
SELECT Statement, UPDATE Statement, INSERT INTO
Statement, DELETE Statement, WHERE Clause, ORDER
BY Clause, GROUP BY Clause, ORDER Clause, Joins,
Views, GROUP Functions, Indexes etc.
CS201-DBMS Dept of CSE
36. www.company.com
SQL
Venkata Rami Reddy Ch Dept of CSE
SQL Introduction
• In a simple manner, SQL is a non-procedural,
English-like language that processes data in
groups of records rather than one record at a
time. Few functions of SQL are:
1. store data
2. modify data
3. retrieve data
4. modify data
5. delete data
6. create tables and other database objects
7. delete data
CS201-DBMS Dept of CSE
37. www.company.com
SQL Commands:
Venkata Rami Reddy Ch Dept of CSE
SQL Introduction
• SQL commands are instructions used to
communicate with the database to perform
specific task that work with data.
• SQL commands can be used not only for
searching the database but also to perform
various other functions like, for example, you
can create tables, add data to tables, or modify
data, drop the table, set permissions for users. :
CS201-DBMS Dept of CSE
38. www.company.com
Cont …
Venkata Rami Reddy Ch Dept of CSE
SQL Introduction
SQL commands are grouped into four major categories
depending on their functionality
Data Definition Language (DDL) :
These SQL commands are used for creating, modifying,
and dropping the structure of database objects.
The commands are CREATE, ALTER, DROP, RENAME,
and TRUNCATE.
Data Manipulation Language (DML)
These SQL commands are used for storing, retrieving,
modifying, and deleting data.
These commands are SELECT, INSERT,
UPDATE, and DELETE.
CS201-DBMS Dept of CSE
39. www.company.com
Cont …
Venkata Rami Reddy Ch Dept of CSE
SQL Introduction
Transaction Control Language (TCL)
These SQL commands are used for managing
changes affecting the data.
These commands are COMMIT, ROLLBACK,
and SAVEPOINT.
Data Control Language (DCL)
These SQL commands are used for providing
security to database objects.
These commands are GRANT and REVOKE.
CS201-DBMS Dept of CSE
40. www.company.com
SQL Process:
Venkata Rami Reddy Ch Dept of CSE
SQL Introduction
When you are executing an SQL command for
any RDBMS, the system determines the best way
to carry out your request and SQL engine figures
out how to interpret the task.
There are various components included in the
process.
These components are Query Dispatcher,
Optimization Engines, Classic Query Engine and
SQL Query Engine, etc.
Classic query engine handles all non-SQL
queries but SQL query engine won't handle logical
files.
CS201-DBMS Dept of CSE
42. www.company.com
Data Definition Language Statements (DDL)
Venkata Rami Reddy Ch Dept of CSE
Data Definition Language Statements (DDL) statements
are used to define the database structure or schema.
They are different types of DDL commands. They are
1. Create
2. Drop
3. Alter
4. Grant
5. Revoke
6. Comment
7. Rename
SQL Languages:
CS201-DBMS Dept of CSE
43. www.company.com
Create:
Venkata Rami Reddy Ch Dept of CSE
Create command is used to create Databases,
Tables, and Views etc.
Syntax for Creating Databases:
CREATE DATABASE DatabaseName;
Example:
If you want to create new database <testDB>, then
CREATE DATABASE statement would be as follows:
SQL> CREATE DATABASE university;
Data Definition
Language
Statements:
CS201-DBMS Dept of CSE
44. www.company.com
Cont …
Venkata Rami Reddy Ch Dept of CSE
Syntax for Creating Table
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
PRIMARY KEY( one or more columns )
);
Data Definition
Language
Statements:
CS201-DBMS Dept of CSE
45. www.company.com
Drop:
Venkata Rami Reddy Ch Dept of CSE
Drop command is used to drop the database or table.
Syntax for Dropping the Database:
DROP DATABASE DatabaseName;
Example:
If you wadatnt to delete an existing database testDB then
DROP DATABASE statement would be as follows:
SQL> DROP DATABASE testDB;
Data Definition
Language
Statements:
CS201-DBMS Dept of CSE
46. www.company.com
Cont …
Venkata Rami Reddy Ch Dept of CSE
Syntax for Dropping Table:
DROP TABLE table_name;
Drop table student;
Data Definition
Language
Statements:
CS201-DBMS Dept of CSE
47. www.company.com
Relational Algebra
Venkata Rami Reddy Ch Dept of CSE
The basic set of operations for the relational
model is the relational algebra.
These operations enable a user to specify basic
retrieval requests.
The result of a retrieval is a new relation, which
may have
Been formed from one or more relations.
The algebra operations thus produce new
relations,which can be further manipulated using
operations of the same algebra.
Relational
Algebra:
CS201-DBMS Dept of CSE
48. www.company.com
Relational Algebra
Venkata Rami Reddy Ch Dept of CSE
A sequence of relational algebra operations forms
a relational algebra expression, whose result will also
be a relation that represents the result of a database
query (or retrieval request).
The relational algebra is very important for several
reasons.
First, it provides a formal foundation for relational
model operations.
Second, and perhaps more important, it is used as
a basis for implementing and optimizing queries in
relational database management systems (RDBMSs)
Relational
Algebra:
CS201-DBMS Dept of CSE
49. www.company.com
SELECT
Venkata Rami Reddy Ch Dept of CSE
The SELECT operation is used to select a subset
of the tuples from a relation that satisfy a selection
condition.
One can consider the SELECT operation to be a
filter that keeps only those tuples that satisfy a
qualifying condition.
The SELECT operation can also be visualized
As a horizontal partition of the relation into two sets
of tuples-those tuples that satisfy the condition and
are selected, and those tuples that do not satisfy the
condition and are discarded.
UNARY
RELATIONAL
OPERATIONS:
CS201-DBMS Dept of CSE
50. www.company.com
SELECT
Venkata Rami Reddy Ch Dept of CSE
In general, the SELECT operation is denoted by
σ <selection condition>(R)
where the symbol σ (sigma) is used to denote the
SELECT operator, and the selection condition
is a Boolean expression specified on the attributes
of relation R.
Notice that R is generally a relational algebra
expression whose result is a relation
the simplest such expression is just the name of a
database relation.
The relation resulting from the SELECT operation
has the same attributes as R.
UNARY
RELATIONAL
OPERATIONS:
CS201-DBMS Dept of CSE
51. www.company.com
SELECT
Venkata Rami Reddy Ch Dept of CSE
select the EMPLOYEE tuples whose department
is 4, or those whose salary is greater than
$25,000,
σ(DNO=4 AND SALARY>25000))
UNARY
RELATIONAL
OPERATIONS:
CS201-DBMS Dept of CSE
52. www.company.com
The PROJECT Operation
Venkata Rami Reddy Ch Dept of CSE
The PROJECT operation, on the other hand,
selects certain columns from the table and discards
the other columns.
If we are interested in only certain attributes of a
relation, we use the PROJECT operation to project
the relation over these attributes only.
The result of the PROJECT operation can hence
be visualized as a vertical partition of the relation into
two relations: one has the needed columns
(attributes) and contains the result of the operation,
and the other contains the discarded columns.
UNARY
RELATIONAL
OPERATIONS:
CS201-DBMS Dept of CSE
53. www.company.com
The PROJECT Operation
Venkata Rami Reddy Ch Dept of CSE
The general form of the PROJECT operation is
∏ <attribute list> (R)
where ∏ (pi) is the symbol used to represent the
PROJECT operation, and <attribute list> is the desired list
of attributes from the attributes of relation R.
Again, notice that R is just the name of a database
relation. The result of the PROJECT operation has only
the
attributes specified in <attribute list> in the same order
as they appear in the list.
Hence, its degree is equal to the number of attributes in
<attribute list>.
UNARY
RELATIONAL
OPERATIONS:
CS201-DBMS Dept of CSE
54. www.company.com
The PROJECT Operation
Venkata Rami Reddy Ch Dept of CSE
To list each employee's first and last name and sal-ary, we
can use the PROJECT operation as follows:
∏<LNAME, FNAME, SALARY>( EMPLOYEE)
UNARY
RELATIONAL
OPERATIONS:
CS201-DBMS Dept of CSE
55. www.company.com
The PROJECT & select Operation
Venkata Rami Reddy Ch Dept of CSE
UNARY
RELATIONAL
OPERATIONS:
CS201-DBMS Dept of CSE
56. www.company.com
UNION Operation
Venkata Rami Reddy Ch Dept of CSE
Relational Algebra Operations From
Set Theory
Relational Algebra
Operations From
Set Theory :
The result of this operation, denoted by RỤS, is a
relation that includes all tuples that are either in R or in S
or in both R and S. Duplicate tuples are eliminated.
Example: To retrieve the social security numbers of all
employees who either work in department 5 or directly
supervise an employee who works in department 5, we
can use the union operation as follows:
DEP5_EMPS σ DNO=5 (EMPLOYEE)
RESULT1 ∏ SSN(DEP5_EMPS)
RESULT2(SSN) ∏ SUPERSSN(DEP5_EMPS)
RESULT RESULT1 ỤRESULT2
CS201-DBMS Dept of CSE
57. www.company.com
UNION Operation
Venkata Rami Reddy Ch Dept of CSE
Relational Algebra Operations From
Set Theory
Relational Algebra
Operations From
Set Theory :
The union operation produces the tuples that
are in either RESULT1 or RESULT2 or both.
The two operands must be “type compatible”.
Type Compatibility:
The operand relations R1(A1, A2, ..., An) and R2(B1,
B2, ..., Bn) must have the same number of
attributes, and the domains of corresponding
attributes must be compatible; that is,
dom(Ai)=dom(Bi) for i=1, 2, ..., n.
CS201-DBMS Dept of CSE
58. www.company.com
UNION Operation Example
Venkata Rami Reddy Ch Dept of CSE
Relational Algebra Operations From
Set Theory
Relational Algebra
Operations From
Set Theory :
CS201-DBMS Dept of CSE
59. www.company.com
INTERSECTION OPERATION
Venkata Rami Reddy Ch Dept of CSE
Relational Algebra Operations From
Set Theory
Relational Algebra
Operations From
Set Theory :
The result of this operation, denoted by R n S,
is a relation that includes all tuples that are in
both R and S. The two operands must be
"type compatible"
Example: The result of the intersection
operation (figure below) includes only those
who are both students and instructors.
STUDENT n NSTRUCTOR
CS201-DBMS Dept of CSE
60. www.company.com
Set Difference (or MINUS) Operation
Venkata Rami Reddy Ch Dept of CSE
Relational Algebra Operations From
Set Theory
Relational Algebra
Operations From
Set Theory :
The result of this operation, denoted by R - S, is a
relation that includes all tuples that are in R but not in S.
The two operands must be "type compatible”.
Example: The figure shows the names of students who
are not instructors, and the names of instructors who are
not students. STUDENT-INSTRUCTOR
INSTRUCTOR-STUDENT
CS201-DBMS Dept of CSE
61. www.company.com
CARTESIAN (or cross product) Operation
Venkata Rami Reddy Ch Dept of CSE
Relational Algebra Operations From
Set Theory
Relational Algebra
Operations From
Set Theory :
This operation is used to combine tuples from two
relations in a combinatorial fashion.
In general, the result of R(A1, A2, . . ., An) x S(B1,
B2, . . ., Bm) is a relation Q with degree n + m
attributes Q(A1, A2, . . ., An, B1, B2, . . ., Bm), in that
order.
The resulting relation Q has one tuple for each
combination of tuples—one from R and one from S.
Hence, if R has nR tuples (denoted as |R| = nR ),
and S has nS tuples,
Then | R x S | will have nR * nS tuples.
The two operands do NOT have to be type
compatible”
CS201-DBMS Dept of CSE
62. www.company.com
CARTESIAN (or cross product) Operation
Venkata Rami Reddy Ch Dept of CSE
Relational Algebra Operations From
Set Theory
Relational Algebra
Operations From
Set Theory :
Example:
FEMALE_EMPS ∏ SEX=’F’(EMPLOYEE)
EMPNAMES ∏ FNAME, LNAME, SSN (FEMALE_EMPS)
EMP_DEPENDENTS EMPNAMES x DEPENDENT
CS201-DBMS Dept of CSE
63. www.company.com
CARTESIAN (or cross product) Operation
Venkata Rami Reddy Ch Dept of CSE
Set Theory
Relational Algebra
Operations From
Set Theory :
CS201-DBMS Dept of CSE
64. www.company.com
JOIN Operation
Venkata Rami Reddy Ch Dept of CSE
Set Theory
Binary Relational
Operations:
The JOIN operation, denoted by , is used to combine
related tuples from two relations into single tuples based
on common colum
The general form of a join operation on two relations
R(A1, A2, . . ., An) and S(B1, B2, . . ., Bm) is:
R <join condition>S
CS201-DBMS Dept of CSE
65. www.company.com
JOIN Operation
Venkata Rami Reddy Ch Dept of CSE
Set Theory
Binary Relational
Operations:
Example:
Suppose that we want to retrieve the name of the manager of
each department. To get the manager’s name, we need to
combine each DEPARTMENT tuple with the EMPLOYEE
tuple whose SSN value matches the MGRSSN value in the
department tuple.
We do this by using the join operation.
DEPT_MGR DEPARTMENT MGRSSN=SSN
EMPLOYEE
CS201-DBMS Dept of CSE
66. www.company.com
EQUIJOIN Operation
Venkata Rami Reddy Ch Dept of CSE
Set Theory
Binary Relational
Operations:
The most common use of join involves join
conditions with equality comparisons only.
Such a join, where the only comparison operator
used is =, is called an EQUIJOIN.
In the result of an EQUIJOIN we always have
one or more pairs of attributes (whose names need
not be identical) that have identical values in
every tuple.
The JOIN seen in the previous example
was EQUIJOIN.
CS201-DBMS Dept of CSE
67. www.company.com
NATURAL JOIN Operation
Venkata Rami Reddy Ch Dept of CSE
Set Theory
Binary Relational
Operations:
Because one of each pair of attributes with
identical values is superfluous, a new operation
called natural join—denoted by *—was created to
get rid of the second (superfluous) attribute in an
EQUIJOIN condition.
The standard definition of natural join
requires that the two join attributes, or each pair of
corresponding join attributes, have the same name
in both relations.
If this is not the case, a renaming operation
is applied first.
CS201-DBMS Dept of CSE
68. www.company.com
NATURAL JOIN Operation
Venkata Rami Reddy Ch Dept of CSE
Set Theory
Binary Relational
Operations:
Example: To apply a natural join on the DNUMBER
attributes of DEPARTMENT and DEPT_LOCATIONS,
it is sufficient to write:
DEPT_LOCS DEPARTMENT * DEPT_LOCATIONS
CS201-DBMS Dept of CSE
69. www.company.com
Relational Calculus
Venkata Rami Reddy Ch Dept of CSE
Set Theory
Relational
Calculus:
A relational calculus expression creates a new relation,
which is specified in terms of variables that range over
rows of the stored database relations (in tuple calculus) or
over columns of the stored relations (in domain calculus).
In a calculus expression, there is no order of operations
to specify how to retrieve the query result
A calculus expression specifies only what information the
result should contain.
This is the main distinguishing feature between relational
algebra and relational calculus.
Relational calculus is considered to be a nonprocedural
language.
This differs from relational algebra, where we must write
a sequence of operations to specify a retrieval request;
CS201-DBMS Dept of CSE
70. www.company.com
Tuple Relational Calculus
Venkata Rami Reddy Ch Dept of CSE
Set Theory
Relational
Calculus:
The tuple relational calculus is based on specifying a
number of tuple variables.
Each tuple variable usually ranges over a particular
database relation, meaning that the variable may take
as its value any individual tuple from that relation.
A simple tuple relational calculus query is of the form
{t | COND(t)}
where t is a tuple variable and COND (t) is a
conditional expression involving t.
The result of such a query is the set of all tuples t that
satisfy COND (t).
CS201-DBMS Dept of CSE
71. www.company.com
Tuple Relational Calculus
Venkata Rami Reddy Ch Dept of CSE
Set Theory
Relational
Calculus:
Example:
To find the first and last names of all employees
whose salary is above $50,000, we can write the
following tuple calculus expression:
{t.FNAME, t.LNAME | EMPLOYEE(t) AND
t.SALARY>50000}
The condition EMPLOYEE(t) specifies
that the range relation of tuple variable t is
EMPLOYEE. The first and last name of each
EMPLOYEE tuple t that satisfies the condition
t.SALARY>50000 will be retrieved.
CS201-DBMS Dept of CSE
72. www.company.com
The Domain Relational Calculus
Venkata Rami Reddy Ch Dept of CSE
Set Theory
Relational
Calculus:
Domain calculus differs from tuple calculus in the type of
variables used in formulas: rather than having variables
range over tuples, the variables range over single values from
domains of attributes.
To form a relation of degree n for a query result, we must
have n of these domain variables—one for each attribute.
An expression of the domain calculus is of the form
{x1, x2, . . ., xn | COND(x1, x2, . . ., xn, xn+1, xn+2,
. . ., xn+m)}
where x1, x2, . . ., xn, xn+1, xn+2, . . ., xn+m are
domain variables that range over domains (of attributes) and
COND is a condition or formula of the domain relational
calculus.
CS201-DBMS Dept of CSE
73. www.company.com
The Domain Relational Calculus
Venkata Rami Reddy Ch Dept of CSE
Set Theory
Relational
Calculus:
Retrieve the birthdate and address of the employee whose
name is ‘John B. Smith’.
Query :
{uv | (Ǝ q) (Ǝ r) (Ǝ s) (Ǝ t) (Ǝ w) (Ǝ x) (Ǝ y) (Ǝ z)
(EMPLOYEE(qrstuvwxyz) and q=’John’ and r=’B’
and s=’Smith’)}
CS201-DBMS Dept of CSE
74. www.company.com
Gate Questions
Venkata Rami Reddy Ch Dept of CSE
Set Theory
SQL
1) Consider the above tables A, B and C. How many
tuples does the result of the following SQL query
contains? (GATE-2012)
SELECT A.id
FROM A
WHERE A.age > ALL (SELECT B.age
FROM B
WHERE B. name = "arun")
(A) 4
(B) 3
(C) 0
(D) 1
CS201-DBMS Dept of CSE
75. www.company.com
Gate Questions
Venkata Rami Reddy Ch Dept of CSE
Set TheoryAnswer (B)
Explanation:
The meaning of “ALL” is the A.Age should be greater than
all the values returned by the subquery. There is no entry
with name “arun” in table B. So the subquery will return
NULL. If a subquery returns NULL, then the condition
becomes true for all rows of A (See this for details). So all
rows of table A are selected.
CS201-DBMS Dept of CSE
76. www.company.com
Gate Questions
Venkata Rami Reddy Ch Dept of CSE
Set Theory
Relational
Calculus &
SQL
2) Let R and S be relational schemes such that
R={a,b,c} and S={c}. Now consider
the following queries on the database(GATE-2009)
IV) SELECT R.a, R.b
FROM R,S
WHERE R.c=S.c
Which of the above queries are equivalent?
(A) I and II
(B) I and III
(C) II and IV
(D) III and IV
Answer (A)
CS201-DBMS Dept of CSE
77. www.company.com
Gate Questions
Venkata Rami Reddy Ch Dept of CSE
Set Theory
Relational
Algebra
7) Let R and S be two relations with the following schema
R (P,Q,R1,R2,R3)
S (P,Q,S1,S2)
Where {P, Q} is the key for both schemas.
Which of the following queries are equivalent?
(GATE-2008)
CS201-DBMS Dept of CSE
78. www.company.com
Gate Questions
Venkata Rami Reddy Ch Dept of CSE
Set Theory
Relational
Algebra
(A) Only I and II
(B) Only I and III
(C) Only I, II and III
(D) Only I, III and IV
Explanation:
In I, Ps from natural join of R and S are selected.
In III, all Ps from intersection of (P, Q) pairs present in
R and S.
IV is also equivalent to III because (R – (R – S)) =
R S.
II is not equivalent as it may also include Ps where Qs
are not same in R and S.
CS201-DBMS Dept of CSE
79. www.company.com
Gate Questions
Venkata Rami Reddy Ch Dept of CSE
Set Theory
Relational
Algebra
Answer (B)
Explanation:
The expression given in question does following steps in
sequence.
a) Select studids of all female students and selects
all courseids of all courses.
b) Then the query does a Cartesian Product of the above
select two columns from different tables.
c) Finally it subtracts enroll table from the result of above
step (b). This will remove all the (studid, courseid) pairs
which are present in enroll table. If all female students
have registered in a courses, then this course will not be
there in the subtracted result.
So the complete expression returns courses in which a
proper subset of female students are enrolled.
CS201-DBMS Dept of CSE