Vous êtes sur la page 1sur 27

Essentials of IT

Unit 3- Chapter 7- Database Design Process

Introduction to Database Management


System
Introduction:
Data: (Piece of information)Known facts that can be recorded and that have implicit meaning is
known as Data.
Database: Collection of related data can be called as a Database.
DBMS: Collection of programs that enables the user to create and maintain a database Is
Database Management System.
DBMS: Data + set of programs to access/manipulate data.

Formal Definition:
DBMS: is a general purpose software system that facilitates the processes of defining, constructing,
manipulating, and sharing databases among various users and applications.

o Defining Defining a database involves specifying the datatypes, structures, and constraints of the
data that has to be stored in the database. oConstructing Constructing the database is the
process of storing the data itself on some storage medium that is controlled by the DBMS.
o Manipulating Manipulating a database includes such functions as querying the database to retrieve
specific data, updating the database to reflect changes in the mini world, and generating reports from
the data.
o Sharing Sharing a database allows multiple users and programs to access the database
simultaneously.

Example :
University Database:

Essentials of Information Technology Page 2


Data stored:Data about students, faculty, courses, research laboratories, course registration/
enrollment etc.
Purpose:To keep an accurate track of the academic activities of the university.

Bank Database:
Data Stored: Data about Bank accounts, Customer details, Deposits, Loans and credits, Online
banking registrations etc
Purpose: To keep daily bank transaction of all branches of the bank through data sharing

Structure of Database Management System Software

Figure 7.1 Simplified database system environment

As shown in figure 7.1, the DBMS software users interact with the database system using queries (written
in software like SQL plus) or Application programs (like Java) to make operations on the database. These
queries are the processed by the DBMS software and the user is given access to the database. The data
present in the database is stored in the hardware in 2 forms, one is metadata which is the definition of the
data stored and the other is the real data present in the database.

Essentials of Information Technology Page 3


Characteristics of DBMS:
There are a number of characteristics that distinguish the database approach with the file-based
approach. Few are listed below

i. Self describing nature of Database System :

- DB system contains the complete definition of structure and the constraints which makes itself
describing.

- The description of the structure and constraints of the data is termed as Meta-data.

- This information (meta-data) is used either by the DBMS software or database users who need
information about the database structures.

- On the other hand, in file based systems, the definition of the data is a part of application program
that has to be handled by the users.

ii. Insulation between Program and Data :

- In file based system, the structure of the data is stored in the application program. As a result, if we
want to change any definition of the data, then the program that accesses that data has to be
changed.

- Whereas, in database systems, as the data structures are stored in the catalog and not in programs,
we can manipulate any one i.e. either program or data whichever is needed.

- Thus DBMS provides program and data independence. iii. Support multiple views of the Data :

- View is a subset of the database. View contains virtual data that is derived from the database files but
it is not explicitly stored.

- Multiple users in the same Database system might have different views of that system. Each view
might contain only the data of interest to that user or a group of users.

- In this way DBMS supports multiple views of the data.

iv. Sharing of data and multi user transaction processing :

- Allows multiple users to access the data at the same time.

- The Concurrency Control Techniques of DBMS ensures that several users trying to access and
update the same data do so in a controlled manner.

Essentials of Information Technology Page 4


- Thus DBMS provides multiple user transaction unlike the file based system where the transaction
processing is restricted for single user.

v. Enforcing Integrity Constraints :


- DBMS provides certain methodologies to define and enforce certain constraints such as data
type, data uniqueness, etc.

vi. Restricting unauthorized access :

- Not all users of the system have the same accessing privileges. DBMS provides a security sub
system to create and control the user accounts.

vii. Providing backup and recovery facilities


- If the computer system fails in the middle of a complex update process, the recovery subsystem is
responsible for making sure that the database is restored to the stage it was in before the process
started executing.

Entity- Relation Model:


- Entity - relation model (abbreviated as ER model) is the conceptual view of a database.

- At view level, the ER model is considered a good option for designing databases.

- Entity :

Essentials of Information Technology Page 5


An entity can be a real-world object, that can be easily identifiable.

Example, in an university database, students, teachers, classes, and courses offered can be
considered as entities.

- Entity set :

An entity set is a collection of similar types of entities.

An entity set may contain entities with their properties sharing similar values.

For example, a Students set may contain all the students of university; likewise a Teachers set may
contain all the teachers of university from all faculties.

Entity sets need not be disjoint.

Attributes:

