2. SQL – Structured Query Language
A database computer language designed for the retrieval and management of
data in a relational database.
All the Relational Database Management Systems (RDMS) like MySQL, MS
Access, Oracle, Sybase, Informix, Postgres and SQL Server use SQL as their
standard database language.
Application –
Allows users to access data in the relational database management systems.
Allows users to describe the data.
Allows users to create and drop databases and tables.
Allows users to set permissions on tables, procedures and views.
Allows users to create view, stored procedure, functions in a database.
3. SQL Functions
What are they?
SQL functions are simply sub-programs, which are commonly used and re-used
throughout SQL database applications for processing or manipulating data.
All SQL database systems have DDL (data definition language) and DML (data
manipulation language) tools to support the creation and maintenance of
databases.
SQL functions are small programs that may have zero or more input parameters
but can return only one value.
DDL - responsible for tasks related to database creation, modification, and
maintenance.
DML - responsible for tasks related to the manipulation of data, which
essentially means DML is the programming interface of the database.
4. Classification & Purpose of SQL Function
Built-in functions -
• Standard functions which are already provided by the SQL database system,
and most of these functions are defined clearly in the ANSI (American
National Standards Institute) SQL standards.
• It is further divided into aggregate functions or scalar functions.
User-defined functions –
• Functions which are created by the user for a specific purpose.
• It can either return a single value or a set of values.
5. Advantages of Using Functions
A function needs to be written only once and can be reused multiple times.
This saves time and effort and supports modular programming.
Functions improve performance and efficiency of the database. SQL functions
are compiled and cached before use.
Complex programming logic can be decomposed into a number of smaller and
simpler functions, thus making it easier to understand and maintain.
7. Aggregate Functions
These functions return a single value after performing calculations on a
group of values.
Frequently used Aggregate functions –
Function Name Syntax
AVG() SELECT AVG(column_name) FROM
table_name
COUNT() SELECT COUNT(column_name) FROM table-
name
FIRST() SELECT FIRST(column_name) FROM table-
name
LAST() SELECT LAST(column_name) FROM table-
name
MAX() SELECT MAX(column_name) from table-
name
MIN() SELECT MIN(column_name) from table-name
SUM() SELECT SUM(column_name) from table-
name