2. Previous Work Review
• http://pirate.shu.edu/~marinom6/work.html
• Please Note only previously due HW assignments are posted on my
pirate.shu.edu web space
• Begin organizing your creating files for this course into an easy to find folder
on your desktop for easy FTP later on
3. Basics
• A new database is created using the code create database databasename
• Select is the function which allows you to choose something in MySQL
• The where function is also needed when using the select function to see where your
request is
• The from function relates to the select and where function; often seen formatted
using select from and where in that order – in order to select something from a
specific database in the section it is in
• Join type is based on join condition
4. Creating Contact Table with SQL Code
CREATE TABLE CONTACT
(
contact_id INT not null PRIMARY KEY
GENERATED ALWAYS AS IDENTITY
(START WITH 1, INCREMENT BY 1),
"FIRST_NAME" varchar(30),
"LAST_NAME" varchar(30),
"ADDRESS" varchar(30),
"CITY" varchar(30),
"STATE" varchar(30),
"ZIPCODE" varchar(30)
);
6. Select – From – Where Conditions
• Logical comparison operators
• =, <, <=, >, >=, and <>
• Projection attributes
• Attributes whose values are to be retrieved
• Selection condition
• Boolean condition that must be true for any retrieved tuple. Selection
conditions include join conditions (see Ch.8) when multiple relations are
involved.
8. INSERT, DELETE, and UPDATE
• Three commands used to modify the database:
• INSERT, DELETE, and UPDATE
• INSERT typically inserts a tuple (row) in a relation (table)
• UPDATE may update a number of tuples (rows) in a relation (table) that
satisfy the condition
• DELETE may also update a number of tuples (rows) in a relation (table)
that satisfy the condition
9. Aggregate Functions in SQL
• Used to summarize information from multiple tuples into a single-tuple summary
• Built-in aggregate functions
• COUNT, SUM, MAX, MIN, and AVG
• Grouping
• Create subgroups of tuples before summarizing
• To select entire groups, HAVING clause is used
• Aggregate functions can be used in the SELECT clause or in a HAVING clause
10. Assertions and Triggers
• CREATE ASSERTION
• Specify additional types of constraints outside scope of built-in relational model
constraints
• CREATE TRIGGER
• Specify automatic actions that database system will perform when certain events and
conditions occur
12. Trigger Visual
R5:
CREATE TRIGGER SALARY_VIOLATION
BEFORE INSERT OR UPDATE OF Salary, Supervisor_ssn ON EMPLOYEE
FOR EACH ROW
WHEN (NEW.SALARY > ( SELECT Salary FROM EMPLOYEE
WHERE Ssn = NEW. Supervisor_Ssn))
INFORM_SUPERVISOR (NEW.Supervisor.Ssn, New.Ssn)
13. Command Prompt
prompt meaning
mysql> Ready for new command.
-> Waiting for next line of multiple-line command.
‘> Waiting for next line, waiting for completion of a string that began with a single quote
(“'”).
“> Waiting for next line, waiting for completion of a string that began with a double quote
(“"”).
`> Waiting for next line, waiting for completion of an identifier that began with a backtick
(“`”).
/*> Waiting for next line, waiting for completion of a comment that began with /*.
14. Querying
To find all loan number for loans made at the Perryridge branch with loan amounts greater
than $1100.
• select loan_number from loan
where branch_name = ‘Perryridge’ and amount>1100;
Find the loan number of those loans with loan amounts between $1,000 and $1,500 (that is,
>=$1,000 and <=$1,500)
• select loan_number from loan
where amount between 1000 and 1500;
15. Joins
• Join operations take two relations and return as a result another relation.
• These additional operations are typically used as subquery expressions in the
from clause
• Join condition – defines which tuples in the two relations match, and what
attributes are present in the result of the join.
• Join type – defines how tuples in each relation that do not match any tuple in
the other relation (based on the join condition) are treated.
17. Building Assignment 15
• Increase all accounts with balances over $700 by 6%, all other accounts
receive 5%.
update account
set balance =case
when balance <= 700 then balance *1.05
else balance * 1.06
end;
18. Building Final Project
• Homepage – similar to http://pirate.shu.edu/~marinom6/ but list
information about yourself
• My Work – should look like http://pirate.shu.edu/~marinom6/work.html but
with your work linked, not mine
• Contact – should look like http://pirate.shu.edu/~marinom6/contact.html but
you can add your name or other info to the header if you want
• You might want to use your .css file to set text color and background color [or
feel free to use CSS embedded in your web pages
19. Extra Credit
• If you would like to complete the Extra Credit with the
additional form
• Reach out to me directly for assistance – not everyone
may want to do this