Entities are represented by means of their properties, called attributes.

All attributes have values.

For example, a student entity may have name, class, and age as attributes.

There exists a domain or range of values that can be assigned to attributes. For example, a student's
name cannot be a numeric value. It has to be alphabetic. A student's age cannot be negative, etc.

Types of attributes :

Simple attribute: The attributes with the atomic values which cannot be divided further are classified
as Simple attributes. For example, a student's phone number is an atomic value of 10 digits.
Composite attribute: Attributes made up of more than one simple attribute are termed as Composite
attributes. For example, a student's complete name may have first_name , middle_name and
last_name.

Derived attribute: Derived attributes are the attributes that do not exist in the physical database, but
their values are derived from other attributes present in the database. For example, average_salary in
a department should not be saved directly in the database, instead it can be derived. To quote
another example, age can be derived from data_of_birth.

Single value attribute: Single value attributes contain single value. For example ,
Social_security_number of an employee, USN of a student etc..

Multi value attribute: Multi value attributes may contain more than one values. For example, a person
can have more than one phone numbers, email addresses etc ..

These attribute types can come together in a way like

Essentials of Information Technology Page 6


simple single-valued attributes
simple multi-valued attributes
composite single-valued attributes
composite multi-valued attributes Keys:

Key is an attribute or collection of attributes that uniquely identifies an entity among entity set.

For example, the roll_number of a student makes him/her identifiable among students.

o Super Key A set of attributes (one or more) that collectively identifies an entity in an entity set.

o Candidate Key A minimal super key is called a candidate key. An entity set may have more than
one candidate key.

o Primary Key A primary key is one of the candidate keys chosen by the database designer to
uniquely identify the entity set.

Relationship:

The association among entities is called a relationship.

For example, an employee works_at department,a student enrollsin a course.

Here,Works_at and Enrolls are the relationships.


Degree of a relationship:

Number of entities participating in a relationship defines the degree of that relationship.

Types :

- Binary -> degree=2

- Ternary -> degree=3

- n-ary -> degree=n

Mapping cardinalities:

Cardinality defines the number of entities in one entity set, which can be associated with the number
of entities of other entity set via relationship set.

Types of Cardinality :

Essentials of Information Technology Page 7


I. One-to-one One entity from entity set A can be associated with at most one entity of entity set B and
vice versa.

II. One-to-many One entity from entity set A can be associated with more than one entities of entity set B
however an entity from entity set B, can be associated with at most one entity.

III.Many-to-one More than one entities from entity set A can be associated with at most one entity of entity
set B, however an entity from entity set B can be associated with more than one entity from entity set
A.

Essentials of Information Technology Page 8


IV.Many-to-many One entity from A can be associated with more than one entity from B and vice versa.

ER NOTATION:

Essentials of Information Technology Page 9


Mapping ER Model to Relational Schema:

Relational Schema:
o Relational Schema consists of relational name,and a set of attributes or field names or column
names.
o Each attribute is associated with its domain. o Domain = Set of atomic values + Data types.

Essentials of Information Technology Page 10


ER to Relational Schema Algorithm:
Steps involved in converting the ER model to relational Schema:

Step1: Mapping of Regular Entity Types:


For each regular (strong) entity type E in the ER schema, create a relation R that includes all the
simple attributes of E. Include only the simple component attributes of a composite attribute.
Choose one of the key attributes of E as primary key for R. If the chosen key of E is composite, the
set of simple attributes that form it will together form the primary key of R.

Step2: Mapping of Weak Entity Types :


For each weak entity type W in the ER schema with owner entity type E , create a relation R and
include all simple attributes (or simple components of composite attributes) of W as attributes of R.
In addition, include as foreign key attributes of R the primary key attribute(s) of the relation(s) that
correspond to the owner entity type(s); this takes care of the identifying relationship type of W.
The primary key of R is the combination of the primary key(s) of the owner(s) and the partial key of
the weak entity type W, if any.

Step3: Mapping of Binary 1:1 Relationship Types :


For each binary 1:1 relationship type R in the ER schema, identify the relations S and T that
correspond to the entity types participating in R.
Choose one of the relations S, say and include as a foreign key in S the primary key of T. It is
better to choose an entity type with total participation in R in the role of S.
Include all the simple attributes (or simple components of composite attributes) of the 1:1 relationship
type R as attributes of S.

Step4: Mapping of Binary 1:N Relationship Types :


