SQL is a database language used to define, manipulate, and retrieve data from databases. It allows for data definition, data manipulation, and view definition. Some key functions of SQL include creating and modifying tables, defining constraints such as primary keys and foreign keys, inserting, updating, and deleting data, and retrieving data using queries with features like WHERE clauses, ORDER BY, and JOINs. SQL follows ANSI and ISO standards.
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...Raj vardhan
The Relational Data Model and Relational Database Constraints
Ch5 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Example of STUDENT Relation(figure 5.1)
The proclaim of this topic is to remind the Loopback addresses in networking. This presentation update the knowledge of network users including to testing the standalone machine (i.e. End user machine) and Network Layer devices (Such as Router , Switches).
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...Raj vardhan
The Relational Data Model and Relational Database Constraints
Ch5 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Example of STUDENT Relation(figure 5.1)
The proclaim of this topic is to remind the Loopback addresses in networking. This presentation update the knowledge of network users including to testing the standalone machine (i.e. End user machine) and Network Layer devices (Such as Router , Switches).
Introduction to IoT (Basics of Networking & Emergence of IoT).pptxtaruian
Basics of Networking: Introduction, Network Types, Layered network models.
Emergence of IoT: Introduction, Evolution of IoT, Enabling IoT and the Complex Interdependence of Technologies, IoT Networking Components.
What is NFV? How does it relate to SDN, what does it mean for the telecommunications industry, and why should anyone outside of that industry care?
Presentation delivered at CloudOpen Europe, Düsseldorf, October 2014
Codd's Rules for Relational Database Management SystemsRajeev Srivastava
An introduction to Codd's 13 (12+1) rules defined by Dr. E.F. Codd for a True Relational Database Management Systems. ACID Properties of a Transaction.
Enumeration in Java Explained | Java Tutorial | EdurekaEdureka!
YouTube Link: https://youtu.be/LYRDMfJ9OwA
**Java, J2EE & SOA Certification Training - https://www.edureka.co/java-j2ee-trai... **
This Edureka video on Java Enum Tutorial will provide you with detailed knowledge about Enumeration in Java along with real times examples for better understanding. This informative video will include the following.
Agenda
What is Enum?
Why we need Enum?
Differences between Class and Enum
Syntax of Enum
Practical Examples of Enum
Advantages of using Enum
Enum Usecase: Rock Paper Scissor Game
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
this slide contains fundamental concept about VPLS protocol, according to the latest version of Cisco books and i taught it at IRAN TIC company.in the next slide, i upload attractive advanced feature about VPLS.
(Some of the pictures in this slide are borrowed from the wonderful site of my good friend Gokhan Kosem)
(www.ipcisco.com)
1) Configure a router to route between multiple directly connected networks
2) Describe the primary functions and features of a router.
3) Explain how routers use information in data packets to make forwarding decisions in a small- to medium-sized business network.
4) Explain the encapsulation and de-encapsulation process used by routers when switching packets between interfaces.
5) Compare ways in which a router builds a routing table when operating in a small- to medium-sized business network.
6) Explain routing table entries for directly connected networks.
7) Explain how a router builds a routing table of directly connected networks.
8) Explain how a router builds a routing table using static routes.
9) Explain how a router builds a routing table using a dynamic routing protocol.
This is the seventh set of slightly updated slides from a Perl programming course that I held some years ago.
I want to share it with everyone looking for intransitive Perl-knowledge.
A table of content for all presentations can be found at i-can.eu.
The source code for the examples and the presentations in ODP format are on https://github.com/kberov/PerlProgrammingCourse
Introduction to IoT (Basics of Networking & Emergence of IoT).pptxtaruian
Basics of Networking: Introduction, Network Types, Layered network models.
Emergence of IoT: Introduction, Evolution of IoT, Enabling IoT and the Complex Interdependence of Technologies, IoT Networking Components.
What is NFV? How does it relate to SDN, what does it mean for the telecommunications industry, and why should anyone outside of that industry care?
Presentation delivered at CloudOpen Europe, Düsseldorf, October 2014
Codd's Rules for Relational Database Management SystemsRajeev Srivastava
An introduction to Codd's 13 (12+1) rules defined by Dr. E.F. Codd for a True Relational Database Management Systems. ACID Properties of a Transaction.
Enumeration in Java Explained | Java Tutorial | EdurekaEdureka!
YouTube Link: https://youtu.be/LYRDMfJ9OwA
**Java, J2EE & SOA Certification Training - https://www.edureka.co/java-j2ee-trai... **
This Edureka video on Java Enum Tutorial will provide you with detailed knowledge about Enumeration in Java along with real times examples for better understanding. This informative video will include the following.
Agenda
What is Enum?
Why we need Enum?
Differences between Class and Enum
Syntax of Enum
Practical Examples of Enum
Advantages of using Enum
Enum Usecase: Rock Paper Scissor Game
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
this slide contains fundamental concept about VPLS protocol, according to the latest version of Cisco books and i taught it at IRAN TIC company.in the next slide, i upload attractive advanced feature about VPLS.
(Some of the pictures in this slide are borrowed from the wonderful site of my good friend Gokhan Kosem)
(www.ipcisco.com)
1) Configure a router to route between multiple directly connected networks
2) Describe the primary functions and features of a router.
3) Explain how routers use information in data packets to make forwarding decisions in a small- to medium-sized business network.
4) Explain the encapsulation and de-encapsulation process used by routers when switching packets between interfaces.
5) Compare ways in which a router builds a routing table when operating in a small- to medium-sized business network.
6) Explain routing table entries for directly connected networks.
7) Explain how a router builds a routing table of directly connected networks.
8) Explain how a router builds a routing table using static routes.
9) Explain how a router builds a routing table using a dynamic routing protocol.
This is the seventh set of slightly updated slides from a Perl programming course that I held some years ago.
I want to share it with everyone looking for intransitive Perl-knowledge.
A table of content for all presentations can be found at i-can.eu.
The source code for the examples and the presentations in ODP format are on https://github.com/kberov/PerlProgrammingCourse
Obtain better data accuracy using reference tablesKiran Venna
Data accuracy can be improved tremendously by using reference tables, especially when data is loaded from external files into target tables. Checking the data accuracy of source tables can be easily done with help of reference tables. By using SAS® macro,
data accuracy for many files can be performed with a single reference table. Step by step approach to build reference tables and a way to automate the data accuracy
checks will be discussed in this paper.
SQL (Structured Query Language) is a domain-specific language used for managing and manipulating relational databases. It serves as a standardized way to communicate with and interact with databases, enabling users to create, modify, retrieve, and manipulate data stored in structured tables.
Key points about SQL:
1. **Database Management**: SQL is used to manage databases, which are organized collections of structured data stored in tables with rows and columns.
2. **Data Manipulation**: SQL provides commands for querying, inserting, updating, and deleting data within databases. This allows users to extract specific information from large datasets.
3. **Data Definition**: SQL is also used to define the structure of the database, including creating tables, defining their attributes (columns), specifying data types, and setting constraints.
4. **Querying**: The core strength of SQL lies in its querying capabilities. Users can write complex queries to filter, sort, join, and aggregate data to generate meaningful insights.
5. **Relational Databases**: SQL is primarily associated with relational databases, where data is organized into tables with defined relationships between them. This ensures data integrity and reduces redundancy.
6. **Standardized Language**: SQL is an industry-standard language, supported by most relational database management systems (RDBMS), including MySQL, PostgreSQL, Microsoft SQL Server, Oracle, and SQLite.
7. **SQL Variants**: While the core syntax remains consistent across databases, different database systems might have slight variations and extensions in their SQL implementations.
8. **Data Integrity**: SQL allows the specification of various constraints, such as primary keys, foreign keys, and unique constraints, to maintain data integrity and enforce relationships between tables.
9. **Transactions**: SQL supports transaction management, allowing users to group multiple operations into a single transaction that can be rolled back if an error occurs.
10. **Administration**: Database administrators (DBAs) use SQL to manage database users, permissions, backups, and other administrative tasks.
11. **Non-Relational Databases**: While SQL is mainly associated with relational databases, there are also versions of SQL adapted for non-relational databases like NoSQL databases.
In summary, SQL is a powerful language used to interact with and manage structured data stored in databases. It's essential for tasks ranging from data retrieval to database design and administration.
Student information management system project report ii.pdfKamal Acharya
Our project explains about the student management. This project mainly explains the various actions related to student details. This project shows some ease in adding, editing and deleting the student details. It also provides a less time consuming process for viewing, adding, editing and deleting the marks of the students.
Immunizing Image Classifiers Against Localized Adversary Attacksgerogepatton
This paper addresses the vulnerability of deep learning models, particularly convolutional neural networks
(CNN)s, to adversarial attacks and presents a proactive training technique designed to counter them. We
introduce a novel volumization algorithm, which transforms 2D images into 3D volumetric representations.
When combined with 3D convolution and deep curriculum learning optimization (CLO), itsignificantly improves
the immunity of models against localized universal attacks by up to 40%. We evaluate our proposed approach
using contemporary CNN architectures and the modified Canadian Institute for Advanced Research (CIFAR-10
and CIFAR-100) and ImageNet Large Scale Visual Recognition Challenge (ILSVRC12) datasets, showcasing
accuracy improvements over previous techniques. The results indicate that the combination of the volumetric
input and curriculum learning holds significant promise for mitigating adversarial attacks without necessitating
adversary training.
Overview of the fundamental roles in Hydropower generation and the components involved in wider Electrical Engineering.
This paper presents the design and construction of hydroelectric dams from the hydrologist’s survey of the valley before construction, all aspects and involved disciplines, fluid dynamics, structural engineering, generation and mains frequency regulation to the very transmission of power through the network in the United Kingdom.
Author: Robbie Edward Sayers
Collaborators and co editors: Charlie Sims and Connor Healey.
(C) 2024 Robbie E. Sayers
Cosmetic shop management system project report.pdfKamal Acharya
Buying new cosmetic products is difficult. It can even be scary for those who have sensitive skin and are prone to skin trouble. The information needed to alleviate this problem is on the back of each product, but it's thought to interpret those ingredient lists unless you have a background in chemistry.
Instead of buying and hoping for the best, we can use data science to help us predict which products may be good fits for us. It includes various function programs to do the above mentioned tasks.
Data file handling has been effectively used in the program.
The automated cosmetic shop management system should deal with the automation of general workflow and administration process of the shop. The main processes of the system focus on customer's request where the system is able to search the most appropriate products and deliver it to the customers. It should help the employees to quickly identify the list of cosmetic product that have reached the minimum quantity and also keep a track of expired date for each cosmetic product. It should help the employees to find the rack number in which the product is placed.It is also Faster and more efficient way.
Final project report on grocery store management system..pdfKamal Acharya
In today’s fast-changing business environment, it’s extremely important to be able to respond to client needs in the most effective and timely manner. If your customers wish to see your business online and have instant access to your products or services.
Online Grocery Store is an e-commerce website, which retails various grocery products. This project allows viewing various products available enables registered users to purchase desired products instantly using Paytm, UPI payment processor (Instant Pay) and also can place order by using Cash on Delivery (Pay Later) option. This project provides an easy access to Administrators and Managers to view orders placed using Pay Later and Instant Pay options.
In order to develop an e-commerce website, a number of Technologies must be studied and understood. These include multi-tiered architecture, server and client-side scripting techniques, implementation technologies, programming language (such as PHP, HTML, CSS, JavaScript) and MySQL relational databases. This is a project with the objective to develop a basic website where a consumer is provided with a shopping cart website and also to know about the technologies used to develop such a website.
This document will discuss each of the underlying technologies to create and implement an e- commerce website.
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Dr.Costas Sachpazis
Terzaghi's soil bearing capacity theory, developed by Karl Terzaghi, is a fundamental principle in geotechnical engineering used to determine the bearing capacity of shallow foundations. This theory provides a method to calculate the ultimate bearing capacity of soil, which is the maximum load per unit area that the soil can support without undergoing shear failure. The Calculation HTML Code included.
About
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
• Remote control: Parallel or serial interface.
• Compatible with MAFI CCR system.
• Compatible with IDM8000 CCR.
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
• Easy in configuration using DIP switches.
Technical Specifications
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
Key Features
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
• Remote control: Parallel or serial interface
• Compatible with MAFI CCR system
• Copatiable with IDM8000 CCR
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
Application
• Remote control: Parallel or serial interface.
• Compatible with MAFI CCR system.
• Compatible with IDM8000 CCR.
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
• Easy in configuration using DIP switches.
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
ALL BASIC SQL SERVER QUERY
1. 1
SQL (Structured Query Language)
SQL is a database language.
It is a comprehensive database language that
facilitates data definition, data manipulation &
view definition.
SQL follows ANSI & ISO standard.
2. 2
We will refer to this
schema in our
discussion on SQL.
Company database schema
9. 9
Defining foreign key on a table
alter table employee add foreign
key(dno) references
department(dnumber);
alter table employee add foreign
key(super_ssn) references
employee(ssn);
10. 10
You may assign name to a constraint
alter table employee add constraint
empfk1 foreign key(super_ssn)
references employee(ssn);
alter table employee add constraint
empfk2 foreign key(dno) references
department(dnumber);
11. 11
Defining primary key and secondary key
on table
alter table employee add primary key(ssn);
alter table department add primary
key(dnumber);
alter table department add unique(dname);
alter table works_on add primary key(essn, pno);
12. 12
Assigning name to a constraint
alter table employee add constraint emp_pk
primary key(ssn);
alter table department add constraint dept_pk
primary key(dnumber);
alter table works_on add constraint works_on_pk
primary key(essn, pno);
alter table department add constraint dept_sk
unique(dname);
14. 14
Disabling & enabling constraint
alter table employee disable constraint empfk2;
alter table employee enable constraint empfk2;
15. 15
Adding new column to a table
alter table employee
add email varchar2(20);
alter table employee
add email varchar2(20) not null;
alter table employee
add mobile char(10) not null;
16. 16
Adding new columns to a table
alter table employee add
(email varchar2(20), mobile char(10));
alter table employee add
(email varchar2(20) not null,
mobile char(10));
17. 17
Removing columns from a table
alter table employee drop column minit;
alter table employee drop (mobile, email);
18. 18
Modifying column
alter table employee
modify address varchar2(40);
alter table employee
modify address varchar2(40) not null;
20. 20
Making column value mandatory
To make a column value mandatory qualify its
definition with
not null.
Examples:
alter table employee modify super_ssn not null;
alter table employee modify dno not null;
21. 21
Defining default value
To assign a default value to a column
you need to use the keyword default.
Examples:
alter table employee modify
dno default 1;
alter table employee modify
super_ssn default ‘888445555’;
22. 22
Defining default value & making column value
mandatory
Examples:
alter table employee modify
super_ssn default ‘888445555’ not null;
alter table employee modify
dno default 1 not null;
If fname column of employee table is already declared
as not null. To declare it as null use:
alter table employee modify fname null;
23. 23
Altering default value &
Removing default value
Altering default value
alter table employee modify dno default 4;
Removing default value
alter table employee modify dno default null;
New value of default
24. 24
Declaring default in table definition
create table employee (
Fname varchar2(15) not null,
Minit char(1),
Lname varchar2(15) not null,
Ssn char(9) not null,
Bdate date
Address varchar2(30),
Gender char(1),
Salary number(10,2),
Super_ssn char(9),
Dno number(1) default 1 not null,
constraint emppk primary key(ssn),
constraint empfk1 foreign key(super_ssn) references
employee(ssn),
constraint empfk2 foreign key(dno) references
department(dnumber) );
25. 25
Declaring check constraint in table definition
create table employee (
Fname varchar2(15) not null,
Minit char(1),
Lname varchar2(15) not null,
Ssn char(9), not null,
Bdate date
Address varchar2(30),
Gender char(1),
Salary number(10,2),
Super_ssn char(9),
Dno number(1) default 1 not null,
constraint emppk primary key(ssn),
constraint empfk1 foreign key(super_ssn) references employee(ssn),
constraint empfk2 foreign key(dno) references department(dnumber),
check (gender = 'F' or gender = 'M'),
check (salary > 50000));
26. 26
Declaring check constraint in table definition
create table department (
dnumber number(1) not null
check (dnumber > 0 and dnumber < 6),
…
);
create table department (
dnumber number(1) not null
check (dnumber in (1, 5, 4)),
…
);
27. 27
Declaring check constraint in table definition
create table dependent (
essn char(9) not null,
dname varchar2(12) not null,
gender char(1),
relationship varchar2(8)
check (relationship in (‘spouse’, ‘son’, ‘daughter’,
‘parent’)),
…);
29. 30
Adding check constraint to existing table
alter table employee add
check (gender = ‘F’ or gender = ‘M’);
alter table employee add constraint emp_gender
check (gender = ‘F’ or gender ‘M’);
alter table employee add check
(salary > 25000 and salary <= 140000);
A check constraint allows you to restrict value of a column.
30. 31
Changing table name
alter table employee rename to employee1;
alter table <old_table_name> rename to
<new_table_name>
31. 32
Changing column name
alter table project rename column dnum to dno;
alter table dependent rename column essn to ssn;
alter table works_on rename column essn to ssn;
33. 34
Data entry (insert statement)
insert into employee values (
‘Richard’, ‘K’, ‘Marini’,
‘653653653’, ’30-dec-1982’, ’98 Oak Forest, Katy, TX’, ‘M’,
37000, ‘888665555’, 4 );
insert into employee (
fname, mint, lname, ssn, bdate, address, gender, salary,
super_ssn, dno)
values (
‘Richard’, ‘K’, ‘Marini’, ‘653653653’, ’30-dec-1982’,
’98 Oak Forest, Katy, TX’,‘M’, 37000, ‘888665555’, 4 );
Mentioning column name here is not mandatory.
34. 35
Data entry (insert statement)
insert into employee (
ssn, fname, mint, lname, bdate, address, gender, salary,
super_ssn, dno)
values
(‘653653653’, ‘Richard’, ‘K’, ‘Marini’, ’30-dec-1982’,
’98 Oak Forest, Katy, TX’,‘M’, 37000, ‘888665555’, 4 );
Entering data into selective column
insert into employee (
fname, lname, ssn, super_ssn, dno)
values (
‘Richard’, ‘Marini’, ‘653653653’, ‘888665555’, 4 );
35. 36
Column that may be left out
null column may be left out.
column with default (but not declared as not
null) may be left out.
not null column without default must be
mentioned.
36. 37
Failure of insert statement
Insert statement fails if one of the following
constraints is violated
Domain constraint
Entity integrity constraint
Key constraint
Referential integrity constraint
37. 38
Failure of insert statement
Domain of a column is the set of all possible values that the
column can assume. While entering data domain
constraint is said to have been violated if an attempt is
made to assign value to a column outside its domain. In this
case the DBMS restricts the data entry and the insert
statement fails.
Entity integrity constraint (EIC) states that primary key
value cannot be null.
Any attempt to leave out the value in the primary key
column (s) results in violation of EIC and in case of such
violation DBMS restricts data entry and the insert statement
fails.
38. 39
Failure of insert statement
Key constraint states that key value across rows
of a table cannot have duplicate (e.g. you cannot
enter duplicate values in the ssn column of
department table). Any attempt to enter duplicate
value in key (primary / secondary) is restricted by
DBMS and data entry fails.
Referential integrity constraint (RIC) states that a
row can refer to an existing row only. RIC is
specified using foreign key. Insert statement fails
if RIC is violated.
39. 40
Changing existing data (update statement)
update employee set salary = 65000
where ssn = ‘888665555’;
update employee set salary = salary + 5000
where dno = 5;
update employee set dno = 5, salary = salary*1.2
where dno = 4;
update employee set salary = null
where ssn = ‘123456789’;
40. 41
Update statement
update employee set dno = default
where ssn = ‘123456789’;
update employee set
salary = null, dno = default
where ssn = ‘123456789’;
41. 42
Update statement can update only one
table
An update statement can update only one table.
One update statement cannot update multiple tables
together.
An update statement cannot update dnumber column of
department and dno column of employee together.
Syntax of update statement
update <table_name>
set <column_name> = <expression>
[,<column_name = <expression>]
[where <condition>]
42. 43
Failure of update statement
Update statement fails if one of the following
constraints is violated
Domain constraint
Entity integrity constraint
Key constraint
Referential integrity constraint
43. Referential integrity
constraint is violated
whenever an attempt is
made to delete a row
from department table or
update Dnumber column
to any value other than
1, 5, 4.
44. 45
Failure of update statement
To avoid violation of referential integrity
constraint, when you define foreign key in the
Employee table do one of the following.
alter table employee add foreign key(dno)
references Department(dnumber) on update
cascade
alter table employee add foreign key(dno)
references Department(dnumber) on update
set null
alter table employee add foreign key(dno)
references Department(dnumber) on update
set default
45. Removing rows from table (delete
statement)
delete from employee where ssn = ‘888665555’;
delete from employee where salary > 30000;
delete from employee where salary > 30000 and dno = 4;
delete from employee where salary between 30000 and
40000;
delete from employee;
One delete command can delete data from one table only.
46
46. 47
Failure of delete statement
Delete statement fails if Referential integrity
constraint is violated. To resolve this
problem you do one of the following:
alter table Employee add foreign key(dno)
references Department(dnumber) on delete
cascade
alter table Employee add foreign key(dno)
references Department(dnumber) on delete set
null
alter table Employee add foreign key(dno)
references Department(dnumber) on delete set
default
47. 48
You may combine actions on update with
delete
alter table Employee add foreign key(dno)
references Department(dnumber) on delete
cascade on update cascade
And the likes
48. 49
Select statement (Retrieving data from database)
• Retrieves data from database
• Can only read database, cannot modify it
Examples of data retrieval
Reading balance in bank account
Viewing term end results
Viewing attendance status
Looking for availability of rail/flight ticket
Browsing through www.flipcart.com to find out the
available books on database systems
50. 51
Select statement (Retrieving data)
Retrieve all information of all projects.
select * from project;
Retrieve name of all projects and its location.
select pname, plocation from project;
51. 52
Select statement
Find out the name of the employees, their address
and salary.
select fname, minit, lname, address, salary
from employee;
52. 53
Select statement (WHERE clause)
Find out the last name & first name of the
employees with salary higher than $40000.
select lname, fname
from employee
where salary > 40000;
53. 54
WHERE clause
select lname, fname from employee
where salary >= 30000 and salary <= 55000;
select lname, fname from employee
where salary between 30000 and 55000;
<> or != Not equal to
Find out the birth date and address of the employee (s)
whose name is John B. Smith.
Select bdate, address from employee
where fname = ‘John’ and minit = ‘B’ and lname = ‘Smith’
Output of a query is displayed as a table.
54. 55
Substring pattern matching
using % (zero or more character) in WHERE
clause
Retrieve name of employees whose last name
starts with an S.
select fname, minit, lname from employee
where lname like ‘S%’; (% zero or more characters)
Retrieve lname & fname of employees who live in
Texas.
select lname, fname from employee
where address like ‘%TX%’;
55. 56
Using _ (exactly one character)
Retrieve first name and last name of employees whose first
name has an o as the second character.
select fname, lname from employee where fname like ‘_o%’;
( _ exactly one character)
Retrieve the first name and last name of employees whose
last name has an e as the fourth character.
select fname, lname from employee where lname like
‘___e%’;
56. 57
What if the string contains _ or % ?
Find out first name and last name of employees
with _ as one of the characters in their email
address.
select fname, lname from employee where email
like ‘%_%’ escape ‘’;
57. 58
What if the string contains _ or % ?
Find out first name and last name of employees
with % as one of the characters in their email
address.
select fname, lname from employee
where email like ‘%%%’ escape ‘’;
Any character that has not been used in the string
may be used as escape character.
58. 59
is null & is not null
(Testing presence of data in a column)
Tell me the name of the employee who do not have a
supervisor.
select fname, minit, lname from employee where super_ssn
is null;
Tell me the name of the employees who do not have email
address.
select fname, lname from employee where email is null;
59. 60
is null & is not null
Tell me the name of the employees who have
email address but did not provide their mobile
number.
select fname, lname from employee
where email is not null and mobile is null;
60. 61
Eliminating duplicate rows from the output of a
query
Output of a select statement is a table.
To eliminate duplicate rows
use distinct clause.
Show me the distinct salary values.
select distinct salary from employee;
Show me the supervisor`s ssn only.
select distinct super_ssn from employee;
Null is treated as different from any other values.
61. 62
Arithmetic operators in query
What would be the salary of the employees if they
get a hike of 10%?
select 1.1*salary from employee;
62. 63
ORDER BY clause
Sorts output of select statement. Default order ascending
select fname, lname, salary from employee order by salary;
select fname, lname from employee order by salary desc;
select fname, lname, salary from employee
order by fname, salary desc;
select fname, lname from employee
order by fname, lname, salary;
63. 64
ORDER BY with WHERE clause
select fname, lname, salary
from employee
where salary < 60000
order by salary desc;
64. 65
Aggregate functions
sum, avg, max, min, count are SQL aggregate
functions
Aggregate functions compute summary of data.
sum (column header) computes total value in this
column.
You may also use distinct keyword before
column header.
65. Aggregate functions
Similarly, avg, max, min
computes the arithmetic mean, maximum and
minimum respectively of a column.
The count function computes number of values
present in the column.
In all these functions the column header can be
preceded by keyword distinct.
66
66. 67
Aggregate functions
Sum and avg function can be applied on numeric
data only,
but count, max and min can be applied on
numeric as well as alphanumeric data.
67. 68
Aggregate functions
Examples:
select sum(salary) from employee;
select avg(salary) from employee;
select sum(salary), avg(salary), max(salary),
min(salary), count(*) from employee;
Find out the number of supervisors in the
company.
68. 69
Group by clause
Group by clause is used when you want to apply
aggregate function on groups of rows in a table. In these
cases we need to partition the relation into non
overlapping groups of rows. Each group (also called
partition) will consist of the rows that have the same
value of some column (s), called the grouping column
(s). We can then apply the function to each such group
independently to produce summary information about
each group.
If null value exists in the grouping column, then a
separate group is created for all rows with a null value in
the grouping column.
69. 70
GROUP BY clause
Tell me the average salary of each department and the
number employees who work in the department.
71. 72
Using GROUP BY clause
Tell me the number of projects each employee
works on.
Select count(pno) from works_on group by essn;
Tell me the number of employees working in each
project.
Select count(essn) from works_on group by pno;
72. 73
HAVING clause in select statement
HAVING <condition>
condition should be on an aggregate function and (or)
grouping column.
having avg(salary) > 30000;
having salary > 30000; (incorrect)
HAVING clause operates on summery data & grouping
column (s).
73. 74
HAVING with GROUP BY clause
Tell me those departments that have average salary of
employees higher than $40000;
Select dno from employee group by dno having avg(salary)
> 40000
Give me those project numbers that involve at least three
employees.
Select pno from works_on group by pno having count(essn)
>= 3;
74. 75
Format of select statement
SELECT <list of columns, summary data>
FROM <list of tables>
WHERE <condition>
GROUP BY <list of columns>
HAVING <condition on summary data, grouping column>
ORDER BY <list of columns, summary data>
75. 76
Joining tables - Multiple tables in select statement
Tell me the name of project & the name of
controlling department.
76. 77
Joining tables
Consider two tables namely,
PROJECT and DEPARTMENT.
Now concatenate each row of
PROJECT table with each row of
DEPARTMENT table and by this
process you get join of two tables.
The output of this join is shown
in the next slide, along with the
query that produces this output.
77. Output of
select * from project, department;
There are some rows that are invalid e.g. the second row which gives two different
values of department number for the project ProductX, but a project is under the
control of a single department. To avoid this, use join condition (Fkey = Pkey)
78. 79
Joining tables - Multiple tables in select statement
Retrieve the name of project and name of controlling
department.
select pname, dname from project , department
where dnum = dnumber;
Retrieve the name of employee and name of department
he/she works.
select fname, minit, lname, dname
from employee, department where dno = dnumber;
The above SQL statement may also be written as:
select fname, minit, lname, dname from
employee join department on dno = dnumber;
79. 80
Joining tables - Multiple tables in select statement
Find out first name, last name and address of all employees
who work in administration department.
select fname, lname, address from employee, department
where dno = dnumber and dname = ‘Administration’;
select fname, lname, address from employee join
department on dno = dnumber and dname =
‘Administration’;
80. 81
Join
Retrieve name of project and name of controlling
department
select pname, dname from project, department
where dnum = dnumber;
81. 82
Join
Tell me the first name, last name and address of
employees who work in administration
department
select fname, lname, address from employee,
department where dno = dnumber and dname
= ‘Administration’;
82. 83
Natural join
If name of the foreign key is the same as that of
primary key you may use natural join as
illustrated in the following example.
Find out name of department name and its
location.
Select dname, dlocation from department
natural join dept_locations
83. 84
Join
Tell me the first name and last name of employees and the
project number they are involved in.
select fname, lname, pno from employee, works_on where
essn = ssn;
Tell me the first name and last name of employees and the
name of the project (s) they are involved in.
select fname, lname, pno from employee, works_on, project
where essn = ssn and pno = pnumber;
84. 85
Join
For every project located in ‘Stafford’, list project number,
controlling department number and the department
manager’s last name.
For the SQL query see the next slide.
85. 86
Query
select pnumber, dnum, lname
from project, department, employee
where dnum = dnumber and mgr_ssn = ssn
and plocation = ‘Stafford’;
select pnumber, dnum, lname
from ((project join department on dnum = dnumber) join
employee on mgr_ssn = ssn)) where plocation = ‘Stafford’;
select pnumber, dnum, lname
from project natural join department natural join employee
where plocation = ‘Stafford’;
86. 87
Self join
For each employee, retrieve the employee’s first and the
first name of his or her immediate supervisor.
select e.fname, s.fname
from employee e, employee s
where e.super_ssn = s.ssn;
87. 88
Set theoretic operations
union, intersect, minus.
You may combine the output of two or more queries using
these set operations provided that the query outputs have
the same schema.
e.g.
Find out name of employees who do not have dependent.
(select fname, minit, lname from employee)
minus
(select fname, minit, lname
from employee, dependent where essn = ssn);
88. 89
Set theoretic operations
Find out project number where Franklin Wong
works either as a manager or as a worker.
(Select pnumber from employee, department,
project where mgr_ssn = ssn and
dnum = dnumber and fname = ‘Franklin’
and lname = ‘Wong’)
union
(Select pno from employee, works_on
where essn = ssn and fname = ‘Franklin’
and lname = ‘Wong’)
89. 90
Union all, intersect all, minus all
Union, intersect and minus eliminates duplicates
(if any) before displaying the results of the query.
If you need to retain duplicates then use union all,
intersect all and minus all.
90. 91
Nested queries
If there is a query inside another query then
the SQL statement is called a nested query.
You may have any number of levels of nesting.
The general look of nested query is
Outer query (inner query);
Outer query (inner query1 (inner query2));
In the following nested query is illustrated with
examples.
91. 92
Nested queries
Find out name of the department where John
Smith works.
select dname from department where dnumber =
(select dno from employee where fname =
‘John’ and lname = ‘Smith’)
92. 93
Nested queries
Retrieve the department name where last
name of persons working in the department
starts with an S.
select dname from department
where dnumber in (select dno from employee
where lname like ‘S%’ );
Find out the name of the employee who draws
the highest salary.
select fname, minit, lname from employee where
salary = (select max(salary) from employee)
93. 94
Nested queries
Retrieve the ssn of employees who work on the
same project as Smith does.
select distinct essn from works_on where pno in
(select pno from works_on where essn =
(select ssn from employee where lname
=‘Smith’));
94. 95
Uncorrelated & Correlated nested query
When an inner query does not access the columns
of the table used in outer query then the nested
query is called uncorrelated nested query.
But when an inner query accesses the columns of
the table used in outer query then the nested
query is called correlated nested query.
Nested queries that you have seen so far are
uncorrelated nested query.
95. 96
Correlated nested query
Retrieve the name of employees whose dependent
has the same name as the last name of the
employee.
select fname, lname from employee where
ssn in (select essn from dependent where
dependent_name = lname);
96. 97
Correlated nested query
Retrieve the last name of employees who has a
dependent with the same gender as that of the
employee.
select e.lname from employee e where e.ssn in
(select essn from dependent
where e.gender = gender);
97. 98
Correlated nested query
Retrieve the names of all employees who have
two or more dependents.
select lname, fname from employee
where (select count(*) from dependent
where essn = ssn) >= 2;
N.B. The outer query is colored.
98. 99
exists & not exists function
exists and not exists functions are used in relation
to nested query.
Usage:
(outer query) where exists (inner query);
(outer query) where not exists (inner query);
99. 100
exists & not exists function
not exists (inner query)
returns true if inner query does not return
result, otherwise it returns false.
exists (inner query)
returns true if inner query returns one or more
rows, otherwise it returns false.
100. 101
not exists function - example
Retrieve the name of employees who do not have
dependent.
select fname, lname from employee
where not exists (select * from dependent where
ssn = essn);
101. 102
exists function - example
Retrieve the name of employees who have at
least one dependent.
select fname, lname from employee
where exists (select * from dependent
where ssn = essn);
102. 103
Correlated vs. uncorrelated nested queries
In case of correlated nested query, the inner is
executed once for every row of the table in the
outer query whereas, in case of uncorrelated
nested query, the inner query is executed only
once, and the output of the inner query is used to
evaluate outer query.
How many times does the inner query execute in
correlated nested query?
How many times does the inner query execute in
uncorrelated nested query?
103. 104
Outer join
• Left outer join
• Right outer join
• Full outer join
Left outer join produces data from matching rows (for which
foreign key = primary key) from the participating tables and
data from non-matching rows from the left table. Right outer
join behaves in a similar way. The full outer join is the union
of left outer join and right outer join.
104. 105
Outer join
Display name of employees and their immediate
supervisor without missing out employees who do
not have supervisor.
Select e.fname, e.lname, s.fname, s.lname
from employee e left outer join employee s
on e.super_ssn = s.ssn;
The key word outer, in such queries, is optional.
105. 106
Outer join
Display name of all employees and their
dependents without leaving out employees who
did not register their dependent detail in the
company database.
Select fname, lname, dependent_name
from employee left outer join dependent
on essn = ssn;
106. 107
Views
A view is a perspective of a database.
To create a view use
create view view_name as <query>;
To drop a view use
drop view view_name;