0% found this document useful (0 votes)
129 views74 pages

Veena DBM S Module 3

SQL is a standard language for querying, manipulating, and transforming data from relational databases. The document discusses SQL commands like CREATE, DROP, ALTER, which are used to define and modify database structure and objects. CREATE is used to create databases and tables. DROP removes databases and tables. ALTER modifies the structure of existing tables, such as adding, removing, or modifying columns. Common data types for table columns include INT, VARCHAR, DATE, TEXT.

Uploaded by

chintala sandhya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
129 views74 pages

Veena DBM S Module 3

SQL is a standard language for querying, manipulating, and transforming data from relational databases. The document discusses SQL commands like CREATE, DROP, ALTER, which are used to define and modify database structure and objects. CREATE is used to create databases and tables. DROP removes databases and tables. ALTER modifies the structure of existing tables, such as adding, removing, or modifying columns. Common data types for table columns include INT, VARCHAR, DATE, TEXT.

Uploaded by

chintala sandhya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 74

SQL- Structured Query Language MODULE 3

Chapter 1: Introduction to SQL


 Structure Query Language (SQL) is a database query language used for storing and
managing data in Relational DBMS.
 SQL was the first commercial language introduced for E.F Codd's Relational model
of database.
 Almost all RDBMS (MySql, Oracle, Infomix, Sybase, MS Access) use SQL as the
standard database query language. SQL is used to perform all types of data
operations in RDBMS.
 SQL is a standard language for accessing and manipulating databases.
 SQL, or Structured Query Language, is a language designed to allow both technical
and non-technical users query, manipulate, and transform data from a relational
database. And due to its simplicity, SQL databases provide safe and scalable storage
for millions of websites and mobile applications.

 Relational Databases
 A relational database is based on tables (or relations) to store the data. The word
'relation' or 'table' is now more widely used in database systems. Within the unit
database the word 'table' will be used.
 . A table holds related information. For example, a company holds details on
employees, sections, salaries, pensions, projects, etc. A relational database contains
many such tables.
 A table is made up of rows (records) and columns (fields). Rows and columns, as
opposed to records and fields, are the names most commonly used when working
with database systems. An example table is shown below:

Employee Table

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 1
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

It is important to note that:


 The convention is to give a singular name to tables (e.g. employee as opposed to
employees)
 Each row within a table must have the same number of columns
 The data in each column is of the same data type (that is character, numeric or date -
There are other data types but, for this unit, only character, numeric and date are
considered.)
 Each row must have a column (or group of columns) whose value must uniquely
identify that row.
For example, in the employee table above, an employee's number would be used to
uniquely identify an individual employee. This column (or group of columns) used to
uniquely identify a row is known as the primary key. A table must have one, and only
one, primary key defined.
 These SQL commands are mainly categorized into four categories.

1. DDL(Data Definition Language) :


 DDL or Data Definition Language actually consists of the SQL commands that can be
used to define the database schema.
 A data definition language (DDL) is a computer language used to create and modify the
structure of database objects in a database. These database objects include views,
schemas, tables, indexes, etc.
 This term is also known as data description language in some contexts, as it describes
the fields and records in a database table.

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 2
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
Examples of DDL commands:
 CREATE – is used to create the database or its objects (like table, index, function, views,

store procedure and triggers).


 DROP – is used to delete objects from the database.

 ALTER-is used to alter the structure of the database.

 TRUNCATE–is used to remove all records from a table, including all spaces allocated for

the records are removed.


 RENAME –is used to rename an object existing in the database.

 CREATE
 Create is a DDL SQL command used to create a table or a database in relational
database management system.

 Creating a Database- Following is the syntax

CREATE DATABASE <DB_NAME>;

 Example for creating Database


CREATE DATABASE Test;
The above command will create a database named Test, which will be an empty schema
without any table.

 Creating a Table- Create command can also be used to create tables. When we create a
table, we have to specify the details of the columns of the tables too. We can specify
the names and data types of various columns in the create command itself.

Following is the syntax,

CREATE TABLE <TABLE_NAME>(column_name1 datatype1, column_name2 datatype2,


column_name3 datatype3, column_name4 datatype4);

Create table command will tell the database system to create a new table with the given
table name and column information.

Example for creating Table

CREATE TABLE Student( student_id INT, name VARCHAR(100),age INT);

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 3
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
The above command will create a new table with name Student in the current database
with 3 columns, namely student_id, name and age. Where the column student_id will
only store integer, name will hold up to 100 characters and age will again store only
integer value.

If we are currently not logged into wer database in which we want to create the table
then we can also add the database name along with table name, using a dot operator .

For example, if we have a database with name Test and we want to create a
table Student in it, then we can do so using the following query:

CREATE TABLE Test.Student(student_id INT, name VARCHAR(100),age INT);

Most commonly used data types for Table columns

Here we have listed some of the most commonly used data types used for columns in
tables.

Data type Use

INT Used for columns to store integer values.

FLOAT Used for columns to store float values.

DOUBLE Used for columns to store float values.

VARCHAR Used for columns to store characters and integers, basically a string.

CHAR Used for columns to store char values (single character).

DATE Used for columns to store date values.

TEXT Used for columns to store text this is generally long in length. For
example, if we create a table for storing profile information of a
social networking website, then for about me section we can have a
column of type TEXT.

 DROP
 DROP command allows removing entire database objects from the database.

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 4
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
 It removes entire data structure from the database.
 It deletes a table, index or view.
 Syntax:
DROP TABLE <table_name>; OR DROP DATABASE <database_name>;

Example for deleting Table and database

DROP TABLE employee; OR DROP DATABASE employees;


 ALTER
 alter command is used for altering the table structure, such as,
 To add a column to existing table
 To rename any existing column
 To change data type of any column or to modify its size.
 To drop a column from the table.
ALTER Command: Add a new Column
 Using ALTER command we can add a column to any existing table.
 Following is the syntax:

ALTER TABLE table_name ADD (column_name data type);


 Example: ALTER TABLE student ADD (address VARCHAR (200));
The above command will add a new column address to the table student, which will
hold data of type varchar which is nothing but string, of length 200.
ALTER Command: Add multiple new Columns
 Using ALTER command we can even add multiple new columns to any existing table.
 Following is the syntax:
ALTER TABLE table_name ADD(column_name1 datatype1, column-name2
datatype2, column-name3 datatype3);
 Example: ALTER TABLE student ADD(father_name VARCHAR(60),mother_name
VARCHAR(60), dob DATE);
The above command will add three new columns to the student table
ALTER Command: Add Column with default value

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 5
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
 ALTER command can add a new column to an existing table with a default value too.
The default value is used when no value is inserted in the column.
 Following is the syntax:
ALTER TABLE table_name ADD (column-name1 datatype1 DEFAULT some_value);
 Example: ALTER TABLE student ADD (dob DATE DEFAULT '01-Jan-99');
The above command will add a new column with a preset default value to the
table student.
ALTER Command: Modify an existing Column
 ALTER command can also be used to modify data type of any existing column.
 Following is the syntax:
 ALTER TABLE table_name modify(column_name data type);
 Example: ALTER TABLE student MODIFY( address varchar(300));
The above command will modify the address column of the student table, to now
hold up to 300 characters.
ALTER Command: Rename a Column
 Using ALTER command we can rename an existing column.
 Following is the syntax:
ALTER TABLE table_name RENAME old_column_name TO new_column_name;
 Example: ALTER TABLE student RENAME address TO location;
The above command will rename address column to location.
ALTER Command: Drop a Column
 ALTER command can also be used to drop or remove columns.
 Following is the syntax:
 ALTER TABLE table_name DROP( column_name);
 Example: ALTER TABLE student DROP(address);
The above command will drop the address column from the table student.
 TRUNCATE
 TRUNCATE command is used to delete all the rows from the table permanently.
 It removes all the records from a table, including all spaces allocated for the
records.

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 6
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
 This command is same as DELETE command, but TRUNCATE command does not
generate any rollback data
 TRUNCATE command removes all the records from a table. But this command will
not destroy the table's structure.
 Following is the syntax: TRUNCATE TABLE table_name
 Example: TRUNCATE TABLE student;
The above query will delete all the records from the table student.
 RENAME
 RENAME command is used to set a new name for any existing table.
 Following is the syntax: RENAME TABLE old_table_name to new_table_name
 Example: RENAME TABLE student to students_info;
The above query will rename the table student to students_info.
2. DML(Data Manipulation Language) :
 DML is short name of Data Manipulation Language which deals with data
manipulation and includes most common SQL statements such SELECT, INSERT,
UPDATE, DELETE, etc., and it is used to store, modify, retrieve, delete and update data
in a database.
 SELECT - retrieve data from a database
 INSERT - insert data into a table
 UPDATE - updates existing data within a table
 DELETE - Delete all records from a database table

 INSERT
 To add data to a table the INSERT command is used.
 The syntax of the INSERT command is given below:
INSERT into table-name values (data, data …);
 EXAMPLE : Suppose we have the following fields in the table named as EMPLOYEE as
follows:

Dept_No Dept_Name Emp_No Emp_Name

 Now use the following query to insert values to these fields in table.

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 7
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
INSERT into EMPLOYEE values (10, ‘Management’, ‘E01’, ‘John Abraham’);
This query will add the data into the fields and will produce the following result:

Dept_No Dept_Name Emp_No Emp_Name

10 Management E01 John Abraham

EXAMPLE to insert NULL value to a column


 In the above query if we do not specify or define any of the fields then a null value
will be inserted into that field or column. For example if the in the above example
the field is not specified that is the name of the employee is not mentioned in the
query then the name field will be assigned a NULL value. However if a default value
is set then a default value will be inserted instead of a null value.
 Suppose we have the following fields in the table named as EMPLOYEE as follows:

Dept_No Dept_Name Emp_No Emp_Name


 INSERT into EMPLOYEE values (10, ‘Management’, ‘E01’);

This query will add the data into the fields and will produce the following result:

Dept_No Dept_Name Emp_No Emp_Name

10 Management E01
 We can also write NULL in the reference of the field and NULL value is specified to
the field as the following query:
INSERT into EMPLOYEE values (10, ‘Management’, ‘E01’, null);
This will result the same as the above query.
EXAMPLE to insert default value to a column:
 If some value is set then writing the default keyword for that very specific field, then
this value will be inserted into that column. Suppose the default value of the field
EMP_NAME is set as “John Abraham” then using the default keyword will insert this
name in the field. Consider the following query to understand this:
INSERT into EMPLOYEE values (10, ‘Management’, ‘E01’, default);

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 8
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
This query will add the data into the fields and will produce the following result:

Dept_No Dept_Name Emp_No Emp_Name

10 Management E01 John Abraham


 Update
 To update a table or row or column in the table we use the update command. The
syntax of update command is given below:
 Update table-name set column-name = value where condition;
 EXAMPLE: Suppose we have a table that is named as employee.