For each regular binary 1:N relationship type R, identify the relation S that represents the participating
entity type at the N side of the relationship type.
Include as foreign key in S the primary key of the relation T that represents the other entity type
participating in R; (this is done because each entity instance on the N-side is related to at most one
entity instance on the 1-side of the relationship type).
Include any simple attributes (or simple components of composite attributes) of the 1:N relationship
type as attributes of S.

Step5: Mapping of Binary M:N Relationship Types :


For each binary M:N relationship type R, create a new relation S to represent R.
Include as foreign key attributes in S the primary keys of the relations that represent the participating
entity types; their combination will form the primary key of S.
Also include any simple attributes of the M:N relationship type (or simple components of composite
attributes) as attributes of S.

Essentials of Information Technology Page 11


Step6: Mapping of Multi valued Attributes :
For each multi valued attribute A, create a new relation R. This relation R will include an attribute
corresponding to A, plus the primary key attribute K- as corresponding to A, plus the primary key
attribute K- as a foreign key in R- of the relation that represents the entity type or relationship type
that has A as an attribute.
The primary key of R is the combination of A and K. If the multi valued attribute is composite, we
include its simple components.

Step7: Mapping of N- ary Relationship Types :


For each n-ary relationship type R, where n>2, create a new relation S to represent R.
Include as foreign key attributes in S the primary keys of the relations that represent the participating
entity types.
Also include any simple attributes of the n-ary relationship type (or simple components of composite
attributes) as attributes of S.
The primary key of S is usually a combination of all the foreign keys that reference the relations
representing the participating entity types.

Example:

Normalization:

Informal design guidelines for Relational Schema:


Measures of quality:
1. Making sure attribute semantics (meanings) are clear.
2. Reducing redundant information in tuples (records).
3. Reducing NULL values in tuples.

Essentials of Information Technology Page 12


4. Disallowing possibility of generating spurious tuples (unwanted additional tuples generated by some
join of two relations).
Normalization:
Normalization is the Formal technique for analyzing a relation based on
- Its primary key and
-The FDs between the attributes of that relation.

-A relation can be normalized to a specific form to prevent the possible occurrence of update anomalies.

- As normalization proceeds, the relations become progressively more restricted (stronger) in format and
also less vulnerable to update anomalies.

-Most commonly used normal forms are:


1NF
2NF
3NF
BCNF
4NF
5NF
First Normal Form :
Def: A relation schema R is in 1NF if every attribute of R takes only single and atomic values.
Example:
Student_Apply(RollNo, Name, Age, DeptName)

Roll no Name Age Department


201 Amar 30 {ise, cse}
205 Akbar 31 {ece}
203 Anthony 32 {auto, robo}

-This Violates 1NF, because of DeptName i.e. a single student cannot belong to two departments.

Solution1:
Use multiple tuples one per value.
Student_Apply(RollNo, DeptName, Name, Age)

Solution2:
Split the Student table into two different tables.
Student(RollNo, Name, Age)
Apply(RollNo,DepName)

Essentials of Information Technology Page 13


Second Normal Form:

Def: A relation schema R is in 2NF if and only if it is in 1NF and every non-prime attribute in R is fully
functionally dependent on key.
Example :
Consider:
Student (RollNo, Name, Dept, Gender, HostelName, RoomNo)
Assumption: Boys & girls are accommodated in separate hostels
Keys: RollNo, (HostelName, RoomNo)

Q: Is this relation in 2NF ?


A:Not in 2NF as HostelNameGender i.e.(not fully functionally dependent because HostelName is just a
part of the key)

Converting to 2NF: [Both the relations are in 2NF]


R1: Student (RollNo, Name, Dept, HostelName, RoomNo)
R2: HostelDetail(HostelName, Gender)

Third Normal Form :

Def:Relation schema R is in 3NF if it is in 2NF and no non-prime attribute of R is transitively dependent


on any key of R.
Example :
Student (rollNo,name,dept,hostelname,roomNo,headDept)
Is it in 3NF? [No] Decompose:
R1 : Student(rollNo,name,dept,hostelName,roomNo)
R2 : deptInfo(dept,headDept)
Both R1 and R2 are in 3NF.Hence the Redundancy in data storage is removed.

Essentials of Information Technology Page 14


Unit 3- Chapter 8- Structured Query Language

SQL (Structural Query Language)


