SQL UNIT-II Name
SQL UNIT-II Name
Basics of SQL, DDL, DML,DCL,TCL – creation, alteration, defining constraints – Functions – aggregate
functions, Built-in functions – Views – Joins – Procedure
1. SQL FUNDAMENTALS
IBM developed the original version of SQL, originally called Sequel, as part of the System R project in
the early 1970s. The Sequel language has evolved since then, and its name has changed toSQL (Structured
Query Language)
The Data Definition Language is used to define the overall schema of the database. The DDL is also used
to specify additional properties of the data. DDL deals with database schemas and descriptions, of how the
data should reside in the database.
CREATE:
It is used to create a table or relation.
Syntax :
CREATE TABLE tablename (A1 D1, A2 D2, . . . ,An Dn, <integrity-constraint1>, . . .
,<integrity-constraintk)>);where
tablename - the name of the table
Ai - the attribute name
Di - the domain(data type ) of the attribute integrity-constrainti – data integrity constraint name
Integrity Constraints:
Integrity Constraints enforce rules on the data in a table whenever a row is inserted, updated, or deleted
from that table. The constraint must be satisfied for the operation to succeed. It prevent the deletion of a
table if there are dependencies from other tables
Primary Key Constraint: The Primary Key constraint uniquely identifies each record in a table. Primary
keys must contain unique values, and cannot contain NULL values. A table can have only one primary key,
which may consist of single or multiple fields.
Foreign Key Constraint: A foreign key is a key used to link two tables together. A foreign key is afield
(or collection of fields) in one table that refers to the primary key in another table. The table containing the
foreign key is called the child table, and the table containing the candidate key is called the referenced or
parent table.
Unique Constraint: The unique constraint ensures that all values in a column are different. Boththe
unique and primary key constraints provide a guarantee for uniqueness for a column or set of columns. A
DR.N.SARANYA, AP(SL.G)/CSE, KPRIET 2
SQL – BASICS AND ADVANCED – PL/SQL
NOT NULL Constraint: The NOT NULL constraint enforces a column to not accept NULL values. This
enforces a field to always contain a value, which means that you cannot insert a new record, or update a
record without adding a value to this field
Check Constraint: The check constraint is used to limit the value range that can be placed in a column.
Default Constraint: The default constraint is used to provide a default value for a column.
Example
CREATE TABLE Employee ( Eid
int,
Name varchar(255) NOT NULL,
Designation varchar(255), Salary int ,
check(Salary>0),
Phno varchar(255) , PRIMARY KEY(Eid)
);
Result:
Table created.
To view the structure of the table, DESCRIBE table_name
DESCRIBE Employee
ALTER :
The alter table statement is used to add, delete, or modify columns in an existing table.
Add Clause:
The new column becomes the last column. If a table already contains rows when a column is added, then
the new column is initially null for all the rows.
Modify Clause:
Column modification can include changes to a column’s data type, size, and default value. the data type is
changed only if the column contains null values. A change to the default value of a column affects only
subsequent insertions to the table.
Drop Clause:
only one column can be dropped at a time. The table must have at least one column remaining in it after it
is altered. Once a column is dropped, it cannot be recovered.
Syntax:
ALTER TABLE table_name ADD|MODIFY column_name datatype;
ALTER TABLE table_name DROP column_name;
Where,
table_name - the name of the table
column_name – name of the attribute
datatype – domain of the attribute Example
1:
Example 2:
ALTER TABLE employee DROP Address;
DR.N.SARANYA, AP(SL.G)/CSE, KPRIET 4
SQL – BASICS AND ADVANCED – PL/SQL
Result:
Table Altered.
DESCRIBE Employee
DROP :
The DROP TABLE statement is used to drop an existing table in a database. The drop command
deletes the entire table along with its content. The DROP TABLE statement cannot beroll backed.
Syntax:
DROP TABLE table_name;
Example:
RENAME :
It is used to rename a table.
Syntax
old_name - the old name of the table, view, sequence, or synonym. new_name
TRUNCATE :
Truncate is used to remove all rows from a table and to release the storage space used by that
table.It does not delete the table. The removed rows can not be roll backed.
Syntax:
Example:
TRUNCATE TABLE Employee.
A data manipulation language (DML) is a language that enables users to access or manipulate data
as organized by the appropriate data model.
DML commands are not auto-committed. It means that the changes are not permanent to database,
they can be rolled back. Data manipulation is retrieval of information, insertion of new information,
deletion of information or modification of information stored in the database.
DML statements are :
The basic structure of an SQL query consists of three clauses: select, from, and where. The query
takes as its input the relations listed in the from clause, operates on them as specified in the where
and select clauses, and then produces a relation as the result. The select clause is used to list the
attributes desired in the result of a query. The from clause is a list of the relations to be accessed in
the evaluation of the query. The where clause is a predicate involving attributes of the relation in the
from clause.
SELECT:
Syntax:
Where,
* - selects all columns
DISTINCT - suppresses duplicates
column|expression - selects the named column or the expression
alias - gives selected columns different headings
Where Clause : restricts the query to rows that meet a
condition Group by -
Example :
Consider the relation Employee
Where Clause
It Restrict the rows returned by select statement.
Comparison Conditions:
= - Equal to
> - Greater than
>= - Greater than or equal to
< - Less than
<= - Less than or equal to
<> - Not equal to
BETWEEN - Between two values (inclusive)
IN(set) - Match any of a list of values (%)
LIKE - Match a character pattern
IS NULL - Is a null value
Logical Conditions:
AND - if all the conditions separated by AND is TRUE
OR - if any of the conditions separated by OR is TRUE
Comparison conditions
IS [NOT] NULL, LIKE, [NOT] IN
NOT] BETWEEN
NOT logical condition
AND logical condition
OR logical condition
Query: Select Name, Salary from employee where Salary between 27500 and 40000
Result:
Name Salary
Raju 27500
Sachin 33000
Dhoni 39650
Query: Select Name, Designation, Salary from Employee where Salary>25000 and
Designation=’Developer’;
Result:
Query: Select Eid, Name, Designation from Employee where Name like ‘D%’
Aggregate Functions
Aggregate functions are functions that take a collection of values as input and return a single
value. SQL offers five built-in aggregate functions:
Example:
Query :Select min(Salary) from Employee;
Result:
Min(Salary)
25000
Avg(Salary)
33575
Group By Clause:
the GROUP BY clause to divide the rows in a table into groups. The attribute or attributes given
in the group by clause are used to form groups. By default, rows are sorted by ascending order of the
columns included in the GROUP BY list.
Designation Avg(Salary)
Accountant 33575.0
Developer 36250
HR 33000
Having Clause:
The HAVING clause is used to restrict groups. The groups that match the criteria in the HAVING
clause are displayed.
Query:
Select Designation, avg(Salary) as avg from Employee group by Designation having
avg(Salary)>34000;
Result:
Designation Avg
Developer 36250
INSERT:
It is used to insert a new row that contains values for each column. Only one row is inserted ata
time.
Syntax:
INSERT INTO table (column1, coulmn2, column3,) VALUES (value1, value2, value3, ...);.
If the order of the values is in the same order as the columns in the table
INSERT INTO table_name VALUES (value1, value2, value3, ...);
Example
Query:
Insert into Employee(Eid, Designation, Name, Salary, Phno)values(587,’Designer’,’Walter’,32570,
‘8978567780’)
Result:
1 row created.
UPDATE :
The UPDATE command is used to modify attribute values of one or more selected tuples.
Syntax:
UPDATE table_name SET column1 = value1, column2 = value2, ...WHERE condition;
Example:
Query:
Update Employee set salary=43575 where Eid=587;
Result:
1 row updated.
DELETE:
The DELETE statement is used to delete existing records in a table. The delete operation is not made
permanent until the data transaction is committed. Ift the WHERE clause is omitted, all rows in the
table are deleted.
Syntax:
DR.N.SARANYA, AP(SL.G)/CSE, KPRIET 13
SQL – BASICS AND ADVANCED – PL/SQL
Example:
Query:
Delete from Employee where EID=587
Result:
1 row deleted.
Query:
Delete from Employee;
Result:
5 row deleted.
Query:
Delete from Employee where EID=587
Result: Remove Employee 587 in the Employee table.
1 row deleted.
Query:
Commit;
Result: makes the change permanent
Commit complete.
ROLLBACK:
Data changes are undone. The previous state of the data is restored.
Example:
Query:
DELETE FROM Employee;
Result :all rows in the employee table is deleted
5 rows deleted.
Query:
ROLLBACK;
Result: deleted rows in the employee table is Roll backed.
SAVEPOINT:
It is used to create a marker in the current transaction which divides the transaction into smaller
sections. Roll back to that marker by using the ROLLBACK TO SAVEPOINT statement.
Query:
Delete from Employee where EID=587
Result: Remove Employee 587 in the Employee table.
1 row deleted.
Query:
savepoint A
Result:
Savepoint created.
Query:
Delete from Employee where EID=222
DR.N.SARANYA, AP(SL.G)/CSE, KPRIET 16
SQL – BASICS AND ADVANCED – PL/SQL
1 row deleted.
Query:
ROLLBACK TO A;
Result:
Rollback complete.
It is used to control database access. It gives access to specific objects in the database. Roles,
permissions, and referential integrity are created using data control language. Users can be given the
privileges to access database. Two types of privileges are there.
System Privilege :
More than 100 distinct system privileges are available for users and roles. System privileges
typically are provided by the database administrator.
Example:
CREATE SESSION
CREATE TABLE
CREATE SEQUENCE
CREATE VIEW
CREATE PROCEDURE
Object Privilege:
An object privilege is a privilege or right to perform a particular action on a specific table, view,
sequence, or procedure.
Example:
ALTER
DELETE
EXECUTE
INDEX
INSERT
REFERENCES
SELECT
UPDATE
DCL statements:
GRANT
REVOKE
Create user:
The DBA creates users by using the CREATE USER statement.
Syntax:
CREATE USER user_name IDENTIFIED BY password;
Example:
Query:
CREATE USER Student IDENTIFIED BY welcome;
Result:
User created.
Where, user name is Student and the password is welcome.
Role:
A role is a named group of related privileges that can be granted to the user. This method makes it easier
to revoke and maintain privileges. The DBA must create the role. Then the DBA can assignprivileges
to the role and users to the role.
Create role:
Syntax:
CREATE ROLE role;
Example:
Role created.
GRANT:
Database Administrator (DBA) can grant specific privileges to a user or role. DBA can create userand
role. Then the privilege is granted.
create table, create view privileges are granted to the user student.
Syntax:
GRANT object_priv [(columns)] ON object TO {user|role|PUBLIC} [WITH GRANT OPTION];
Example:
GRANT select ON Employee TO Student;
Grant succeeded.
REVOKE:
The REVOKE statement is used to revoke privileges granted to other users.
Syntax:
REVOKE {privilege [, privilege...]|ALL} ON object FROM {user[, user...]|role|PUBLIC}
[CASCADE CONSTRAINTS];
Example:
REVOKE select ON Employee FROM Student;
Revoke succeeded.
CONSTRAINTS:
Constraints are the rules enforced on the data columns of a table. These are used to limit the type of
data that can go into a table. This ensures the accuracy and reliability of the data in the database.
Constraints could be either on a column level or a table level. The column level constraints are applied
only to one column, whereas the table level constraints are applied to the whole table.
Following are some of the most commonly used constraints available in SQL:
1. Domain Constraint
a. Domain of an attribute specifies all the possible values that attribute can hold
b. It defines the domain or set of values for an attribute
c. It specifies that the value taken by the attribute must be the atomic (can’t be divided)
value from its domain
d. It contains
i. NOT NULL constraint
ii. CHECK constraint
The above relation satisfies Tuple Uniqueness Constraint since all attributes are unique
The above relation does not satisfies Tuple Uniqueness Constraint since all attributes are not unique
3. Key Constraint
a. All the values of primary key must be unique.
b. The value of primary key must not be null.
The above relation does not satisfies Tuple Uniqueness Constraint since all attributes are not unique
The above relation does not satisfy Entity Integrity Constraint as here the Primary Key contains a NULL
value.
5. Referential Integrity Constraint
a. This constraint is enforced when a foreign key references the primary key of a relation.
b. It specifies that all the values taken by the foreign key must either be available in the
relation of the primary key or be null.
c. We can not insert a record into a referencing relation if the corresponding record does
not exist in the referenced relation.
d. We can not delete or update a record of the referenced relation if the corresponding
record exists in the referencing relation.
Eg : Consider two relations ‘student’ and ‘Department’
Here relation ‘student’ references the relation ‘Department’
Here,
• The relation ‘Student’ does not satisfy the referential integrity constraint.
• This is because in relation ‘Department’, no value of primary key specifies department no. 14.
• Thus, referential integrity constraint is violated.
Constraint and its creation:
1. NOT NULL :
• Values cannot be NULL
• A NULL is not the same as no data, rather, it represents unknown data.
Eg : CREATE TABLE STUDENTS(
ROLL_NO INT NOT NULL,
NAME VARCHAR (20) ,
AGE INT,
PHONE INT);
• To add NOT NULL constraint to an existing table
ALTER TABLE STUDENTS
MODIFY AGE INT NOT NULL;
2. DEFAULT :
• Set Default Value if not passed
• It provides a default value to a column when the INSERT INTO statement does not provide a
specific value.
Eg : CREATE TABLE CUSTOMERS(
ID_NO INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
AGE INT NOT NULL,
COMPANY CHAR (25) ,
COMPANY VARCHAR (18) DEFAULT ‘Prepinsta’);
• To add DEFAULT constraint to an existing table
ALTER TABLE CUSTOMERS MODIFY SALARY DECIMAL (18, 2) DEFAULT 5000.00;
3. UNIQUE :
• Values cannot match any older values
• It prevents two records from having identical values in a column but accepts NULL values
• It is similar to primary key i.e., used to identify row uniquely but can have NULL values
Eg : CREATE TABLE STUDENTS(
ROLL_NO INT NOT NULL UNIQUE,
NAME VARCHAR (20) ,
AGE INT,
PHONE INT);
• To add UNIQUE constraint to an existing table
ALTER TABLE STUDENTS
MODIFY AGE INT NOT NULL UNIQUE;
• To add UNIQUE constraint to an existing table
ALTER TABLE STUDENTS
ADD CONSTRAINT myUniqueConstraint UNIQUE(AGE, PHONE);
4. PRIMARY KEY :
• Used to uniquely identify a row
• A primary key is a field in a table which uniquely identifies each row/record in a database table.
Primary keys must contain unique values. A primary key column cannot have NULL values.
• A table can have only one primary key, which may consist of single or multiple fields. When
multiple fields are used as a primary key, they are called a composite key.
• If a table has a primary key defined on any field(s), then you cannot have two records having the
same value of that field(s).
Eg : CREATE TABLE STUDENTS(
ROLL_NO INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
AGE INT NOT NULL,
GPA DECIMAL (18, 2),
PRIMARY KEY (ROLL_NO)
);
•To create PRIMARY KEY constraint on more than one attribute in a table is called Composite
Primary Key
CREATE TABLE STUDENTS(
ROLL_NO INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
AGE INT NOT NULL,
GPA DECIMAL (18, 2),
PRIMARY KEY (ROLL_NO, NAME));
• To add PRIMARY KEY constraint to an existing table
ALTER TABLE STUDENTS
ADD CONSTRAINT PK_ROLLNO PRIMARY KEY (ROLL_NO, NAME);
5. CHECK :
• Used to validates condition for a new value
• It enables a condition to check the value being entered into a record. If the condition evaluates to
false, the record violates the constraint and isn't entered the table.
6. FOREIGN KEY :
• Used to references a row in another table
• Uniquely identifies a row/record in any of the given database table.
• A foreign key is a key used to link two tables together. This is sometimes also called as a
referencing key.
• A Foreign Key is a column or a combination of columns whose values match a Primary Key in a
different table.
• The relationship between 2 tables matches the Primary Key in one of the tables with a Foreign
Key in the second table.
• If a table has a primary key defined on any field(s), then you cannot have two records having the
same value of that field(s).
STUDENT_DETAILS table
CREATE TABLE Student_Details(
ROLL_NO INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
COURSE_ID VARCHAR(10),
PRIMARY KEY (COURSE_ID)
);
STUDENT_MARKS table
CREATE TABLE Student_Marks (
COURSE_ID INT references Student_Details(COURSE_ID),
MARKS INT
);
If the Student_Marks table has already been created and the foreign key has not yet been set, the use the
syntax for specifying a foreign key by altering a table.
FUNCTIONS
• A function in Oracle is a subprogram that is used to perform an action such as complex
calculations and returns the result of the action as a value
• SQL is used to handle data in databases. It provides various in-built functions and commands
Dual in Oracle:
1. It is a pre-define table in oracle.
2. It is having single column & single row
DR.N.SARANYA, AP(SL.G)/CSE, KPRIET 35
SQL – BASICS AND ADVANCED – PL/SQL
TYPES OF FUNCTIONS
1. System Defined Functions - These type of functions, SQL Server already contains, which will be
difficult to implement without the System Defined Functions. This function is easily mixed with the
complicated and immediately required operations.
2. User Defined Functions - This function returns a value, based on the user-defined condition. User
Defined Functions are used to create an easy statement. It generates at the time of execution, which
is based on these parts:
• Scalar-valued function: A user-defined function can return a scalar value, we use this
statement in all the database.
• Inline function: When a user-defined function holds the Select statement, that is
updatable or not, the tabular result returned by the function is also updatable. These
functions are called inline functions. We can use these functions in the 'Form clause
of another query.
• Table-valued function: When a user-defined function holds the Select statement, that
is updatable or not, this Table-valued function returned is not updatable. Table-
valued function shows a table and we can use these functions in the 'Form clause of
another query.
Advantage of Functions
The SQL function have some advantages like:
• We can use these functions with where, having (clause).
• They can be used in a 'Select statement'.
• These are based on the function oriented.
• These functions are easy to use.
▪ Numeric Functions
▪ String Functions
▪ Date Functions
• Date functions can be defined as a set of functions that operate on date and
time and allows the developer to retrieve the current date and time in a
particular time zone or extract only the date/month/year or more complex
DR.N.SARANYA, AP(SL.G)/CSE, KPRIET 39
SQL – BASICS AND ADVANCED – PL/SQL
actions like extracting the last day of the month/next day/session time zone,
etc.
• It also consists of functions that can be used to convert a Date value to a
character string or convert a date that is in a character string to a Date value.
▪ Conversion Functions
The Oracle Server uses data of one type where it expects data of a different data type.
This can happen when the Server automatically converts the data to the expected data
type. This data type conversion can be done implicitly by the Server, or explicitly by
the user. As a user, we can use the following two functions to convert explicitly.
Function Description Syntax Example O/P
AGGREGATE FUNCTIONS:
• SQL aggregation function is used to perform the calculations on multiple rows of a single
column of a table. It returns a single value.
• Aggregate functions are often used with the GROUP BY and HAVING clauses of the SELECT
statement.
• These functions ignore the NULL values except the count function.
• It is a function where the values of multiple rows are grouped together as input on certain criteria
to form a single value of more significant meaning.
• It is also used to summarize the data.
i. COUNT:
• It is used to Count the number of rows in a database table. It can work on both numeric
and non-numeric data types.
Eg : Count(*): Returns total number of records .i.e 6.
Count(salary): Return number of Non Null values over the column salary. i.e 5.
Count(Distinct Salary): Return number of distinct Non Null values over the column
salary .i.e 4
ii. SUM:
• It is used to calculate the sum of all selected columns. It works on numeric fields only.
Eg : sum(salary): Sum all Non Null values of Column salary i.e., 310
sum(Distinct salary): Sum of all distinct Non-Null values i.e., 250.
iii. AVG:
• It is used to calculate the average value of the numeric type. AVG function returns the
average of all non-Null values.
Eg : Avg(salary) = Sum(salary) / count(salary) = 310/5
Avg(Distinct salary) = sum(Distinct salary) / Count(Distinct Salary) = 250/4
iv. MAX:
• It is used to find the maximum value of a certain column. This function determines the
largest value of all selected values of a column.
Eg : Max(salary): Maximum value in the salary column except NULL i.e., 80.
v. MIN:
• It is used to find the minimum value of a certain column. This function determines
the smallest value of all selected values of a column.
Eg : Min(salary): Minimum value in the salary column except NULL i.e., 40.
• A PL/SQL function is a reusable program unit stored as a schema object in the Oracle Database
• Its structure is as follows,
CREATE [OR REPLACE] FUNCTION function_name (parameter_list)
RETURN return_type
IS
[declarative section]
BEGIN
[executable section]
[EXCEPTION]
[exception-handling section]
END;
Eg:
DROP FUNCTION get_total_sales;
PL/SQL STORED PROCEDURE:
• A PL/SQL procedure is a reusable unit that encapsulates specific business logic of the application
• It is a prepared SQL code that you can save, so the code can be reused over and over again.
• It is a named block stored as a schema object in the Oracle Database.
• Its basic syntax includes,
CREATE [OR REPLACE ] PROCEDURE procedure_name (parameter_list)
IS
[declaration statements]
BEGIN
[execution statements]
EXCEPTION
[exception handler]
END [procedure_name ];
The most important part is parameters. Parameters are used to pass values to the Procedure. There are 3
different types of parameters, they are as follows:
1. IN: This is the Default Parameter for the procedure. It always receives the values from calling
program.
2. OUT: This parameter always sends the values to the calling program.
3. IN OUT: This parameter performs both the operations. It Receives value from as well as sends the
values to the calling program.
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( SQLERRM );
END;
Eg:
EXEC print_contact(100);
S.NO SP UDF
1 It may or may not return a value It must return a value
2 It can have input/output parameters It has only input parameters
3 Can call UDF from SP Cannot call SP from UDF
SP cannot be used in SQL statements like UDF can be used in SQL statements like
4
SELECT, INSERT, UPDATE, DELETE SELECT, INSERT, UPDATE, DELETE
SP cannot be used anywhere in the UDF can be used anywhere in the
5 WHERE/HAVING/SELECT part of WHERE/HAVING/SELECT part of SQL
SQL queries queries
Execution plan can be re-used in SP Execution plan can be compiled every time in
6
UDF
7 Can use transactions in SP Cannot use transactions in UDF
SP can have both table variables and UDF can have only table variables as it does not
8
temporary tables permit the use of temporary tables
• Improved security measures
• Client/server traffic is reduced. • Enables faster execution
9 • Programming abstraction and • Modular Programming
efficient code reuse • Can reduce network traffic (data)
• Pre-compiled Execution
VIEWS
A) Creating View
Eg:
CREATE VIEW employee_yos AS
SELECT employee_id, first_name || ' ' || last_name full_name,
To remove a view,
DROP VIEW view_name;
Eg:
DROP VIEW employee_yos;
JOINS
• A Join operation pairs two tuples from different relations, if and only if a given join
condition issatisfied. Three types of joins available namely inner join, outer join, semi
join.
• Oracle join is used to combine columns from two or more tables based on values of the
related columns. The related columns are typically the primary key column(s) of the first
table and foreign key column(s) of the second table.
• Oracle supports inner join, left join, right join, full outer join and cross join.
• Note that you can join a table to itself to query hierarchical data using an inner join, left
join, or right join. This kind of join is known as self-join
• The VIEW continues to exist even after one of the tables (that the Oracle VIEW is based
on) is dropped from the database. However, if you try to query the Oracle VIEW after the
table has been dropped, you will receive a message indicating that the Oracle VIEW has
errors.
Inner Join :
An inner join includes only those tuples with matching attributes and the rest are discarded in the
resulting relation. Theta Join, Equijoin, and Natural Join are called inner joins.
Theta Join ( )
Theta join combines tuples from different relations provided they satisfy the theta condition. The
join condition is denoted by the symbol .Theta join can use all kinds of comparison operators. The
general form is
R1 R2
Example
Equi Join( c)
Equijoin is a special case of join where only equality condition holds between a pair of attributes. As
values of two attributes will be equal in result of equijoin, only one attribute will appear in resultThe
general form is
R1 c R2
Example
Relations: Employee, Project
Query:
Employee Employee.Eid=Project.Empid Project
Result
Natural Join ( )
It is used to combine related tuples from two relations into single based on equality condition. There
is noneed to specify equality condition explicitly
Example
Relation: Employee, Project
Query:
employee project
Result:
Example
Relation: Employee, Project
Query:
employee ⋉ project
Result:
Outer Join
Outer joins include all the tuples from the participating relations in the resulting relation. There are
three kinds of outer joins − left outer join, right outer join, and full outer join.
All the tuples from the Left relation, R, are included in the resulting relation. If there are tuples in R
without any matching tuple in the Right relation S, then the S-attributes of the resulting relation are
made NULL.
Example:
Customer Relation:
custome first_na
last_name email address city state zipcode
r_id me
gwashington 3200 Mt Vernon Mount
1 George Washington VA 22121
@usa.gov Hwy Vernon
jadams@usa.g
2 John Adams 1250 Hancock St Quincy MA 02169
ov
tjefferson@us 931 Thomas Charlott
3 Thomas Jefferson VA 22902
a.gov Jefferson Pkwy esville
11350
jmadison@us
4 James Madison Constitution Orange VA 22960
a.gov
Hwy
jmonroe@usa. 2050 James Charlott
5 James Monroe VA 22902
gov Monroe Parkway esville
Orders Relations
All the tuples from the Right relation, S, are included in the resulting relation. If there are tuples in
S without any matching tuple in R, then the R-attributes of resulting relation are made NULL.
Example
Relation: Customer, Orders
Query:
DR.N.SARANYA, AP(SL.G)/CSE, KPRIET 55
SQL – BASICS AND ADVANCED – PL/SQL
Customer ⟖ Orders
Result:
Relation:
Customer,
OrdersQuery:
Customer⟗
Orders
Result