Dept_No Dept_Name Emp_No Emp_Name

10 Management E01 John Abraham

20 Management E02 Tim

30 Finance E10 Ali

40 Finance E11 Faddy

50 IT E25 Kate
 To update the table we are going to use the following query:

Update employee set EMP_NO = E04 where DEPT_NO = 30;

 This query will produce the following result:

Dept_No Dept_Name Emp_No Emp_Name

10 Management E01 John Abraham

20 Management E02 Tim

30 Finance E04 Ali

40 Finance E11 Faddy

50 IT E25 Kate
This will update entry in the column EMP_NO with DEPT_NO 30.

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 9
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
EXAMPLE to update multiple columns:

 If the user wants to update a number of columns of the table then he can use the
following query:

Update employee set EMP_NO = E06, set Emp_Name = ‘Stuart’ where DEPT_NO = 30;

 This query will update the entries in the column EMP_NO and Emp_Name with
DEPT_NO 30. The following result will be produced:

Dept_No Dept_Name Emp_No Emp_Name

10 Management E01 John Abraham

20 Management E02 Tim

30 Finance E06 Stuart

40 Finance E11 Faddy

50 IT E25 Kate
It can be observed that the name Ali is changed to Stuart and E04 is changed to E06.
 Delete
 To delete a table row or some data from a table in the database the delete command is
used.
 The syntax of delete command is as follows: DELETE from table-name;
EXAMPLE to delete all records from a table
 To delete all records use the delete command. This will delete the attributes, indexes
etc. of the table but the table as a whole will not be deleted.
 To delete all records from the table use the following SQL statement:
DELETE from Employee;
 This query will delete all the records from the table named as Employee. This change
will be permanent and cannot be recovered.
EXAMPLE to delete a particular record from a table:
Suppose we have the following table named as EMPLOYEE:

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 10
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

Dept_No Dept_Name Emp_No Emp_Name

10 Management E01 John Abraham

20 Management E02 Tim

30 Finance E04 Ali

40 Finance E11 Faddy

50 IT E25 Kate
 If we want to delete a specific record from the table then use the following query:

DELETE from employee where DEPT_NO = 40;

 This query will delete the records where the department number is 40 from the table
named as employee. This will delete the whole row from the table. The following result
will be generated:

Dept_No Dept_Name Emp_No Emp_Name

10 Management E01 John Abraham

20 Management E02 Tim

30 Finance E04 Ali

50 IT E25 Kate

 Select
 Select command is used to view the records from the table. To view all the columns and
all the rows ‘*’can be specified with the select statement. The name of the table is
required while specifying the select.
 Syntax :- Select * from <tablename>;
 EXAMPLE : SQL> select * from student;
Output:-

ROLLNO NAME MARKS ADDR


101 ABC 75 LINK ROAD
102 XYZ 80 JM ROAD

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 11
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

103 PQR 67 N7

 Select statement is very flexible. If user needs to view only certain fields or columns,
then by specifying those names of the columns in the form of list, user can view the
required output.
 The general form is as follows:
Select column1, column2, column3…… column n from <tablename>;
 EXAMPLE : SQL> select rollno, name, marks from student;
Output:-

ROLLNO NAME MARKS


101 ABC 75
102 XYZ 80
103 PQR 67
3 rows selected.
 To select particular row ‘where clause is used. This clause allows user to put the
condition. The rows or columns which satisfy the condition will be displayed.
 Syntax:- Select<column1><column2><column3> from <tablename> where
condition;
 EXAMPLE : SQL> select * from student where marks=80;

ROLLNO NAME MARKS ADDR


102 XYZ 80 JM ROAD

3. Data Control Language (DCL)


A Data Control Language (DCL) can be defined as a computer language that is used for
controlling privilege in the database. The privileges are required for performing all the
database operations, such as creating sequences, views or tables. It is a part of the
Structured Query Language.
 Types of Privileges
There are two main types of privileges in the database:

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 12
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
 System Privileges- System privileges are used for performing a particular type of
action on objects, such as cache groups, synonyms, materialized views, tables, views,
sequences, indexes, replication schemes, and PL/SQL procedures & functions. This
type of privileges can only be granted or revoked by the instance administrator or a
user.
 Object Privileges- Object privileges can be defined as the right for performing a special type
of action on objects like materialized views, sequences, replication schemes, cache groups,
synonyms, tables, views, etc. This type of privilege cannot be revoked and the owner of the
object can grant object privileges.
 Data Control Languages (DCL) Commands
There are two types of commands in the data control languages:
1. Grant Command- Grant Command is used for offering access or privileges to the
users on the objects of the database. Through this command, the users get access to
the privileges in the database.
 The General Syntax for the Grant Command is mentioned below:

GRANT privilege_name ON object_name TO {user_name I PUBLIC I role_name}


[WITH GRANT OPTION];

 For Example- GRANT ALL ON workers TO MNO; [WITH GRANT OPTION]


In the given example, the permission to view and modify the details in the ‘workers
table’ has been given to the user MNO.
2. Revoke Command- The main purpose of the revoke command is canceling the
previously denied or granted permissions. Through the revoke command, the access
to the given privileges can be withdrawn. In simple words, the permission can be
taken back from the user with this command.
 The general syntax for the revoke command is mentioned below:
REVOKE<privilege list> ON <relation name or view name> From <user name>

 For Example- REVOKE UPDATE ON worker FROM MNO;

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 13
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
 Allow a User to create session- When we create a user in SQL, it is not even allowed to login
and create a session until and unless proper permissions/privileges are granted to the user.

 Following command can be used to grant the session creating privileges.

GRANT CREATE SESSION TO username;

 Allow a User to create table- To allow a user to create tables in the database, we can use the
below command,

GRANT CREATE TABLE TO username;

 Grant all privilege to a User- Sysdba is a set of privileges which has all the permissions in it.
So if we want to provide all the privileges to any user, we can simply grant them
the sysdba permission.

GRANT sysdba TO username;

 Grant permission to create any table- Sometimes user is restricted from creating come
tables with names which are reserved for system tables. But we can grant privileges to a user to
create any table using the below command,

GRANT CREATE ANY TABLE TO username;

 Grant permission to drop any table- As the title suggests, if we want to allow user to drop
any table from the database, then grant this privilege to the user,

GRANT DROP ANY TABLE TO username;

 To take back Permissions- If we want to take back the privileges from any user, use
the REVOKE command.

REVOKE CREATE TABLE FROM username;

Differences between the Grant and Revoke Command

Grant Command Revoke Command

A user is allowed to perform some particular A user is disallowed to performing some


activities on the database by using Grant particular activities by using the revoke
Command. command.
The access to privileges for database objects
The access to privileges for database objects
that is granted previously to the users can be
is granted to the other users.
revoked.

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 14
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
4. Transaction Control Language(TCL)

Commands are used to manage transactions in the database. These are used to manage
the changes made to the data in a table by DML statements. It also allows statements to
be grouped together into logical transactions.

 COMMIT command
 COMMIT command is used to permanently save any transaction into the database.
 When we use any DML command like INSERT, UPDATE or DELETE, the changes made
by these commands are not permanent, until the current session is closed, the
changes made by these commands can be rolled back.
 To avoid that, we use the COMMIT command to mark the changes as permanent.
 Following is commit command's syntax- COMMIT;

 ROLLBACK command

 This command restores the database to last committed state. It is also used
with SAVEPOINT command to jump to a save point in an ongoing transaction.

 If we have used the UPDATE command to make some changes into the database, and
realize that those changes were not required, then we can use
the ROLLBACK command to rollback those changes, if they were not committed using
the COMMIT command.

 Following is rollback command's syntax- ROLLBACK TO savepoint_name;

 SAVEPOINT command

 SAVEPOINT command is used to temporarily save a transaction so that we can


rollback to that point whenever required.

 Following is savepoint command's syntax- SAVEPOINT savepoint_name;

 In short, using this command we can name the different states of our data in any table
and then rollback to that state using the ROLLBACK command whenever required.

 Using Savepoint and Rollback and Following is the table class,

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 15
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

id name

1 Abhi

2 Adam

4 Alex

Using some SQL queries on the above table and results.


INSERT INTO class VALUES(5, 'Rahul');
COMMIT;

UPDATE class SET name = 'Abhijit' WHERE id = '5';


SAVEPOINT A;
INSERT INTO class VALUES(6, 'Chris');
SAVEPOINT B;
INSERT INTO class VALUES(7, 'Bravo');
SAVEPOINT C;

SELECT * FROM class;


NOTE: SELECT statement is used to show the data stored in the table.
The resultant table will look like,

id name

1 Abhi

2 Adam

4 Alex

5 Abhijit

6 Chris

7 Bravo
Use the ROLLBACK command to roll back the state of data to the savepoint B.
ROLLBACK TO B;

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 16
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
SELECT * FROM class;
Now class table will look like,

id name

1 Abhi

2 Adam

4 Alex

5 Abhijit

6 Chris
Again use the ROLLBACK command to roll back the state of data to the savepoint A

ROLLBACK TO A;
SELECT * FROM class;
The table will look like,

id name

1 Abhi

2 Adam

4 Alex

5 Abhijit

 SELECT queries