SQL (Structured Query Language) is a standard supported by all the popular Relational database
management systems in the market place.
The basis data structure in RDBMS is a table.
SQL provides you the features to define tables, define constraints on tables, query for data in table,
and change the data in table by adding, modifying, and removing data.
SQL also supports grouping of data in multiple rows, combining tables and other features.
All these put together, SQL is a high-level query language standard to access and alter data in
RDBMS.

Clauses we have in SQL:

SELECT clause
FROM clause
WHERE clause
GROUP BY HAVING

Clauses can be used:


To retrieve/insert/modify existing data from database.
Get all data from the table
Get selected columns from the table.
Get selected rows from the table.
Get selected columns of selected rows from the table.
Get computed columns using char, number, data functions, general functions, and aggregating
functions.
Get data in multiple rows grouped on an aggregating function applied on one or more columns.
Select specific aggregating data on multiple rows using having clause.
Apply set operations like Union and Intersection on data sets of the same cardinality and type.
Get data from multiple tables using Cartesian product, equality join, un-equal join, and outer join.
Create views on physical data.
Data types in SQL:
1. Character data type : This data type is used when the data to be manipulated includes letters,
numbers, spaces and other symbols i.e. it can be stored as alpha-numerical values. This data type is
used when a fixed length character is required.

Essentials of Information Technology Page 15


2. Varchar2 data type : This data type is used to store the same type of data say the character data
type. If a value less than the specified size is entered then the field is automatically fixed to that
length. If a value larger than the specified size is entered than the additional characters are ignored.
This data type can be used to save a lot of disk space.
3. Number data type : Data types that are restricted to pure numbers belong to this data type. This data
type includes a combination of digits 0 through 9, a decimal point and a minus sign if necessary.
4. Date data type : This data type is used to store date and time in a table. The format of storage varies
with respect to database in use.

DBMS Languages
Data definition language (DDL)
Defines schemas
Storage definition language (SDL)
Specifies the internal schema
View definition language (VDL)
Specifies user views/mappings to conceptual schema
Data manipulation language (DML)
Allows retrieval, insertion, deletion, modification

Data Definition Language (DDL):


To do with altering the structure of data base.
Create tables.
Create Indexes on tables.
Alter tables
Add constraints to tables.
Drop tables.
Truncate tables.
Drop indexes.
Create sequences.
Data Manipulation Language (DML):
To do with adding, updating, and deleting data from tables.
Insert Data
Update Data
Delete Data
Merge Tables.
Data Control Language (DCL):
To do with controlling access to data in tables.
Grant Permissions
Revoke Permissions
Create and update roles.
Add users to roles.
DDL commands:

Essentials of Information Technology Page 16


1. The Create Table Command: It defines each column of the table uniquely. Each column has
minimum of three attributes, a name, data type and size.

Syntax:

Create table <table name> (<col1><datatype>(<size>),<col2><datatype><size>));

Ex: create table emp( empno


number(4) primary key, ename
char(10));

2. Modifying the structure of tables.

a) add new columns

Syntax:
Alter table <tablename>add(<new col><datatype(size),<new col>datatype(size));

Ex: alter table emp add(sal


number(7,2));

3. Dropping a column from a table.

Syntax:
Alter table <tablename> drop column <col>;

Ex: alter table emp drop


column sal;

4.Modifying existing columns.

Syntax:
Alter table <tablename>modify(<col><newdatatype>(<newsize>));

Ex: alter table emp modify(ename


varchar2(15));

5. Renaming the tables

Syntax:
Rename <oldtable> to <new table>;

Ex:
rename emp to emp1;

Essentials of Information Technology Page 17


6. Truncating the tables.

Syntax:
Truncate table <tablename>;

Ex: trunc table


emp1;

7. Destroying tables.

Syntax:
Drop table <tablename>;

Ex: drop table


emp;

DML commands:
1. Inserting Data into Tables: -

Once a table is created the most natural thing to do is load this table with data to be
manipulated later.

Syntax 1: insert into <tablename> (<col1>,<col2>.....<col n>) values(<val 1>, <val


2>.......<val n>);

Syntax 2: insert into <tablename>


values(&<col1>,&<col2>......,&<col n>);

Syntax 3:
insert into <tablename> values(<val 1>,<val 2>.......,<val n>);

Ex 1:
Insert into skc(sname,rollno,class,dob,fee_paid)values(sri,104B,cse,27-feb-05,10000.00);

Ex 2: insert into skc values(&sname,&roll no,&class); enter


sname:sri enter roll no:104B enter class:cse

