Advanced_data Flashcards
What are relational databases? Explain the theory behind them!
- Relational databases store structured data in tables with defined relationships between them, following the principles of the relational model.
Why SQL is important these days?
- SQL is essential for managing and querying large datasets in relational databases, which are prevalent in modern applications and it is ensuring data security and integrity.
All the new GUI tools enable me to click a button to write SQL. Why should I spend time learning to write SQL manually?
- Understanding SQL enables greater control, customization, and troubleshooting in complex queries beyond what GUI tools offer.
If SQL is standardized, should you be able to program with SQL on any databases?
- Yes, you can generally write and execute standard SQL queries on different relational databases. However, there might be differences in syntax and supported features, which could require adjustments when working with specific databases. These variations are often related to non-standard features, data types, functions, and performance optimizations that are implemented differently by different DBMS vendors.
What makes SQL a nonprocedural language?
- SQL is considered a nonprocedural language because it focuses on specifying what you want to achieve rather than how to achieve it. In other words, you describe the desired outcome, and the database management system (DBMS) figures out the most efficient way to execute your request.
What can you do with SQL?
- SQL allows you to query, insert, update, and delete data, create and modify database structures, and define user access permissions.
Do the following statements return the same or different output? Why?
SELECT * FROM CHECKS; select * from checks;
- The statements return the same output, as SQL is case-insensitive for keywords but not for column/table names.
The following queries do not work when entered into the command line psql console. Why not?
Select * Select * from checks Select amount name payee FROM checks;
- The first needs to specify the table from which we want to select all columns like line 2. The third line must have a comma between columns name.
What shorthand could you use instead of WHERE a >= 10 AND a <=30
?
- I can use
WHERE a BETWEEN 10 AND 30
Which function capitalizes the first letter of a character string and makes the rest lowercase?
- The INITCAP() function performs this action.
Will this query work? Why?
SELECT COUNT(LASTNAME) FROM CHARACTERS;
- The query will work if there’s a table named “CHARACTERS” with a column “LASTNAME” since COUNT operates on columns.
Assuming that they are separate columns, which function(s) would splice together FIRSTNAME and LASTNAME?
- The CONCAT() function can combine FIRSTNAME and LASTNAME.
What is the function of the GROUP BY clause?
- The
GROUP BY
clause in SQL is used to group rows from a table into summary rows based on the values in one or more columns. It’s often used in combination with aggregate functions likeSUM
,COUNT
,AVG
,MAX
, andMIN
to perform calculations on groups of data rather than on individual rows. This is particularly useful for generating reports, performing analysis, and summarizing data.
SELECT CustomerName, SUM(Amount) AS TotalAmount FROM Orders GROUP BY CustomerName;
Why are so few functions defined in the ANSI standard and so many defined by the individual implementations?
- Database systems often introduce proprietary functions to differentiate themselves, leading to a variety of extensions beyond the standard.
When using the HAVING clause, do you always have to use a GROUP BY also?
- Yes, HAVING is used in conjunction with GROUP BY to filter grouped data.
- Use the WHERE clause for filtering individual rows based on column values, and use the HAVING clause for filtering groups of rows based on aggregate values after using GROUP BY.