SQL SELECT statement syntax- It is the most frequently used SQL command and has the
following general syntax
SELECT [DISTINCT| ALL ] { * | [fieldExpression [AS newName]} FROM tableName
[alias] [WHERE condition][GROUP BY fieldName(s)] [HAVING condition] ORDER BY
fieldName(s)

Here
 SELECT is the SQL keyword that lets the database know that we want to retrieve data.

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 17
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
 [DISTINCT | ALL] are optional keywords that can be used to fine tune the results
returned from the SQL SELECT statement. If nothing is specified then ALL is assumed as
the default.
 {*| [fieldExpression [AS newName]} at least one part must be specified, "*" selected
all the fields from the specified table name, fieldExpression performs some
computations on the specified fields such as adding numbers or putting together two
string fields into one.
 FROM tableName is mandatory and must contain at least one table, multiple tables
must be separated using commas or joined using the JOIN keyword.
 WHERE condition is optional, it can be used to specify criteria in the result set returned
from the query.
 GROUP BY is used to put together records that have the same field values.
 HAVING condition is used to specify criteria when working using the GROUP BY
keyword.
 ORDER BY is used to specify the sort order of the result set.

ORDER BY
The SQL ORDER BY clause is used to sort the data in ascending or descending order,
based on one or more columns. Some databases sort the query results in an ascending
order by default.

Syntax
The basic syntax of the ORDER BY clause is as follows −

SELECT column-list
FROM table_name
[WHERE condition]
[ORDER BY column1, column2, .. columnN] [ASC | DESC];
We can use more than one column in the ORDER BY clause.
Example
Consider the CUSTOMERS table having the following records −
+----+----------+-----+-----------+----------+

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 18
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
This example, which would sort the result in an ascending order by the NAME and the
SALARY −
SQL> SELECT * FROM CUSTOMERS ORDER BY NAME, SALARY;
This would produce the following result −
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
+----+----------+-----+-----------+----------+
This example, which would sort the result in the descending order by NAME.
SQL> SELECT * FROM CUSTOMERS ORDER BY NAME DESC;
This would produce the following result −
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 19
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
+----+----------+-----+-----------+----------+
GROUP BY

 The SQL GROUP BY syntax


SELECT column-names FROM table-name WHERE condition GROUP BY column-names;
 The general syntax with ORDER BY is:
SELECT column-names FROM table-name WHERE condition GROUP BY column-names
ORDER BY column-names;

 Example - Using GROUP BY with the SUM Function


To use the GROUP BY clause with the SUM function in SQL.
In this example, we have a table called employees with the following data:

employee_number last_name first_name salary dept_id


1001 Smith John 62000 500
002 Anderson Jane 57500 500
1003 Everest Brad 71000 501
1004 Horvath Jack 42000 501
SQL statement:
SELECT dept_id, SUM(salary) AS total_salaries FROM employees GROUP BY dept_id;
There will be 2 records selected.

dept_id total_salaries

500 119500

501 113000

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 20
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
In this example, we have used the SUM function to add up all of the salaries for
each dept_id and we have aliased the results of the SUM function as total_salaries. Because
the dept_id is not encapsulated in the SUM function, it must be listed in the GROUP BY
clause.

Example - Using GROUP BY with the COUNT function


To use the GROUP BY clause with the COUNT function in SQL.
In this example, we have a table called products with the following data:
product_id product_name category_id
1 Pear 50
2 Banana 50
3 Orange 50
4 Apple 50
5 Bread 75
6 Sliced Ham 25
7 Kleenex NULL
SQL statement:
SELECT category_id, COUNT(*) AS total_products FROM products
WHERE category_id IS NOT NULL GROUP BY category_id ORDER BY category_id;
There will be 3 records selected.

category_id total_products
25 1
50 4
75 1
In this example, we have used the COUNT function to calculate the number of products for
each category_id and we have aliased the results of the COUNT function as total_products.
We have excluded any category_id values that are NULL by filtering them out in the WHERE
clause. Because the category_id is not encapsulated in the COUNT function, it must be listed
in the GROUP BY clause.

Example - Using GROUP BY with the MIN function


To use the GROUP BY clause with the MIN function in SQL.
In this example, we will use the employees table again that is populated the following data:

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 21
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

employee_number last_name first_name salary dept_id


1001 Smith John 62000 500
1002 Anderson Jane 57500 500
1003 Everest Brad 71000 501
1004 Horvath Jack 42000 501
SQL statement:
SELECT dept_id, MIN(salary) AS lowest_salary FROM employees GROUP BY dept_id;
There will be 2 records selected.

dept_id lowest_salary

500 57500

501 42000

In this example, we have used the MIN function to return the lowest salary for
each dept_id and we have aliased the results of the MIN function as lowest_salary. Because
the dept_id is not encapsulated in the MIN function, it must be listed in the GROUP BY
clause.

Example - Using GROUP BY with the MAX function


To use the GROUP BY clause with the MAX function.
Let's use the employees table again, but this time find the highest salary for each dept_id:

employee_number last_name first_name salary dept_id


1001 Smith John 62000 500
1002 Anderson Jane 57500 500
1003 Everest Brad 71000 501
1004 Horvath Jack 42000 501
SQL statement:
SELECT dept_id, MAX(salary) AS highest_salary FROM employees GROUP BY dept_id;
There will be 2 records selected.

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 22
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

dept_id highest_salary
500 62000
501 71000
In this example, we have used the MAX function to return the highest salary for
each dept_id and we have aliased the results of the MAX function as highest_salary.
The dept_id column must be listed in the GROUP BY clause because it is not encapsulated in
the MAX function.

Example - COUNT Function only includes NOT NULL Values


The COUNT function will only count the records where the expression is NOT NULL
in COUNT(expression). When the expression is a NULL value, it is not included in the
COUNT calculations. Let's explore this further.
In this example, we have a table called customers with the following data:

customer_id last_name first_name favorite_website

4000 Jackson Joe techonthenet.com

5000 Smith Jane digminecraft.com

6000 Ferguson Samantha bigactivities.com

7000 Reynolds Allen checkwermath.com

8000 Anderson Paige NULL

9000 Johnson Derek techonthenet.com

The following SELECT statement that uses the COUNT function:


SELECT COUNT(customer_id) FROM customers;
There will be 1 record selected.

COUNT(customer_id)
6
In this example, the query will return 6 since there are 6 records in the customers table and
all customer_id values are NOT NULL (ie: customer_id is the primary key for the table).

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 23
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
But what happens when we encounter a NULL value with the COUNT function? Let's enter
this next SELECT statement that counts the favorite_website column which can contain
NULL values:

SELECT COUNT(favorite_website) FROM customers;


There will be 1 record selected.

COUNT(favorite_website)
5
This second example will return 5. Because one of the favorite_website values is NULL, it
would be excluded from the COUNT function calculation. As a result, the query will return 5
instead of 6.
Example - Using a Single Expression in the COUNT Function
To use the COUNT function with a single expression in a query.
In this example, we have a table called employees with the following data:

employee_number last_name first_name salary dept_id


1001 Smith John 62000 500
1002 Anderson Jane 57500 500
1003 Everest Brad 71000 501
1004 Horvath Jack 42000 501
SQL statement:
SELECT COUNT(*) AS total FROM employees WHERE salary > 50000;
There will be 1 record selected. These are the results that we should see:

total
3
In this example, we will return the number of employees who have a salary above $50,000.
We have aliased the COUNT(*) as total to make our query results more readable.
Now, total will display as the column heading when the result set is returned.

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 24
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
Example - Using GROUP BY with the COUNT Function
In some cases, we will be required to use the GROUP BY clause with the COUNT function.
This happens when we have columns listed in the SELECT statement that are not part of
the COUNT function. Let's explore this further.
Again, using the employees table populated with the following data:

employee_number last_name first_name salary dept_id


1001 Smith John 62000 500
1002 Anderson Jane 57500 500
1003 Everest Brad 71000 501
1004 Horvath Jack 42000 501
SQL statement:
SELECT dept_id, COUNT(*) AS total FROM employees WHERE salary > 50000 GROUP BY
dept_id;
There will be 2 records selected.

dept_id total
500 2
501 1
In this example, the COUNT function will return the number of employees that make over
$50,000 for each dept_id. Because the dept_id column is not included in the COUNT
function, it must be listed in the GROUP BY clause.
Example - Using DISTINCT with the COUNT Function
to count only the unique values.
Using the same employees table as the previous example:

employee_number last_name first_name salary dept_id


1001 Smith John 62000 500
1002 Anderson Jane 57500 500
1003 Everest Brad 71000 501
1004 Horvath Jack 42000 501

SQL statement:
SELECT COUNT(DISTINCT dept_id) AS total FROM employees WHERE salary > 50000;

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 25
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
There will be 1 record selected. These are the results that we should see:

total
2
In this example, the COUNT function will return the unique number of dept_id values that
have at least one employee that makes over $50,000.
 Views
 A VIEW is a virtual table, through which a selective portion of the data from one or more
tables can be seen.
 Views do not contain data of their own. They are used to restrict access to
the database or to hide data complexity.
 A view is stored as a SELECT statement in the database.
 DML operations on a view like INSERT, UPDATE, DELETE affects the data in the original
table upon which the view is based.
 A view contains rows and columns, just like a real table. The fields in a view are fields
from one or more real tables in the database.
 A view is a specific representation of data from one or more tables. The tables referred
in the views are known as Base tables.
 Creating a view does not take any storage space as only the query is stored in the data
dictionary and the actual data is not stored anywhere.

For example: suppose that in the EMF table we want that 'Manager' should have access to
the detail of employee's names, job and department. But he should not have any access to
the salaries of all the employees. This can be done with the help of Views. We can create
View according to the individual's need. We will create the view for the manager under
which we do not include salary column. This helps the database administrator to limit the
access to different kinds of users.

Uses of Views

The reasons for using views in applications can be many like;

 Reducing complexity.
 Security is increased - sensitive information can be excluded from a view

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 26
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
 Renaming the table columns- by giving the different names to columns while creating views
 Views can represent a subset of the data contained in a table.
 Views can join and simplify multiple tables into a single virtual table.
 Views take very little space to store; the database contains only the definition of a view, not a
copy of all the data it presents.
 Different views can be created on the same base table for different users.
Syntax:
CREATE [OR REPLACE] VIEW view_name AS SELECT column_list FROM table_name
[WHERE condition] [WITH CHECK OPTION][CONSTRAINT constrain_name]
[WITH READ ONLY];

 In the Syntax, View _name specifies the name of the view and must follow the rules for
identifiers. Column_name specifies the name of the column to be used in view. If the
column_name option is not specified, then the view is created with the same columns as
specified in the select_statement. Select_statement specifies the SELECT Statement that
defines a view.

 The view may use the data contained in other views and tables. WITH CHECK OPTION
forces the data modification statements to fulfill the criteria given in the SELECT
statement defining the view. It also ensures that the data is visible after the modifications
are made permanent. WITH READ ONLY restrict the DML operations to be performed on
the view.

 Creating Views

To create a view, we must meet the following requirements:

 To create a view in our schema, we must have the CREATE VIEW privilege.

 To create a view in another user's schema, we must have the CREATE ANY VIEW system
privilege. We can acquire these privileges explicitly or through a role.

 The owner of the view (whether it is we or another user) must have been explicitly
granted privileges to access all objects referenced in the view definition. The owner

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 27
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
cannot have obtained these privileges through roles. Also, the functionality of the view
depends on the privileges of the view owner.

 For example, if the owner of the view has only the INSERT privilege for Scott's EMP table,
then the view can be used only to insert new rows into the EMP table, not to SELECT,
UPDATE, or DELETE rows.

Examples:

Consider the EMPLOYEES table and create a View for the 'RAMAN'; she cannot access the
Salary of all the employees.

SQL > DESC EMPLOYEES;


SQL > CREATE OR REPLACE VIEW RAMAN AS SELECT EID, NAME FROM EMPLOYEES;

On Execution the view with Name 'Raman' is created. Once we create a view now it is
assumed to be a Table. We can now perform the various DML operations on the View. But
make sure if we impose the CHECK OPTIONS, then we cannot perform any operation.
Remember that it will also copy the Records contained in the base table. Display all the
records in the view.

SQL> SELECT * FROM RAMAN;

After execution this command will display all the records of EMP table as when view
created all the records automatically copied into the view. It will display all the records.

 Read Only Option

If we use read only option in the view while creation then we cannot perform any DML
operation on the view. If we try to do this then error message will encounter. WITH READ
ONLY restrict the DML operations to be performed on the view

Consider the EMPLOYEES table and create a view for the 'RAMANDEEP'; she cannot access
the Salary of all the employees. Use the constraint 'WITH READ ONLY.

SQL> create view ramandeep as select eid, name from employees with read only;

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 28
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
After execution a view with the name 'ramandeep' will be created. In the view because we
use the option WITH READ ONLY so it restricts the DML operations to be executed.

 Modifying Views

 We can use the OR REPLACE option to modify the view. If the view exists it will be
replaced with the new definition or a new view will be created. We can use Create or
Replace option to create views instead of dropping the view and recreating it as with this
option the privileges granted on the view are preserved, but the dependent stored
programs and view become invalid.

 The view will become invalid whenever the base table is altered. Vie can recompile a view
using the Alter view statement, but oracle automatically recompiles the view once it is
accessed. On recompiling the dependent objects become invalid.

SQL> ALTER VIEW View Name;


Restrictions on DML Statements

 There are certain rules that have to be followed to perform the DML operations. They
are as under:

 We cannot insert the rows into view if the base table has certain columns with NOT
NULL constraint that does not appear in the view.

 If a view is defined by a query that contains SET or DISTINCT operators, a GROUP BY


clause, or a group function, then rows cannot be inserted into, updated in, or deleted
from the base tables using the view.

 If a view is defined with WITH CHECK OPTION, a row cannot be inserted into. or
updated in, the base table (using the view), if the view cannot select the row from the
base table.

 If view contains WITH READ ONLY Constraint then we cannot perform any DML
operations.

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 29
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
 Renaming Columns

Views can be used to rename the columns without effecting the base tables provided that
the number of columns in a view must match the number of columns specified in the select
statement.

Create a view RAMAN from the table employees with different column names,

SQL> CREATE OR REPLACE UIEW


RAMAN (ENO, ENAME) AS SELECT EID, NAME FROMEMPLOYEES;
View Created

After execution the view RAMAN will be created with the different column names.

 SQL JOIN
A JOIN clause is used to combine rows from two or more tables, based on a related column
between them.
A selection from the "Orders" table:

OrderID CustomerID OrderDate

10308 2 1996-09-18

10309 37 1996-09-19

10310 77 1996-09-20

Then, a selection from the "Customers" table:

CustomerID CustomerName ContactName Country

1 Alfreds Futterkiste Maria Anders Germany

Ana Trujillo Emparedados y


2 Ana Trujillo Mexico
helados

Antonio
3 Antonio Moreno Taquería Mexico
Moreno

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 30
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
Notice that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in
the "Customers" table. The relationship between the two tables above is the "CustomerID"
column.

Then, we can create the following SQL statement (that contains an INNER JOIN), that
selects records that have matching values in both tables:

Example

SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate


FROM Orders
INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;

And it will produce something like this:

OrderID CustomerName OrderDate

10308 Ana Trujillo Emparedados y helados 9/18/1996

10365 Antonio Moreno Taquería 11/27/1996

10383 Around the Horn 12/16/1996

10355 Around the Horn 11/15/1996

10278 Berglunds snabbköp 8/12/1996

 Different Types of SQL JOINs


Here are the different types of the JOINs in SQL:
 (INNER) JOIN: Returns records that have matching values in both tables
 LEFT (OUTER) JOIN: Return all records from the left table, and the matched
records from the right table
 RIGHT (OUTER) JOIN: Return all records from the right table, and the matched
records from the left table

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 31
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
 FULL (OUTER) JOIN: Return all records when there is a match in either left or
right table

 SQL INNER JOIN Keyword


 The INNER JOIN keyword selects records that have matching values in both tables.
 INNER JOIN Syntax

SELECT column_name(s) FROM table1


INNER JOIN table2 ON table1.column_name = table2.column_name;

A selection from the "Orders" table:

OrderID CustomerID EmployeeID OrderDate ShipperID

10308 2 7 1996-09-18 3

10309 37 3 1996-09-19 1

10310 77 8 1996-09-20 2

And a selection from the "Customers" table:

CustomerID CustomerName ContactName Address City PostalCode Country

1 Alfreds Maria Anders Obere Str. 57 Berlin 12209 Germany


Futterkiste

2 Ana Trujillo Ana Trujillo Avda. de la México 05021 Mexico


Emparedados y Constitución D.F.
helados 2222

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 32
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

3 Antonio Moreno Antonio Mataderos México 05023 Mexico


Taquería Moreno 2312 D.F.

SQL INNER JOIN Example


The following SQL statement selects all orders with customer information:
SELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;

Note: The INNER JOIN keyword selects all rows from both tables as long as there is a match
between the columns. If there are records in the "Orders" table that do not have matches in
"Customers", these orders will not be shown!

JOIN Three Tables

The following SQL statement selects all orders with customer and shipper information:

SELECT Orders.OrderID, Customers.CustomerName, Shippers.ShipperName


FROM ((Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID)
INNER JOIN Shippers ON Orders.ShipperID=Shippers.ShipperID);

 SQL LEFT JOIN Keyword


 The LEFT JOIN keyword returns all records from the left table (table1), and the matched
records from the right table (table2). The result is NULL from the right side, if there is no
match.
 LEFT JOIN Syntax
SELECT column_name(s) FROM table1
LEFT JOIN table2 ON table1.column_name = table2.column_name;
Note: In some databases LEFT JOIN is called LEFT OUTER JOIN.

A selection from the "Customers" table:

CustomerID CustomerName ContactName Address City PostalCode Country

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 33
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

1 Alfreds Maria Anders Obere Str. 57 Berlin 12209 Germany


Futterkiste

2 Ana Trujillo Ana Trujillo Avda. de la México 05021 Mexico


Emparedados y Constitución D.F.
helados 2222

3 Antonio Moreno Antonio Mataderos México 05023 Mexico


Taquería Moreno 2312 D.F.
And a selection from the "Orders" table:

OrderID CustomerID EmployeeID OrderDate ShipperID

10308 2 7 1996-09-18 3

10309 37 3 1996-09-19 1

10310 77 8 1996-09-20 2

SQL LEFT JOIN Example

The following SQL statement will select all customers, and any orders they might have:

SELECT Customers.CustomerName, Orders.OrderID


FROM Customers
LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CustomerName;

Note: The LEFT JOIN keyword returns all records from the left table (Customers), even if
there are no matches in the right table (Orders).

 SQL RIGHT JOIN Keyword


 The RIGHT JOIN keyword returns all records from the right table (table2), and the
matched records from the left table (table1). The result is NULL from the left side, when
there is no match.

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 34
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
 RIGHT JOIN Syntax
SELECT column_name(s) FROM table1
RIGHT JOIN table2 ON table1.column_name = table2.column_name;
Note: In some databases RIGHT JOIN is called RIGHT OUTER JOIN.

A selection from the "Orders" table:

OrderID CustomerID EmployeeID OrderDate ShipperID

10308 2 7 1996-09-18 3

10309 37 3 1996-09-19 1

10310 77 8 1996-09-20 2

And a selection from the "Employees" table:

EmployeeID LastName FirstName BirthDate Photo

1 Davolio Nancy 12/8/1968 EmpID1.pic

2 Fuller Andrew 2/19/1952 EmpID2.pic

3 Leverling Janet 8/30/1963 EmpID3.pic

SQL RIGHT JOIN Example

The following SQL statement will return all employees, and any orders they might have
placed:

SELECT Orders.OrderID, Employees.LastName, Employees.FirstName


FROM Orders
RIGHT JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID
ORDER BY Orders.OrderID;

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 35
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
Note: The RIGHT JOIN keyword returns all records from the right table (Employees), even
if there are no matches in the left table (Orders).

 SQL FULL OUTER JOIN Keyword


 The FULL OUTER JOIN keyword return all records when there is a match in either left
(table1) or right (table2) table records.
Note: FULL OUTER JOIN can potentially return very large result-sets!
 FULL OUTER JOIN Syntax

SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2 ON table1.column_name = table2.column_name;

A selection from the "Customers" table:

CustomerID CustomerName ContactName Address City PostalCode Country

1 Alfreds Futterkiste Maria Anders Obere Str. 57 Berlin 12209 Germany

2 Ana Trujillo Ana Trujillo Avda. de la México 05021 Mexico


Emparedados y Constitución D.F.
helados 2222

3 Antonio Moreno Antonio Mataderos México 05023 Mexico


Taquería Moreno 2312 D.F.

And a selection from the "Orders" table:

OrderID CustomerID EmployeeID OrderDate ShipperID

10308 2 7 1996-09-18 3

10309 37 3 1996-09-19 1

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 36
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

10310 77 8 1996-09-20 2

SQL FULL OUTER JOIN Example

The following SQL statement selects all customers, and all orders:

SELECT Customers.CustomerName, Orders.OrderID


FROM Customers
FULL OUTER JOIN Orders ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName;

A selection from the result set may look like this:

CustomerName OrderID

Alfreds Futterkiste

Ana Trujillo Emparedados y helados 10308

Antonio Moreno Taquería 10365

10382

10351

Note: The FULL OUTER JOIN keyword returns all the rows from the left table (Customers),
and all the rows from the right table (Orders). If there are rows in "Customers" that do not
have matches in "Orders", or if there are rows in "Orders" that do not have matches in
"Customers", those rows will be listed as well.
 SQL Self JOIN
 A self JOIN is a regular join, but the table is joined with itself.
 Self JOIN Syntax
SELECT column_name(s) FROM table1 T1, table1 T2 WHERE condition;
A selection from the "Customers" table:

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 37
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

CustomerID CustomerName ContactName Address City PostalCode Country

1 Alfreds Maria Anders Obere Str. 57 Berlin 12209 Germany


Futterkiste

2 Ana Trujillo Ana Trujillo Avda. de la México 05021 Mexico


Emparedados y Constitución D.F.
helados 2222

3 Antonio Moreno Antonio Mataderos México 05023 Mexico


Taquería Moreno 2312 D.F.

SQL Self JOIN Example

The following SQL statement matches customers that are from the same city:

SELECT A.CustomerName AS CustomerName1,


B.CustomerName AS CustomerName2, A.City
FROM Customers A, Customers B
WHERE A.CustomerID <> B.CustomerID
AND A.City = B.City
ORDER BY A.City;

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 38
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
Chapter 2 - Advanced SQL

 Sub queries and correlated queries

SQL Sub queries


 A sub query is a SQL statement that has another SQL query embedded in the WHERE or
the HAVING clause.
 A sub query is a SQL query within a query.
 Sub queries are nested queries that provide data to the enclosing query.
 Sub queries can return individual values or a list of records
 Sub queries must be enclosed with parenthesis

Syntax- The syntax for a sub query when the embedded SQL statement is part of
the WHERE condition is as follows:

SELECT "column_name1" FROM "table_name1"


WHERE "column_name2" [Comparison Operator]
(SELECT "column_name3" FROM "table_name2" WHERE "condition");

[Comparison Operator] could be equality operators such as =, >, <, >=, <=. It can also be a
text operator such as "LIKE".

We use the following tables for our examples.


Table Store_Information

Store_Name Sales Txn_Date


Los Angeles 1500 Jan-05-1999
San Diego 250 Jan-07-1999
Los Angeles 300 Jan-08-1999
Boston 700 Jan-08-1999
Table Geography

Region_Name Store_Name
East Boston
East New York

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 1
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

West Los Angeles


West San Diego

Example: Simple sub query- To use a sub query to find the sales of all stores in the West
region, we use the following SQL statement:
SELECT SUM (Sales) FROM Store_Information
WHERE Store_Name IN
(SELECT Store_Name FROM Geography
WHERE Region_Name = 'West');
Result:
SUM (Sales)
2050

 In this example, instead of joining the two tables directly and then adding up only the
sales amount for stores in the West region, we first use the sub query to find out which
stores are in the West region, and then we sum up the sales amount for these stores.
 In this example, the inner query and the outer query are independent of each other.
This type of sub query is called a simple sub query.
 Correlated queries
 In a SQL database query, a correlated sub query (also known as a synchronized sub
query) is a sub query (a query nested inside another query) that uses values from the
outer query. Because the sub query may be evaluated once for each row processed by
the outer query, it can be inefficient.
 Example : Correlated sub query
If the inner query is dependent on the outer query, we will have a correlated sub
query. An example of a correlated sub query is shown below:
SELECT SUM (a1.Sales) FROM Store_Information a1
WHERE a1.Store_Name IN
(SELECT Store_Name FROM Geography a2
WHERE a2.Store_Name = a1.Store_Name);

Result:

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 2
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

SUM (Sales)
2750
Here, the inner query is used to make sure that SQL only sums up sales amount from stores
that appear in both the Store_Information and the Geography tables.
The WHERE clause in the inner query, where the condition involves a table from the outer
query.

Difference between Sub query and Correlated sub query

Sub query – The inner query is executed only once. The inner query will get executed first
and the output of the inner query used by the outer query. The inner query is not
dependent on outer query.

Correlated sub query: – The outer query will get executed first and for every row of outer
query, inner query will get executed. So the inner query will get executed as many times as
number of rows in the result of the outer query. The outer query output can use the inner
query output for comparison. This means inner query and outer query dependent on each
other

What are SQL Functions?


SQL provides many built-in functions to perform operations on data. These functions are
useful while performing mathematical calculations, string concatenations, sub-strings etc.
SQL functions are divided into two categories,
1. Aggregate Functions
2. Scalar Functions
Aggregate Functions
These functions return a single value after performing calculations on a group of values.
Following are some of the frequently used Aggregate functions.

 AVG () Function
Average returns average value after calculating it from values in a numeric column.
Its general syntax is-- SELECT AVG(column_name) FROM table_name

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 3
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
Using AVG() function
Consider the following Emp table

eid name age salary

401 Anu 22 9000

402 Shane 29 8000

403 Rohan 34 6000

404 Scott 44 10000

405 Tiger 35 8000

SQL query to find average salary will be-- SELECT avg(salary) from Emp;
Result of the above query will be,

avg(salary)

8200

 COUNT() Function
Count returns the number of rows present in the table either based on some condition or
without condition.
Its general syntax is-- SELECT COUNT(column_name) FROM table-name;

Using COUNT() function

Consider the following Emp table

eid name age salary

401 Anu 22 9000

402 Shane 29 8000

403 Rohan 34 6000

404 Scott 44 10000

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 4
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

405 Tiger 35 8000

SQL query to count employees, satisfying specified condition is


SELECT COUNT(name) FROM Emp WHERE salary = 8000;

Result of the above query will be,

count(name)

Example of COUNT(distinct)
Consider the following Emp table

eid name age salary

401 Anu 22 9000

402 Shane 29 8000

403 Rohan 34 6000

404 Scott 44 10000

405 Tiger 35 8000

SQL query is, -- SELECT COUNT (DISTINCT salary) FROM emp;


Result of the above query will be,

count(distinct salary)

 FIRST() Function
First function returns first value of a selected column
Syntax for FIRST function is,--- SELECT FIRST(column_name) FROM table-name;

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 5
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
Using FIRST() function
Consider the following Emp table

eid name age salary

401 Anu 22 9000

402 Shane 29 8000

403 Rohan 34 6000

404 Scott 44 10000

405 Tiger 35 8000


SQL query will be, - SELECT FIRST(salary) FROM Emp;
and the result will be,

first(salary)

9000

 LAST() Function
LAST function returns the return last value of the selected column.
Syntax of LAST function is,-- SELECT LAST(column_name) FROM table-name;

Using LAST() function

Consider the following Emp table

eid name age salary

401 Anu 22 9000

402 Shane 29 8000

403 Rohan 34 6000

404 Scott 44 10000

405 Tiger 35 8000

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 6
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
SQL query will be,-- SELECT LAST(salary) FROM emp;
Result of the above query will be,

last(salary)

8000

 MAX() Function
MAX function returns maximum value from selected column of the table.
Syntax of MAX function is,-- SELECT MAX(column_name) from table-name;

Using MAX() function


Consider the following Emp table

eid name age salary

401 Anu 22 9000

402 Shane 29 8000

403 Rohan 34 6000

404 Scott 44 10000

405 Tiger 35 8000


SQL query to find the Maximum salary will be,-- SELECT MAX(salary) FROM emp;
Result of the above query will be,

MAX(salary)

10000

 MIN() Function
MIN function returns minimum value from a selected column of the table.
Syntax for MIN function is,-- SELECT MIN(column_name) from table-name;

Using MIN() function


Consider the following Emp table,

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 7
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

eid name age salary

401 Anu 22 9000

402 Shane 29 8000

403 Rohan 34 6000

404 Scott 44 10000

405 Tiger 35 8000


SQL query to find minimum salary is,-- SELECT MIN(salary) FROM emp;
Result will be,

MIN(salary)

6000

 SUM() Function
SUM function returns total sum of a selected columns numeric values.
Syntax for SUM is,-- SELECT SUM(column_name) from table-name;

Using SUM() function


Consider the following Emp table

eid name age salary

401 Anu 22 9000

402 Shane 29 8000

403 Rohan 34 6000

404 Scott 44 10000

405 Tiger 35 8000


SQL query to find sum of salaries will be,-- SELECT SUM(salary) FROM emp;
Result of above query is,

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 8
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

SUM(salary)

41000

Scalar Functions
Scalar functions return a single value from an input value. Following are some frequently
used Scalar Functions in SQL.

 UCASE() Function
UCASE function is used to convert value of string column to Uppercase characters.
Syntax of UCASE,-- SELECT UCASE(column_name) from table-name;

Using UCASE() function


Consider the following Emp table

eid name age salary

401 anu 22 9000

402 shane 29 8000

403 rohan 34 6000

404 scott 44 10000

405 Tiger 35 8000


SQL query for using UCASE is,-- SELECT UCASE(name) FROM emp;
Result is,

UCASE(name)

ANU

SHANE

ROHAN

SCOTT

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 9
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

TIGER

 LCASE() Function
LCASE function is used to convert value of string columns to Lowecase characters.
Syntax for LCASE is-- SELECT LCASE(column_name) FROM table-name;

Using LCASE() function


Consider the following Emp table

eid name age salary

401 Anu 22 9000

402 Shane 29 8000

403 Rohan 34 6000

404 SCOTT 44 10000

405 Tiger 35 8000


SQL query for converting string value to Lower case is,-- SELECT LCASE(name) FROM emp;
Result will be,

LCASE(name)

anu

shane

rohan

scott

tiger

 MID() Function
MID function is used to extract substrings from column values of string type in a table.
Syntax for MID function is,-- SELECT MID(column_name, start, length) from table-name;

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 10
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
Using MID() function
Consider the following Emp table

eid name age salary

401 anu 22 9000

402 shane 29 8000

403 rohan 34 6000

404 scott 44 10000

405 Tiger 35 8000


SQL query will be,-- SELECT MID(name,2,2) FROM emp;
Result will come out to be,

MID(name,2,2)

nu

ha

oh

co

ig

 ROUND() Function
ROUND function is used to round a numeric field to number of nearest integer. It is used on
Decimal point values.
Syntax of Round function is,- SELECT ROUND(column_name, decimals) from table-name;

Using ROUND() function


Consider the following Emp table

eid name age salary

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 11
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

401 anu 22 9000.67

402 shane 29 8000.98

403 rohan 34 6000.45

404 scott 44 10000

405 Tiger 35 8000.01


SQL query is,-- SELECT ROUND(salary) from emp;
Result will be,

ROUND(salary)

9001

8001

6000

10000

8000

 Procedural SQL
 PL/SQL is a combination of SQL along with the procedural features of programming
languages.
 PL/SQL is a block structured language that enables developers to combine the
power of SQL with procedural statements. All the statements of a block are passed
to oracle engine all at once which increases processing speed and decreases the
traffic.
Disadvantages of SQL:
 SQL doesn’t provide the programmers with a technique of condition checking,
looping and branching.
 SQL statements are passed to Oracle engine one at a time which increases traffic and
decreases speed.
VEENA R C, Assistant Professor
Dept., of CSE, GST Page 12
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
 SQL has no facility of error checking during manipulation of data.
Features of PL/SQL:
1. PL/SQL is basically a procedural language, which provides the functionality of
decision making, iteration and many more features of procedural programming
languages.
2. PL/SQL can execute a number of queries in one block using single command.
3. One can create a PL/SQL unit such as procedures, functions, packages, triggers, and
types, which are stored in the database for reuse by applications.
4. PL/SQL provides a feature to handle the exception which occurs in PL/SQL block
known as exception handling block.
5. Applications written in PL/SQL are portable to computer hardware or operating
system where Oracle is operational.
6. PL/SQL Offers extensive error checking.
Differences between SQL and PL/SQL:

SQL PL/SQL

PL/SQL is a block of codes that used to


SQL is a single query that is used to
write the entire program blocks/
perform DML and DDL operations.
procedure/ function, etc.

It is declarative, that defines what


PL/SQL is procedural that defines how
needs to be done, rather than how
the things needs to be done.
things need to be done.

Execute as a single statement. Execute as a whole block.

Mainly used to manipulate data. Mainly used to create an application.

It is an extension of SQL, so it can


Cannot contain PL/SQL code in it.
contain SQL inside it.

Structure of PL/SQL Block:


PL/SQL extends SQL by adding constructs found in procedural languages, resulting in a
structural language that is more powerful than SQL. The basic unit in PL/SQL is a block. All
PL/SQL programs are made up of blocks, which can be nested within each other.

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 13
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
Typically, each block performs a logical action in the program. A block has the following
structure:

DECLARE
Declaration statements;
BEGIN
Executable statements
EXCEPTIONS
Exception handling statements
END;
 Declare section starts with DECLARE keyword in which variables, constants,

records as cursors can be declared which stores data temporarily. It basically


consists definition of PL/SQL identifiers. This part of the code is optional.
 Execution section starts with BEGIN and ends with END keyword. This is a
mandatory section and here the program logic is written to perform any task like
loops and conditional statements. It supports all DML commands, DDL commands
and SQL*PLUS built-in functions as well.
 Exception section starts with EXCEPTION keyword. This section is optional which
contains statements that are executed when a run-time error occurs. Any exceptions
can be handled in this section.
 A subprogram is a program unit/module that performs a particular task. These
subprograms are combined to form larger programs. This is basically called the
'Modular design'. A subprogram can be invoked by another subprogram or program
which is called the calling program.
 A subprogram can be created −
o At the schema level
o Inside a package
o Inside a PL/SQL block
 At the schema level, subprogram is a standalone subprogram. It is created with
the CREATE PROCEDURE or the CREATE FUNCTION statement. It is stored in the

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 14
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
database and can be deleted with the DROP PROCEDURE or DROP FUNCTION
statement.
 A subprogram created inside a package is a packaged subprogram. It is stored in
the database and can be deleted only when the package is deleted with the DROP
PACKAGE statement.
 PL/SQL subprograms are named PL/SQL blocks that can be invoked with a set of
parameters. PL/SQL provides two kinds of subprograms −
Functions − these subprograms return a single value; mainly used to compute and
return a value.

Procedures − these subprograms do not return a value directly; mainly used to


perform an action.

Parts of a PL/SQL Subprogram

 Each PL/SQL subprogram has a name, and may also have a parameter list. Like
anonymous PL/SQL blocks, the named blocks will also have the following three
parts −

S.No Parts & Description

Declarative Part

It is an optional part. However, the declarative part for a subprogram does not start
1 with the DECLARE keyword. It contains declarations of types, cursors, constants,
variables, exceptions, and nested subprograms. These items are local to the
subprogram and cease to exist when the subprogram completes execution.

Executable Part
2
This is a mandatory part and contains statements that perform the designated action.

Exception-handling
3
This is again an optional part. It contains the code that handles run-time errors.

Creating a Procedure

A procedure is created with the CREATE OR REPLACE PROCEDURE statement. The


simplified syntax for the CREATE OR REPLACE PROCEDURE statement is as follows −

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 15
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
CREATE [OR REPLACE] PROCEDURE procedure_name [(parameter_name [IN | OUT | IN
OUT] type [, ...])]
{IS | AS}
BEGIN
< procedure_body >
END procedure_name;

Where,
o procedure-name specifies the name of the procedure.
o [OR REPLACE] option allows the modification of an existing procedure.
o The optional parameter list contains name, mode and types of the
parameters. IN represents the value that will be passed from outside and OUT
represents the parameter that will be used to return a value outside of the
procedure.
o procedure-body contains the executable part.

The AS keyword is used instead of the IS keyword for creating a standalone procedure.

Example- The following example creates a simple procedure that displays the string 'Hello
World!' on the screen when executed.

CREATE OR REPLACE PROCEDURE greetings


AS
BEGIN
dbms_output.put_line('Hello World!');
END;
When the above code is executed using the SQL prompt, it will produce the following result
Procedure created.

Executing a Standalone Procedure

A standalone procedure can be called in two ways −

 Using the EXECUTE keyword


 Calling the name of the procedure from a PL/SQL block
 The above procedure named 'greetings' can be called with the EXECUTE keyword as −

EXECUTE greetings;

The above call will display −

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 16
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
Hello World
PL/SQL procedure successfully completed.

 The procedure can also be called from another PL/SQL block −


BEGIN
greetings;
END;
/
The above call will display −
Hello World
PL/SQL procedure successfully completed.

Deleting a Standalone Procedure

A standalone procedure is deleted with the DROP PROCEDURE statement.

Syntax for deleting a procedure is − DROP PROCEDURE procedure-name;

We can drop the greetings procedure by using the following statement –


DROP PROCEDURE greetings;
Parameter Modes in PL/SQL Subprograms

The following table lists out the parameter modes in PL/SQL subprograms −

S.No Parameter Mode & Description

IN

An IN parameter lets you pass a value to the subprogram. It is a read-only


parameter. Inside the subprogram, an IN parameter acts like a constant. It
1 cannot be assigned a value. You can pass a constant, literal, initialized variable,
or expression as an IN parameter. You can also initialize it to a default value;
however, in that case, it is omitted from the subprogram call. It is the default
mode of parameter passing. Parameters are passed by reference.

OUT

An OUT parameter returns a value to the calling program. Inside the


2 subprogram, an OUT parameter acts like a variable. You can change its value
and reference the value after assigning it. The actual parameter must be
variable and it is passed by value.

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 17
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

IN OUT

An IN OUT parameter passes an initial value to a subprogram and returns an


updated value to the caller. It can be assigned a value and the value can be read.
3
The actual parameter corresponding to an IN OUT formal parameter must be a
variable, not a constant or an expression. Formal parameter must be assigned a
value. Actual parameter is passed by value.

IN & OUT Mode Example 1

This program finds the minimum of two values. Here, the procedure takes two numbers
using the IN mode and returns their minimum using the OUT parameters.

DECLARE
a number;
b number;
c number;
PROCEDURE findMin(x IN number, y IN number, z OUT number) IS
BEGIN
IF x < y THEN
z:= x;
ELSE
z:= y;
END IF;
END;
BEGIN
a:= 23;
b:= 45;
findMin(a, b, c);
dbms_output.put_line(' Minimum of (23, 45) : ' || c);
END;
/
When the above code is executed at the SQL prompt, it produces the following result −
Minimum of (23, 45) : 23

PL/SQL procedure successfully completed.

IN & OUT Mode Example 2

This procedure computes the square of value of a passed value. This example shows how
we can use the same parameter to accept a value and then return another result.

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 18
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
DECLARE
a number;
PROCEDURE squareNum(x IN OUT number) IS
BEGIN
x := x * x;
END;
BEGIN
a:= 23;
squareNum(a);
dbms_output.put_line(' Square of (23): ' || a);
END;
/
When the above code is executed at the SQL prompt, it produces the following result −
Square of (23): 529

PL/SQL procedure successfully completed.

 ODBC and JDBC


Definition of JDBC
 Java Database Connectivity (JDBC) is an application programming interface i.e.
(API). JDBC was released as a part of Java development Kit (JDK) 1.1 in the
year 1996 by SUN Microsoft. It is built the basis of ODBC and hence, some basics of
ODBC retain in JDBC.
 It is a standard interface between any Java application and different databases. The
function of JDBC is to help the Java-based application to access different types of
databases. JDBC provide methods to query database, and it can also be used to
update the database. JDBC provide JDBC drivers that converts the request from
Java application on client side to the language that database understands.
 As JDBC is language and platform specific, Java application can use JDBC-to-
ODBC Bridge to communicate with ODBC adaptable databases. Unlike ODBC, JDBC
has easy coding but, it is only limited to Java only.
Definition of ODBC
 ODBC is Open Database Connectivity. Like JDBC, ODBC is also an API that acts as
an interface between an application on the client side and the database on the
server side. Microsoft introduced ODBC in the year 1992.
VEENA R C, Assistant Professor
Dept., of CSE, GST Page 19
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
 ODBC helps an application to access the data from the database. An application
written in any language can use ODBC to access different types of databases and
hence, it is said to be language and platform independent. Like JDBC, ODBC also
provides ODBC drivers that convert the request of application written in any
language into the language understandable by databases.
 ODBC is most widely used and understands many different programming languages.
But its code is complex and hard to understand.

 Similarity: Both are used by the client-side applications to access different kinds of
databases on server side.

Difference between ODBC and JDBC

ODBC JDBC

JDBC Stands for java database


ODBC Stands for Open Database Connectivity.
connectivity.

Introduced by SUN Micro Systems in


Introduced by Microsoft in 1992.
1997.

We can use ODBC for any language like C,C++,Java We can use JDBC only for Java
etc. languages.

We can choose ODBC only windows platform. We can Use JDBC in any platform.

Mostly ODBC Driver developed in native languages JDBC Stands for java database
like C,C++. connectivity.

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 20
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

For Java applications it is not recommended to use For Java application it is highly
ODBC because performance will be down due to recommended to use JDBC because
internal conversion and applications will become there we no performance & platform
platform Dependent. dependent problem.

ODBC is procedural. JDBC is object oriented.

 HAVING Clause:
The HAVING Clause enables us to specify conditions that filter which group results appear
in the results.

The WHERE clause places conditions on the selected columns, whereas the HAVING clause
places conditions on groups created by the GROUP BY clause.
Syntax
The HAVING clause must follow the GROUP BY clause in a query and must also precedes
the ORDER BY clause if used. The following code block has the syntax of the SELECT
statement including the HAVING clause −
SELECT column1, column2 FROM table1, table2
WHERE [conditions] GROUP BY column1, column2
HAVING [conditions] ORDER BY column1, column2;

Example- Consider the CUSTOMERS table having the following records.


+----+----------+-----+-----------+----------+

| ID | NAME | AGE | ADDRESS | SALARY |


+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+

Following is an example, which would display a record for a similar age count that would
be more than or equal to 2.

SQL > SELECT ID, NAME, AGE, ADDRESS, SALARY FROM CUSTOMERS
GROUP BY age HAVING COUNT (age) >= 2;

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 21
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
This would produce the following result −

+----+--------+-----+---------+---------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+--------+-----+---------+---------+
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
+----+--------+-----+---------+---------+

 EXCEPT CLAUSE IN SQL


The SQL EXCEPT clause/operator is used to combine two SELECT statements and
returns rows from the first SELECT statement that are not returned by the second
SELECT statement. This means EXCEPT returns only rows, which are not available in the
second SELECT statement.

Just as with the UNION operator, the same rules apply when using the EXCEPT operator.
MySQL does not support the EXCEPT operator.

Syntax
SELECT column1 [, column2 ]
FROM table1 [, table2 ]
[WHERE condition]
EXCEPT
SELECT column1 [, column2 ]
FROM table1 [, table2 ]
[WHERE condition]
Here, the given condition could be any given expression based on our requirement.
Example
Consider the following two tables.
Table 1 − CUSTOMERS Table is as follows.
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+

Table 2 − ORDERS table is as follows.

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 22
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
+-----+---------------------+-------------+--------+
|OID | DATE | CUSTOMER_ID | AMOUNT |
+-----+---------------------+-------------+--------+
| 102 | 2009-10-08 00:00:00 | 3 | 3000 |
| 100 | 2009-10-08 00:00:00 | 3 | 1500 |
| 101 | 2009-11-20 00:00:00 | 2 | 1560 |
| 103 | 2008-05-20 00:00:00 | 4 | 2060 |
+-----+---------------------+-------------+--------+
Joining two tables in our SELECT statement as shown below.

SQL> SELECT ID, NAME, AMOUNT, DATE FROM CUSTOMERS


LEFT JOIN ORDERS ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID
EXCEPT
SELECT ID, NAME, AMOUNT, DATE FROM CUSTOMERS
RIGHT JOIN ORDERS ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID;
This would produce the following result.
+----+---------+--------+---------------------+
| ID | NAME | AMOUNT | DATE |
+----+---------+--------+---------------------+
| 1 | Ramesh | NULL | NULL |
| 5 | Hardik | NULL | NULL |
| 6 | Komal | NULL | NULL |
| 7 | Muffy | NULL | NULL |
+----+---------+--------+---------------------+

 EMBEDDED SQL IN DBMS

The structured query language provides us 2 features:

 It allows us to write queries.


 It allows us to use it in programming languages so that database can be accessed
through application programs also.
Due to this duality SQL is sometimes called dual mode language.
Actually all the queries can’t be expressed in SQL alone. There are many queries that are
expressed in programming languages like C, C++, Java but can’t be expressed in SQL. For
writing such queries we need to embed the SQL in general purpose programming
languages. The mixture of SQL and general purpose programming languages is called
embedded SQL.

There are some special embedded SQL statements which are used to retrieve the data into
the program. There is a special SQL precompiler that accepts the combined source code
with other programming tools and converts them into an executable program

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 23
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
Concepts for Embedding the SQL Statements

We can mix the SQL statements directly into general purpose programming language like C,
Java or Pascal. There are some techniques to embed SQL statements in the programming
languages.
1. The programming language in which the SQL statements are embedded is called the host
language. The SQL statements and host language statements make the source program
which is fed to a SQL precompiler for processing the SQL statements.
2. The host programming languages variables can be referenced in the embedded SQL
statements, which allows values calculated by the programs to be used by SQL
statements.
3. There are some special program variables which are used to assign null values to
database columns. These program variables support the retrieval of null values from the
database.

Embedded SQL Program Development


Since the embedded SQL is a mixture of SQL and programming language, so it cannot be fed
directly to a general purpose programming language compiler. Actually the program
execution is a multi-step which is as follows.
1. First, the embedded SQL source code is fed to the SQL precompiler. The precompiler
scans the program and processes the embedded SQL statements present in the code.
There can be different precompilers for different type of programming languages.
2. After processing the source code, the precompiler produces 2 files as its output. The
first file contains the source program without embedded SQL statements and the
second file contains all the embedded SQL statements used in the program.
3. The first file produced by precompiler (that contains the source program) is fed to
the compiler for the host programming language (like C compiler). The compiler
processes the source code and produces object code as its output.
4. Now the linker takes the object modules produced by the compiler and link them with
various library routines and produces an executable program.
5. The database request modules, produced by the precompiler (in steps) are submitted
to a special BIND program. The BIND program examines the SQL statements, parse
them, validates them, optimizes them and finally produces an application plan for each
statement. The result is a combined application plan for the entire program, that

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 24
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
represents a DBMS-executable version of its embedded SQL statements. The BIND
program stores the plan in the database, usually assigning it the name of the
application program that has created it.

An Embedded SQL Example in C


Although the SQL statements can be embedded in any general purpose programming
language, still we just take an example in C language so that a clear picture can be drawn.
We just take an interactive SQL statement and it can be embedded in C language.
Increase the salary of teacher by 10% who are B.Tech
update teacher set salary=1.1*salary where qualification=’B.Tech’;
The embedded SQL program for above written SQL statement will be:
main()
{
exec sql include sqlca;
exec sql declare table teacher (tid char(6) not null,tname char(20),sex char(1),
age number(3),qualification char(7),salary number(7),city varchar(15));
//Display a message to user
printf("updating teacher salary who are B.Techn");

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 25
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

//this code executes the SQL statement


exec sql update teacher set salary=1.1*salary where qualification='B.Tech';
printf(update done");
exit();
}

Explanation

1. The embedded SQL statement can be written in any case (lower or upper). Although
we should follow the convention of that programming language in which we are
embedding the SQL statements. For e.g., COBOL and FORTRAN are written in upper
case so, the SQL statements are also written in upper case, while in C, the SQL
statements are written in lower case as shown in above program.
2. Each embedded SQL statement begins with an introducer which indicates that it is a
SQL statement. For most of the programming language EXEC SQL is used as an
introducer.
3. Each embedded SQL statement ends with a terminator. There can be different
terminators for different programming languages. For example, there is END EXEC for
COBOL and a semicolon (;) for C.
4. The DECLARE TABLE statement is used to declare a table. With the use of DECLARE
TABLE statement our program specifies the column and data type explicitly.
5. When we type SQL statement, we may make an error. This error is displayed by the
interactive SQL program and we are prompted to type a new statement.
There can be two types of errors: compile time and runtime.

Error Handling with SQL Code


In this scheme the DBMS communicates the status to the embedded SQL program through
an area of program storage called the SQL communication are or SQLCA. The SQLCA is a
data structure that contains the error variables and the status indicators. By examining the
SQLCA, the application program can determine the success or failure of its embedded SQL
statements and can take actions accordingly.

 CURSORS
 A cursor is a temporary work area created in system memory when an SQL statement
is executed.
 A cursor is a set of rows together with a pointer that identifies a current row.

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 26
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
 It is a database object to retrieve data from a result set one row at a time. It is useful
when we want to manipulate the record of a table in a singleton method, in other
words one row at a time.
 In other words, a cursor can hold more than one row, but can process only one row at a
time. The set of rows the cursor holds is called the active set.
 Types of Cursors
There are the following two types of Cursors:
1. Implicit Cursor
2. Explicit Cursor
 Implicit Cursor- These types of cursors are generated and used by the system
during the manipulation of a DML query (INSERT, UPDATE and DELETE). An
implicit cursor is also generated by the system when a single row is selected by a
SELECT command.
 Explicit Cursor- This type of cursor is generated by the user using a SELECT
command. An explicit cursor contains more than one row, but only one row can
be processed at a time. An explicit cursor moves one by one over the records. An
explicit cursor uses a pointer that holds the record of a row. After fetching a row,
the cursor pointer moves to the next row.

Main components of Cursors


each cursor contains the followings 5 parts:

1. Declare Cursor: In this part we declare variables and return a set of values.
2. Open: This is the entering part of the cursor.
3. Fetch: Used to retrieve the data row by row from a cursor.
4. Close: This is an exit part of the cursor and used to close a cursor.
5. Deallocate: In this part we delete the cursor definition and release all the system
resources associated with the cursor.

Syntax of a Cursor

1. DECLARE @Variable nvarchar(50) /* Declare All Required Variables */


2. DECLARE Cursor_Name CURSOR /* Declare Cursor Name*/
3. [LOCAL | GLOBAL] /* Define Cursor Scope */
4. [FORWARD_ONLY | SCROLL] /* Define Movement Direction of Cursor */
5. [ KEYSET | DYNAMIC |STATIC | FAST_FORWARD] /* Define basic type of cursor *
/
6. [ SCROLL_LOCKS | OPTIMISTIC |READ_ONLY ] /* Define Locks */
7. OPEN Cursor_Name /* Open Cursor */
8. FETCH NEXT FROM Cursor_Name /* Fetch data From Cursor */
VEENA R C, Assistant Professor
Dept., of CSE, GST Page 27
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
9. Implement SQL QUery
10. CLOSE Cursor_Name /* Clsoe The Cursor */
11. DEALLOCATE Cursor_Name /* Deallocate all resources and Memory */

4 important terminologies of cursors.

Cursor Scope- Microsoft SQL Server supports the GLOBAL and LOCAL keywords on the
DECLARE CURSOR statement to define the scope of the cursor name.

1. GLOBAL: specifies that the cursor name is global to the connection.


2. LOCAL: specifies that the cursor name is local to the Stored Procedure, trigger or
query that holds the cursor.

Data Fetch Option in Cursors- Microsoft SQL Server supports the following two
fetch options for data:

1. FORWARD_ONLY: Specifies that the cursor can only be scrolled from the first to the
last row.
2. SCROLL: It provides 6 options to fetch the data (FIRST, LAST, PRIOR, NEXT,
RELATIVE and ABSOLUTE).

Types of cursors- Microsoft SQL Server supports the following 4 types of cursors.

1. STATIC CURSOR: A static cursor populates the result set during cursor creation and
the query result is cached for the lifetime of the cursor. A static cursor can move
forward and backward.
2. FAST_FORWARD: This is the default type of cursor. It is identical to the static
except that you can only scroll forward.
3. DYNAMIC: In a dynamic cursor, additions and deletions are visible for others in the
data source while the cursor is open.
4. KEYSET: This is similar to a dynamic cursor except we can't see records others add.
If another user deletes a record, it is inaccessible from our record set.

Types of Locks - Locking is the process by which a DBMS restricts access to a row in a
multi-user environment. When a row or column is exclusively locked, other users are not
permitted to access the locked data until the lock is released. It is used for data integrity.
This ensures that two users cannot simultaneously update the same column in a row.

Microsoft SQL Server supports the following three types of Locks.


1. READ ONLY: Specifies that the cursor cannot be updated.
VEENA R C, Assistant Professor
Dept., of CSE, GST Page 28
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
2. SCROLL_LOCKS: Provides data integrity into the cursor. It specifies that the cursor
will lock the rows as they are read into the cursor to ensure that updates or deletes
made using the cursor will succeed.
3. OPTIMISTIC: Specifies that the cursor does not lock rows as they are read into the
cursor. So, the updates or deletes made using the cursor will not succeed if the row
has been updated outside the cursor.

Example- Find the name and age of a sailor, specified by assigning a value to the host
variable c_sid

EXEC SQL SELECT S.sname, S.age


INTO :c_sname, :c_age
FROM Sailors S
WHERE S.sid = :c_sid;
The INTO clause allows us to assign the columns of the single answer row to the host
variables c_sname and c_age. Therefore, we do not need a cursor to embed this query in a
host language program. But what about the following query, which computes the names
and ages of all sailors with a rating greater than the current value of the host variable
c_minrating?

This query returns a collection of rows, not just one row. 'When executed interactively, the
answers are printed on the screen. If we embed this query in a C program by prefixing the
command with EXEC SQL, how can the answers be bound to host language variables? The
INTO clause is inadequate because we must deal with several rows. The solution is to use a
cursor:

DECLARE sinfo CURSOR FOR


SELECT S.sname, S.age
FROM Sailors S
WHERE S.rating > :c_minrating;

This code can be included in a C program, and once it is executed, the cursor sinfo is
defined. Subsequently, we can open the cursor:

OPEN sinfo:

The value of c_minrating in the SQL query associated with the cursor is the value of this
variable when we open the cursor. (The cursor declaration is processed at compile-time,
and the OPEN command is executed at run-time.)

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 29
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
A cursor can be thought of as 'pointing' to a row in the collection of answers to the query
associated with it. when a cursor is opened, it is positioned just before the first row. We can
use the FETCH command to read the first row of cursor sinfo into host language variables:

FETCH sinfo INTO :c_sname, :c_age;

When the FETCH statement is executed, the cursor is positioned to point at the next row
(which is the first row in the table when FETCH is executed for the first time after opening
the cursor) and the column values in the row are copied into the corresponding host
variables. By repeatedly executing this FETCH statement (say, in a while-loop in the C
program), we can read all the rows computed by the query, one row at a time. Additional
parameters to the FETCH command allow us to position a cursor in very flexible ways

When we are done with a cursor, we can close it:

CLOSE s_info;

It can be opened again if needed, and the value of : c_minrating in the SQL query associated
with the cursor would be the value of the host variable c_minrating at that time

Properties of Cursors
The general form of a cursor declaration is:
DECLARE cursorname [INSENSITIVE] [SCROLL] CURSOR
[WITH HOLD]
FOR some query
[ ORDER BY order-item-list ]
[ FOR READ ONLY I FOR UPDATE ]

A cursor can be declared to be a read-only cursor (FOR READ ONLY) or, if it is a cursor on a
base relation or an updatable view, to be an updatable cursor (FOR UPDATE). If it is
updatable, simple variants of the UPDATE and DELETE commands allow us to update or
delete the row on which the cursor is positioned. For example, if sinfo is an updatable
cursor and open, we can execute the following statement:

UPDATE Sailors S SET S.rating = S.rating 1 WHERE CURRENT of sinfo;

This Embedded SQL statement modifies the rating value of the row currently pointed to by
cursor sinfo; similarly, we can delete this row by executing the next statement:

DELETE Sailors S WHERE CURRENT of sinfo;

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 30
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
A cursor is updatable by default unless it is a scrollable or insensitive cursor (see below), in
which case it is read-only by default. If the keyword SCROLL is specified, the cursor is
scrollable, which means that variants of the FETCH command can be used to position the
cursor in very flexible ways; otherwise, only the basic FETCH command, which retrieves
the next row, is allowed. If the keyword INSENSITIVE is specified, the cursor behaves as if it
is ranging over a private copy of the collection of answer rows. Otherwise, and by default,
other actions of some transaction could modify these rows, creating unpredictable
behavior.

 TRIGGERS AND ACTIVE DATABASES & DESIGNING ACTIVE DATABASES


 A trigger is a procedure that is automatically invoked by the DBMS in response to
specified changes to the database, and is typically specified by the DBA.
 A database that has a set of associated triggers is called an active database.
 A trigger description contains three parts:
o Event: A change to the database that activates the trigger.
o Condition: A query or test that is run when the trigger is activated.
o Action: A procedure that is executed when the trigger is activated and its condition
is true.
 A trigger can be thought of as a 'daemon' that monitors a database, and is executed
when the database is modified in a way that matches the event specification.
 An insert, delete, or update statement could activate a trigger, regardless of which user
or application invoked the activating statement; users may not even be aware that a
trigger was executed as a side effect of their program
 A condition in a trigger can be a true/false statement (e.g., all employee salaries are less
than $100,000) or a query. A query is interpreted as true if the answer set is nonempty
and false if the query has no answers. If the condition part evaluates to true, the action
associated with the trigger is executed.
 A trigger action can examine the answers to the query in the condition part of the
trigger, refer to old and new values of tuples modified by the statement activating the
trigger, execute Hew queries, and make changes to the database.
 In fact, an action can even execute a series of data-definition commands (e.g., create
new tables, change authorizations) and transaction-oriented commands (e.g., commit)
or call host-language procedures.
 An important issue is when the action part of a trigger executes in relation to the
statement that activated the trigger.
 For example, a statement that inserts records into the Students table may activate a
trigger that is used to maintain statistics on how many students younger than 18 are
inserted at a time by a typical insert statement. Depending on exactly what the trigger
VEENA R C, Assistant Professor
Dept., of CSE, GST Page 31
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
does, we may want its action to execute before changes are made to the Students table
or afterwards:
 A trigger that initializes a variable used to count the number of qualifying insertions
should be executed before, and a trigger that executes once per qualifying inserted
record and increments the variable should be executed after each record is inserted
(because we may want to examine the values in the new record to determine the
action).
 Types of Triggers
o Row Triggers- A row trigger is fired each time the table is affected by the triggering
statement. If a triggering statement affects no rows, a row trigger is not executed at
all.
o Statement Triggers -A statement trigger is fired once on behalf of the triggering
statement, regardless of the number of rows in the table that the triggering
statement affects (even if no rows are affected)
 Trigger Timings
o Before Trigger-Execute the trigger action before the triggering statement.
Eliminate unnecessary processing of the triggering statement.
o After Trigger-AFTER triggers are used when you want the triggering statement to
complete before executing the trigger action

 Creating Triggers
The syntax for creating a trigger is −

CREATE [OR REPLACE ] TRIGGER trigger_name


{BEFORE | AFTER | INSTEAD OF }
{INSERT [OR] | UPDATE [OR] | DELETE}
[OF col_name]
ON table_name
[REFERENCING OLD AS o NEW AS n]
[FOR EACH ROW]
WHEN (condition)
DECLARE
Declaration-statements
BEGIN
Executable-statements
EXCEPTION
Exception-handling-statements
END;
Where,

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 32
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

 CREATE [OR REPLACE] TRIGGER trigger_name − Creates or replaces an existing


trigger with the trigger_name.

 {BEFORE | AFTER | INSTEAD OF} − This specifies when the trigger will be executed.
The INSTEAD OF clause is used for creating trigger on a view.

 {INSERT [OR] | UPDATE [OR] | DELETE} − This specifies the DML operation.

 [OF col_name] − This specifies the column name that will be updated.

 [ON table_name] − This specifies the name of the table associated with the trigger.

 [REFERENCING OLD AS o NEW AS n] − This allows you to refer new and old values
for various DML statements, such as INSERT, UPDATE, and DELETE.

 [FOR EACH ROW] − This specifies a row-level trigger, i.e., the trigger will be
executed for each row being affected. Otherwise the trigger will execute just once
when the SQL statement is executed, which is called a table level trigger.

 WHEN (condition) − This provides a condition for rows for which the trigger would
fire. This clause is valid only for row-level triggers.

Example
To start with, we will be using the CUSTOMERS table we had created and used in the
previous chapters −

Select * from customers;

+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
+----+----------+-----+-----------+----------+
The following program creates a row-level trigger for the customers table that would fire
for INSERT or UPDATE or DELETE operations performed on the CUSTOMERS table. This
trigger will display the salary difference between the old values and new values −

CREATE OR REPLACE TRIGGER display_salary_changes

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 33
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

BEFORE DELETE OR INSERT OR UPDATE ON customers


FOR EACH ROW
WHEN (NEW.ID > 0)
DECLARE
sal_diff number;
BEGIN
sal_diff := :NEW.salary - :OLD.salary;
dbms_output.put_line('Old salary: ' || :OLD.salary);
dbms_output.put_line('New salary: ' || :NEW.salary);
dbms_output.put_line('Salary difference: ' || sal_diff);
END;
/

When the above code is executed at the SQL prompt, it produces the following result −

Trigger created.
The following points need to be considered here −

 OLD and NEW references are not available for table-level triggers, rather you can
use them for record-level triggers.

 If you want to query the table in the same trigger, then you should use the AFTER
keyword, because triggers can query the table or change it again only after the
initial changes are applied and the table is back in a consistent state.

 The above trigger has been written in such a way that it will fire before any DELETE
or INSERT or UPDATE operation on the table, but you can write your trigger on a
single or multiple operations, for example BEFORE DELETE, which will fire
whenever a record will be deleted using the DELETE operation on the table.

Triggering a Trigger
Let us perform some DML operations on the CUSTOMERS table. Here is one INSERT
statement, which will create a new record in the table −

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)


VALUES (7, 'Kriti', 22, 'HP', 7500.00 );

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 34
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3

When a record is created in the CUSTOMERS table, the above create


trigger, display_salary_changes will be fired and it will display the following result −
Old salary:
New salary: 7500
Salary difference:
Because this is a new record, old salary is not available and the above result comes as null.
Let us now perform one more DML operation on the CUSTOMERS table. The UPDATE
statement will update an existing record in the table −

UPDATE customers
SET salary = salary + 500
WHERE id = 2;
When a record is updated in the CUSTOMERS table, the above create
trigger, display_salary_changes will be fired and it will display the following result −
Old salary: 1500
New salary: 2000
Salary difference: 500

 Constraints versus Triggers

Constraints Triggers
A constraint is an object the database
engine uses to constrain data in one An AFTER trigger is a special type of SQL code
table or a relationship of tables in order block that executes when a DML statement
to maintain database integrity. These is executed against the table the trigger is
constraints include CHECK, UNIQUE, defined on
PRIMARY KEY, etc.

Constraints are used to maintain the Triggers are basically stored procedures
integrity and atomicity of database .in which automatically fired when any insert
other words it can be said they are used ,update or delete is issued on table
to prevent invalid data entry.
The main 5 constraints are NOT
NULL,PRIMARY KEY,FOREIGN
KEY,UNIQUE KEY and CHECK.
trigger effected only those row after which
Constraint affected all row of table. trigger applied

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 35
GITAM University, Bangalore
SQL- Structured Query Language MODULE 3
Advantages of using SQL triggers

 SQL triggers provide an alternative way to check the integrity of data.


 SQL triggers can catch errors in business logic in the database layer.
 SQL triggers provide an alternative way to run scheduled tasks. By using SQL triggers,
you don’t have to wait to run the scheduled tasks because the triggers are invoked
automatically before or after a change is made to the data in the tables.
 SQL triggers are very useful to audit the changes of data in tables.
Disadvantages of using SQL triggers

 SQL triggers only can provide an extended validation and they cannot replace all the
validations. Some simple validations have to be done in the application layer. For
example, we can validate user’s inputs in the client side by using JavaScript or on the
server side using server-side scripting languages such as JSP, PHP, ASP.NET, and Perl.
 SQL triggers are invoked and executed invisible from the client applications;
therefore, it is difficult to figure out what happens in the database layer.
 SQL triggers may increase the overhead of the database server.

VEENA R C, Assistant Professor


Dept., of CSE, GST Page 36
GITAM University, Bangalore

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy