Week 18 (5/7/2025 - 5/13/2025)
(Click on READ MORE for better formatting)
Hi everyone, welcome to my 18th blog! This is the Week 2 post for CST 363 Introduction to Database Systems.
- SQL has the flexibility to join tables on any column(s) using any predicate (=, >, < ). Most of the time the join will use equality between a primary and foreign key. Think of example where joining on something other than keys would be needed. Write the query both as an English sentence and in SQL. If you can't think of your own example, search the textbook or internet for an example.
- One of the problems from Homework 2 calls for a scenario where this happens. To be specific, it is Problem 6: "List all departments in alphabetical order along with the count of students majoring in that department using a label of "count". Include only students with more than 90 credits. List the department even if the count is 0." The SQL representation of this query is as follows:
- select s1.dept_name, count(s2.ID) as "count" from student as s1 left join student as s2 on (s1.ID = s2.ID and s2.tot_cred > 90) group by s1.dept_name order by s1.dept_name;
- Explanation: tot_cred is not a primary or foreign key. Also, this query makes use of a conditional inside the join statement to narrow down results.
- What is your opinion of SQL as a language? Do you think it is easy to learn and use? When translating from an English question to SQL, what kinds of questions do you find most challenging?
- I think SQL is a good language for its purpose. It has many features to make a wide variety of tasks possible using only SQL queries. However, it can be abused and there are some major vulnerabilities to watch out for when implementing SQL in an application. The most prominent of these vulnerabilities is SQL injection. I think some questions involving join queries have been the most challenging to translate so far. Subquery can also be challenging at times.
That is all for this week, see you in my Week 19 post!
Comments
Post a Comment