Ex 3:
insert into skc values(sri,104B,cse,27-feb-05,10000.00);
2. Delete operations.

a) Remove all rows

Syntax:

Essentials of Information Technology Page 18


delete from <tablename>;

b) Removal of a specified row/s

Syntax:
delete from <tablename> where <condition>;

3. Updating the contents of a table.

a) updating all rows

Syntax:
Update <tablename> set <col>=<exp>,<col>=<exp>;

b) updating seleted records.

Syntax:
Update <tablename> set <col>=<exp>,<col>=<exp> where <condition>;

4. Types of data constrains.

a) not null constraint at column level.

Syntax:
<col><datatype>(size)not null

b) unique constraint

Syntax:
Unique constraint at column level. <col><datatype>(size)unique;

c) unique constraint at table level:

Syntax: Create
table
tablename(col=format,col=format,unique(<col1>,<col2>);

d) primary key constraint at column level

Syntax:
<col><datatype>(size)primary key;
e) primary key constraint at table level.

Syntax:

Essentials of Information Technology Page 19


Create table tablename(
col=format, col=format
primary key(col1>,<col2>);

f) foreign key constraint at column level.

Syntax:
<col><datatype>(size>) references <tablename>[<col>];

g) foreign key constraint at table level

Syntax: foreign key(<col>[,<col>]) references


<tablename>[(<col>,<col>)

h) check constraint

Syntax:
<col><datatype>(size) check(<logical expression>)

i) check constraint constraint at table level.

Syntax:
check(<logical expression>)

DCL commands:
Oracle provides extensive feature in order to safeguard information stored in its tables from unauthoraised
viewing and damage. The rights that allow the user of some or all oracle resources on the server are
called privileges.

a) Grant privileges using the GRANT statement


The grant statement provides various types of access to database objects such as tables,views and
sequences and so on.

Syntax:
GRANT <object privileges> ON <objectname> TO<username> [WITH GRANT OPTION];

b) Revoke permissions using the REVOKE statement:


The REVOKE statement is used to deny the Grant given on an object.

Syntax:
REVOKE<object privilege>
ON
FROM<user name>;

Essentials of Information Technology Page 20


Example-1
CREATING A STUDENT RELATION TABLE WITH ALL DATATYPES:

Example: create table


student252( sid
number(5), sname
varchar(20), sbranch
char(5), dob date,
spercent number(3,2));

INSERT THE RECORDS INTO STUDENT RELATION: METHOD


1:
Insert into Student252(sid,sname,sbranch,dob,spercent) values(104,sri,,cse,27-
feb-05,70); 1 row created.

METHOD 2:
Insert into Student252 values(104,sri,,cse,27-feb-05,70); 1
row created.

METHOD 3:
Insert into Student252(sid,sname,sbranch,dob,spercent) values(&sid,
&sname,&sbranch,&dob,&spercent); 1 row created.

METHOD 4:
Insert into Student252(sid,sname,sbranch,dob,spercent) values(&sid,
&sname,&sbranch,&dob,&spercent); 1
row created.

To retrieve all data from the database.


Select * from Student252;

To retrieve data related to student with percent greater than 90%


Select * from Student252 where spercent = 90;

MODIFYING THE STRUCTURE OF TABLE

ADDING A NEW COLUMN


ALTER TABLE Emp252 ADD (age number(3), phno number(10)); Table
altered.

MODIFYING EXISTING COLUMN


ALTER TABLE Emp252 MODIFY (phno varchar(20)); Table
altered.

Essentials of Information Technology Page 21


DROPING A COLUMN
ALTER TABLE Emp252 DROP COLUMN phno;
Table altered.

Operators in Database:
What is an Operator in SQL?
An operator is a reserved word or a character used primarily in an SQL statement's WHERE clause to
perform operation(s), such as comparisons and arithmetic operations.

Operators are used to specify conditions in an SQL statement and to serve as conjunctions for multiple
conditions in a statement.

Arithmetic operators

Comparison operators

Logical operators

Operators used to negate conditions

SQL Arithmetic Operators:


Assume variable a holds 10 and variable b holds 20, then:

Operator Description Example

+ Addition - Adds values on either side of the a + b will


operator give 30

- Subtraction - Subtracts right hand operand from a - b will


left hand operand give -10

* Multiplication - Multiplies values on either side of a * b will


the operator give 200

/ Division - Divides left hand operand by right hand b / a will


operand give 2

% Modulus - Divides left hand operand by right hand b%a


