Professional Documents
Culture Documents
Database Applications
Programming 1
Information System
A database is a carefully designed and constructed
repository of facts. The database is part of a larger whole
known as information system, which provides for data
collection, storage, and retrieval.
The steps are laid out for conversion from old system to
the new system. Training principles and methodologies
are also planned and must be submitted for approval.
SDLC-Implementation
During the implementation phase, the hardware, DBMS
software, and application programs are installed, and the
database design is implemented. During the initial stages
of the implementation phase, the system enters into a
cycle of coding, testing, and debugging until it is ready to
be delivered. The actual database are created, and the
system is customized by the creation of tables and views,
user authorization, and so on.
SDLC-Implementation
The database contents might be loaded interactively or in
by batch mode, using a variety of methods and devices:
Designer’s View
COURSE
crs_code (PK)
crs_title
crs_descript
crs_credit
Logical Design
Validate the Logical Model Using Normalization
The logical design should contain only properly normalized
tables. The process of mapping the conceptual model to
the logical model may unveil some new attributes or the
discovery of new multivalued or composite attributes.
Logical Design
Validate Logical Model Integrity Constraints
COMPARISON OPERATORS
=, <, >, <=, >=, <> Used in conditional expressions
LOGICAL OPERATORS
AND/OR/NOT Used in conditional expressions
Command or Option Description
SPECIAL OPERATORS
BETWEEN Checks whether an attribute value is within a range
IS NULL Checks whether an attribute value is null
LIKE Checks whether an attribute value matches a given string pattern
IN Checks whether an attribute value matches any value within a value list
EXISTS Checks whether a subquery returns any rows
DISTINCT Limits values to unique values
AGGREGATE FUNCTIONS
COUNT Returns the number of rows with non-null values for a given condition
MIN Returns the minimum attribute value found in a given column
MAX Returns the maximum attribute value found in a given column
SUM Returns the sum of all values for a given column
AVG Returns the average of all values for a given column
Insert Into
The INSERT INTO statement is used to insert new records in a
table.
SELECT COUNT/AVG/SUM(column_name)FROM
table_name WHERE condition;
Min, Max
The Min() Function returns the smallest value of the selected
column. The Max() function returns the largest value of the
selected column.
SELECT MIN/MAX(column_name)FROM
table_name WHERE condition;
Introduction to SQL
• Transactional Control Language (TCL). These SQL
commands are used for managing changes affecting the
data. These command are commit, rollback, and savepoint.
Command or Option Description
COMMIT Commit command is used to permanently save any transaction into
database.
ROLLBACK This command restores the database to last committed state. It is also use
with savepoint command to jump to a savepoint in a transaction.
SAVEPOINT This command is used to temporarily save a transaction so that you can
rollback to that point whenever necessary.
Introduction to SQL
• Data Control Language (DCL). These SQL commands are
used for providing security to database objects. These
commands are grant, revoke, and deny.
Command or Option Description
GRANT This command is used by administrators to add new permissions to a
database user.
REVOKE This command is used to remove database access from a user previously
granted such access.
DENY This command is used to explicitly prevent a user from receiving a particular
permission.
SQL Join Operators
The relational join operation merges rows from two tables
and returns the rows with one of the following conditions:
• Have common values in common columns (natural join)
• Meet a given join condition (equality or inequality)
• Have common values in common columns or have no
matching values (outer join)
SQL Join Operators
SQL Join Operators
Join operations can be classified as inner joins and outer joins.
The inner join is the traditional join in which only rows that
meet a given criterion are selected. An outer join returns not
only the matching rows but the rows with unmatched
attribute values for one table or both tables to be joined.
Join Classification Join Type SQL Syntax Example Description
CROSS CROSS SELECT * Returns the Cartesian product of T1 and T2 (old style)
JOIN FROM T1, T2
SELECT * Returns the Cartesian product of T1 and T2
FROM T1 CROSS JOIN T2
INNER Old-style JOIN SELECT * Returns only the rows that meet the join condition in
FROM T1, T2 the WHERE clause (old style); only rows with matching
WHERE T1.C1 = T2.C1 values are selected
NATURAL JOIN SELECT * Returns only the rows with matching values in the
FROM T1 NATURAL JOIN T2 matching columns; the matching columns must have
the same names and similar data types
JOIN SELECT * Returns only the rows with matching values in the
USING FROM T1 JOIN T2 USING (C1) columns indicated in the USING clause
JOIN SELECT * Returns only the rows that meet the join condition
ON FROM T1 JOIN T2 ON T1.C1=T2.C1 indicated in the ON
OUTER LEFT SELECT * Returns rows with matching values and includes all
JOIN FROM T1 LEFT OUTER JOIN T2 rows from the left table (T1) with unmatched values
ON T1.C1=T2.C1
RIGHT SELECT * Returns rows with matching values and includes all
JOIN FROM T1 LEFT OUTER JOIN T2 rows from the right table (T2) with unmatched values
ON T1.C1=T2.C1
FULL SELECT * Returns rows with matching values and includes all
JOIN FROM T1 FULL OUTER JOIN T2 rows from both tables (T1 and T2) with unmatched
ON T1.C1=T2.C1 values
Cross join
A CROSS join performs a relational product of two tables.
The CROSS join syntax is:
CALL stored_procedure_name();
Stored Procedure
Declaring Variables
Variable are used in stored procedure to store immediate result.
The following syntax is used:
Data type can be any primitive type which SQL supports such as
INT, VARCHAR, and DATETIME, along with the data type is the size
of the variable.
Stored Procedure
To assign other value to a variable use SET statement, such as:
CASE
WHEN expression THEN commands
…
WHEN expression THEN commands
ELSE commands
END CASE;
Stored Procedure
Loop in Stored Procedure
Allows user to process commands iteratively.
WHILE expression DO
Statements
END WHILE
Stored Procedure
The syntax for REPEAT Loop is as follows:
REPEAT
Statements;
UNTIL expression
END REPEAT