BCS Database Programming Notes 1 - 12 (6)
BCS Database Programming Notes 1 - 12 (6)
By
Mwavu Rogers
[email protected]
(256)-700497421
One-to-One
One-to-Many
Then multiplicity ?
• This is where the EER diagram comes into the scene ,which
helps us find relations between various different subjects.
The process involves understanding the business problem ,
finding an IT related solution towards the problem, decide
on how the solution will be developed(mostly software
products), identifying the core stakeholder (those who will
interact directly with the system), stating requirements for
each stakeholder and lastly modelling the logical database
design from the requirements.
• Note, core requirement in the logical database design are
the functional and non functional requirements of the
system.
Insertion Anomaly
Update Anomaly
Deletion Anomaly
Transitive dependency
CREATE
ALTER
DROP
TRUNCATE
INSERT
UPDATE
DELETE
GRANT
REVOKE
These are SQL Commands used to fetch the data from the
database. SQL uses only one command:
SELECT
Example
SELECT * from staff WHERE Group_Email=
“[email protected]”
The SELECT statement above will return all staff members
with a group email [email protected] in a result set.
Program-data independence
Financial services
Banking services
Consumer goods
Retail sectors
Controlled manufacturing
Operational System
Flat Files
Meta Data
•Data quality
JTS Tech Solution Uganda is an ICT company located in Mbarara town. The
company has 4 branches i.e. Mbarara, Sembabule, Lwengo, Masaka. Each
branch is assigned employees of different categories such as manager,
supervisors, coordinator and other operations workers. The company offers IT
services such Website design and development, Mobile application
Development, ICT Training and Consultations, Microsoft Package Training,
Internship Training, Digital Marketing, Research Development and others. The
company also has over 1000 clients for the different services provided. The
organization employees are responsible for attending to the client in different
areas. Assuming you have been hired at JTS as the database administrator;
•Syntax
To drop the column from the table, we can use the
following Syntax
ALTER TABLE table_name DROP COLUMN
column_name
To change the name of the table, we can use the following
Syntax
ALTER TABLE table_name REMAME old__name
new_name
OR
ALTER TABLE table_name REMAME old_table_name
TO new_table_name
Examples of DML:
These commands are used to fetch the data from the database.
It uses only one command “SELECT”
Syntax.
SELECT column1, column2,… FROM table_name;
The starting point is the offset for the query (where your
results will start). The “rows_to_return” is how many rows
you want your query to retrieve.
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;
SELECT column_name(s)
FROM table1, table2
WHERE table1.column_name = table2.column_name;
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
SELECT column_name(s)
FROM table1 LEFT OUTER JOIN table2
ON table1.column_name = table2.column_name;
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
SELECT column_name(s)
FROM table1 LEFT OUTER JOIN table2
ON table1.column_name = table2.column_name;
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;
SELECT column_name(s)
FROM table1 RIGHT OUTER JOIN table2
ON table1.column_name = table2.column_name;
Example
We can refer to the columns of the table that are associated
with trigger by using the OLD and NEW keywords.
Example
Assuming you have a table containing student details that you need to frequently reference
on a daily basis.
• The 'IN' parameter serves as the default receiver for input values in
the procedure. Values can be passed as arguments during the
invocation of the stored procedure.
Syntax
DECLARE variable_name datatype DEFAULT
defaultValue;
Assigning Values
Syntax
DECLARE amount INT DEFAULT 0;
Assigning Values
SET amount = 2000;
• No parameter P1
procedure
• Parameterized P2
procedure
• Execute SQL
statement p3
• Declare variables
and assign values
p5
Perform calculation
Syntax
DROP PROCEDURE procedure_name DELIMITER
Example
DROP PROCEDURE p1#
List all defined stored procedure
SHOW PROCEDURE STATUS;
Explaining structure of stored procedure
SHOW CREATE PROCEDURE procedure_name;
INOUT
OUT
Line 4 means that if a user has clicked the save button which
indicates that the value of the button is posted. Then the code below
gets executed.
Line 5-10 show different value declared to capture the user input from
the form field using their names as passed in the square brackets
following the method specified to process form data.
Line 15-16 indicates an SQL statement being prepared to insert data.
Using prepared statement, each column value is specified using a
question mark “?” which are bound as parameters using the
bind_param() method. The binding method specified the number of
strings to be bound using s and the exact values for each column.
Specification character s indicates that the corresponding variable has
type string. Other are i for integers, d for double, b for blob etc.