operand and returns remainder will give
0

SQL Comparison Operators:


Assume variable a holds 10 and variable b holds 20, then:

Essentials of Information Technology Page 22


Operator Description Example

= Checks if the values of two operands are equal or (a = b) is


not, if yes then condition becomes true. not true.

!= Checks if the values of two operands are equal or (a != b)


not, if values are not equal then condition becomes is true.
true.

<> Checks if the values of two operands are equal or (a <> b)


not, if values are not equal then condition becomes is true.
true.

> Checks if the value of left operand is greater than (a > b) is


the value of right operand, if yes then condition not true.
becomes true.

< Checks if the value of left operand is less than the (a < b) is
value of right operand, if yes then condition true.
becomes true.

>= Checks if the value of left operand is greater than (a >= b)


or equal to the value of right operand, if yes then is not
condition becomes true. true.

<= Checks if the value of left operand is less than or (a <= b)


equal to the value of right operand, if yes then is true.
condition becomes true.

!< Checks if the value of left operand is not less than (a !< b) is
the value of right operand, if yes then condition false.
becomes true.

!> Checks if the value of left operand is not greater (a !> b) is


than the value of right operand, if yes then condition true.
becomes true.

SQL Logical Operators:

Essentials of Information Technology Page 23


Here is a list of all the logical operators available in SQL.

Operator Description

ALL The ALL operator is used to compare a value to all values in


another value set.

AND The AND operator allows the existence of multiple conditions


in an SQL statement's WHERE clause.

ANY The ANY operator is used to compare a value to any


applicable value in the list according to the condition.

BETWEEN The BETWEEN operator is used to search for values that


are within a set of values, given the minimum value and the
maximum value.

EXISTS The EXISTS operator is used to search for the presence of a


row in a specified table that meets certain criteria.

IN The IN operator is used to compare a value to a list of literal


values that have been specified.

LIKE The LIKE operator is used to compare a value to similar


values using wildcard operators.

NOT The NOT operator reverses the meaning of the logical


operator with which it is used. Eg: NOT EXISTS, NOT
BETWEEN, NOT IN, etc. This is a negate operator.

OR The OR operator is used to combine multiple conditions in an


SQL statement's WHERE clause.

IS NULL The NULL operator is used to compare a value with a NULL


value.

Essentials of Information Technology Page 24


UNIQUE The UNIQUE operator searches every row of a specified table
for uniqueness (no duplicates).

The ORDER BY Keyword:

The ORDER BY keyword is used to sort the result-setby a specified column.

Syntax:
SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DSC

SQL Aggregate Functions

SQL aggregate functions return a single value, calculated from values in a column.

Useful aggregate functions:


AVG() - Returns the average value
COUNT() - Returns the number of rows
FIRST() - Returns the first value
LAST() - Returns the last value
MAX() - Returns the largest value
MIN() - Returns the smallest value
SUM() - Returns the sum

The SUM() and AVG() Function

The SUM() function returns the total sum of a numeric column.

Syntax:
SELECT SUM(column_name) FROM table_name;

The AVG() function returns the average value of a numeric column.

SELECT AVG(column_name) <AS avg_Col_name> FROM table_name

The COUNT() Function

The COUNT(column_name) function returns the number of values (NULL values will not be
counted) of the specified column

Syntax:

Essentials of Information Technology Page 25


SELECT COUNT(column_name) FROM table_name;

The COUNT(*) function returns the number of recordsin a table

Syntax:
SELECT COUNT(DISTINCT column_name) FROM table_name;

The MAX() and MIN() Function:

The MAX() function returns the largest value of the selected column.

Syntax:
SELECT MAX(column_name) FROM table_name;

The MIN() function returns the smallest value of the selected column.

Syntax:
SELECT MIN(column_name) FROM table_name;

GROUP BY & Having Clause:

The GROUP BY statement is used in conjunction with the aggregate functions


to group the result-set by one or more columns.

Syntax:
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name ;

The HAVING clause was added to SQL because the WHERE keyword could not be used with
aggregate functions.

Syntax:
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value ;

Essentials of Information Technology Page 26


Nested Queries or Sub Queries :

What Is a Subquery?

A subquery is a SELECT statement embedded in a clause of another SQL statement.

Syntax of nested query:

select<column(s)>
from table =>Outer Query where<condn>
operator
(select<column> =>Inner Query from
table);

Essentials of Information Technology Page 27

Vous aimerez peut-être aussi