Download presentation
Presentation is loading. Please wait.
1
Lecture 3 Finishing SQL
2
Quick Recap Constraints Select Operators Not Null, Unique
What is a Database schema A Collection of Database Objects associated with ONE database Username. EX – Facebook Personal_Information, Wall_Posts, Friends, Friends_Wall_Posts What are some Datatypes? Go through the Datatypes table to review. EX - String, Number, etc. Select Operators Equal, Not Equal, Greater than, Less than, etc. etc. BETWEEN, LIKE, IN Select Distinct, Wildcards Constraints Not Null, Unique PRIMARY KEY / FOREIGN KEY Zahid Hussin
3
QUIZ!!! (like I promised) Can a Table have more than one PRIMARY KEY?
Can a Table have more than one FOREIGN KEY? What is the difference between COUNT() and COUNT(*) Write a Query to find the FIRST_NAME which starts with the letter “T”. Table name for this Question is “persons” True/False --- A Primary key CAN contain Null Values. True/False --- A Primary key CANNOT contain Unique Values Here is the tough one! ---- Write the line of code which creates the foreign key constraint for a column. Zahid Hussin
4
HOMEWORK REVIEW ! First we need to create the table which is used in the homework.
5
HW REVIEW CONT. 1. What Query will confirm 10 records are in the database? 2. Write a query that tells you how many drivers are single drivers? 3. Write a Query that tells you how many drivers are not single drivers? 4. In the front end, you wrote 10 records. For each record a new customer ID is generated. What should your max customer ID be?
6
HW part 1.5 What is the difference between Count() and Count(*)
Which aggregate function gives you the biggest value of a column? If you want to order the table from newest entry to oldest entry, what would be the code for this? 1. Count (Column_name) will count the NON-NULL data in column_name and return that number. 2. Count (*) will count EVERY ROW in the ENTIRE TABLE and return that value.
7
HW PART 1.5 CONT. 4. Write the code which will help you search for a record that starts or ends with a certain character. 5. Write an SQL query which will help you find a city with ONLY 5 Characters. 6. Write an SQL query to find the first name of employees that start with the letter 'A'.
8
HW PART 2
9
HW PART 2 CONT. 1. Write a query to display first name and last name for all employees whose salary is in the range $10,000 through $15,000 I HAD AN ISSUE HERE, there were too many rows and I only wanted to see this answer within the first 10 rows that showed above.
10
HW PART 2 CONT. 2. Write a query to display the [first name, last name and department ID] of all employees in departments 30 or 100 in descending order by department ID.
11
HW PART 2 CONT. 3. Write a query to display the first name, last name and hire date for all employees who were hired in 1987. 4. Write a query to display the last names of employees whose names have exactly 6 characters.
12
HW PART 2 CONT. 5. Write a query to display the first name, last name and salary for all employees whose salary is in the range $10,000 through $15,000 and are in department 30 or 100.
13
!!!JOINS!!! Imagine that Each table is represented by a circle.
THIS IS THE MOST IMPORTANT SQL COMMAND YOU WILL EVER EVER EVER EVER EVER EVER EVER EVER LEARN!!!!!!!!!! An instruction to a database to combine data from MORE THAN ONE TABLE. And then to return some values WHICH FULFILL A SPECIFIC CONDITION. Imagine that Each table is represented by a circle. Then what can we do with these circles? Zahid Hussin
15
Lets start ! To explain this, I will use 2 basic tables which are easy to understand. Table 1 = people Table 2 = food What does the foreign key signify? What does it do?
16
First understand Foreign Key
Lets put some data into our two tables Why doesn’t this work?
17
What about NO Foreign key?
And now will it work?
18
YES
20
JOIN INNER JOIN General Query Example…
What if I only want to see the name of the person and the food they like? Introduction to Software Testing (Ch 1) © Ammann & Offutt
21
INNER JOIN CONT. I want to see which food people like.
What about more complex functions?
22
RIGHT JOIN SAME AS RIGHT OUTER JOIN
General Query Someone explain this to me!!!
23
RIGHT JOIN CONT.
24
LEFT JOIN SAME AS LEFT OUTER JOIN
General Query This should be easier to explain.
25
LEFT JOIN CONT.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.