|
3 | 3 |
|
4 | 4 | :information_source: This repository contains interview questions on various DevOps related topics
|
5 | 5 |
|
6 |
| -:bar_chart: There are currently **300** questions |
| 6 | +:bar_chart: There are currently **312** questions |
7 | 7 |
|
8 | 8 | :warning: You don't need to know how to answer all the questions in this repo. DevOps is not about knowing all :)
|
9 | 9 |
|
|
38 | 38 | <td align="center"><a href="#openshift"><img src="images/openshift.png" width="75px;" height="75px;" alt="OpenShift"/><br /><b>OpenShift</b></a><br /><sub><a href="#openshift-beginner">Beginner :baby:</a></sub><br><sub></td>
|
39 | 39 | <td align="center"><a href="#shell-scripting"><img src="images/bash.png" width="75px;" height="75px;" alt="Bash"/><br /><b>Shell Scripting</b></a><br /><sub><a href="#shell-scripting-beginner">Beginner :baby:</a></sub><br><sub><a href="#shell-scripting-advanced">Advanced :star:</a></sub></td>
|
40 | 40 | </tr>
|
| 41 | + <tr> |
| 42 | + <td align="center"><a href="#sql"><img src="images/sql.png" width="75px;" height="75px;" alt="sql"/><br /><b>SQL</b></a><br /><sub><a href="#sql-beginner">Beginner :baby:</a></sub><br><sub><a href="#sql-advanced">Advanced :star:</a></sub></td> |
| 43 | + </tr> |
41 | 44 | </table>
|
42 | 45 | </center>
|
43 | 46 | <!-- markdownlint-enable -->
|
@@ -2005,6 +2008,187 @@ A short way of using if/else. An example:
|
2005 | 2008 | [[ $a = 1 ]] && b="yes, equal" || b="nope"
|
2006 | 2009 | </b></details>
|
2007 | 2010 |
|
| 2011 | +## SQL |
| 2012 | + |
| 2013 | +<a name="sql-beginner"></a> |
| 2014 | +#### :baby: Beginner |
| 2015 | + |
| 2016 | +<details> |
| 2017 | +<summary>What does SQL stand for?</summary><br><b> |
| 2018 | + |
| 2019 | +Structured Query Language |
| 2020 | + |
| 2021 | +</b></details> |
| 2022 | + |
| 2023 | +<details> |
| 2024 | +<summary>How is SQL Different from NoSQL</summary><br><b> |
| 2025 | + |
| 2026 | +The main difference is that SQL databases are structured (data is stored in the form of |
| 2027 | +tables with rows and columns - like an excel spreadsheet table) while NoSQL is |
| 2028 | +unstructured, and the data storage can vary depending on how the NoSQL DB is set up, such |
| 2029 | +as key-value pair, document-oriented, etc. |
| 2030 | +</b></details> |
| 2031 | + |
| 2032 | +<details> |
| 2033 | +<summary>What does it mean when a database is ACID compliant?</summary><br> |
| 2034 | + |
| 2035 | +ACID stands for Atomicity, Consistency, Isolation, Durability. In order to be ACID compliant, the database much meet each of the four criteria |
| 2036 | + |
| 2037 | +**Atomicity** - When a change occurs to the database, it should either succeed or fail as a whole. |
| 2038 | + |
| 2039 | +For example, if you were to update a table, the update should completely execute. If it only partially executes, the |
| 2040 | +update is considered failed as a whole, and will not go through - the DB will revert back to it's original |
| 2041 | +state before the update occurred. It should also be mentioned that Atomicity ensures that each |
| 2042 | +transaction is completed as it's own stand alone "unit" - if any part fails, the whole statement fails. |
| 2043 | + |
| 2044 | +**Consistency** - any change made to the database should bring it from one valid state into the next. |
| 2045 | + |
| 2046 | +For example, if you make a change to the DB, it shouldn't corrupt it. Consistency is upheld by checks and constraints that |
| 2047 | +are pre-defined in the DB. For example, if you tried to change a value from a string to an int when the column |
| 2048 | +should be of datatype string, a consistent DB would not allow this transaction to go through, and the action would |
| 2049 | +not be executed |
| 2050 | + |
| 2051 | +**Isolation** - this ensures that a database will never be seen "mid-update" - as multiple transactions are running at |
| 2052 | +the same time, it should still leave the DB in the same state as if the transactions were being run sequentially. |
| 2053 | + |
| 2054 | +For example, let's say that 20 other people were making changes to the database at the same time. At the |
| 2055 | +time you executed your query, 15 of the 20 changes had gone through, but 5 were still in progress. You should |
| 2056 | +only see the 15 changes that had completed - you wouldn't see the database mid-update as the change goes through. |
| 2057 | + |
| 2058 | +**Durability** - Once a change is committed, it will remain committed regardless of what happens |
| 2059 | +(power failure, system crash, etc.). This means that all completed transactions |
| 2060 | +must be recorded in non-voliatile memory. |
| 2061 | + |
| 2062 | +Note that SQL is by nature ACID compliant. Certain NoSQL DB's can be ACID compliant depending on |
| 2063 | +how they operate, but as a general rule of thumb, NoSQL DB's are not considered ACID compliant |
| 2064 | +</details> |
| 2065 | + |
| 2066 | +<details> |
| 2067 | +<summary>When is it best to use SQL? NoSQL?</summary><br><b> |
| 2068 | + |
| 2069 | +SQL - Best used when data integrity is crucial. SQL is typically implemented with many |
| 2070 | +businesses and areas within the finance field due to it's ACID compliance. |
| 2071 | + |
| 2072 | +NoSQL - Great if you need to scale things quickly. NoSQL was designed with web applications |
| 2073 | +in mind, so it works great if you need to quickly spread the same information around to |
| 2074 | +multiple servers |
| 2075 | + |
| 2076 | +Additionally, since NoSQL does not adhere to the strict table with columns and rows structure |
| 2077 | +that Relational Databases require, you can store different data types together. |
| 2078 | +</b></details> |
| 2079 | + |
| 2080 | +<details> |
| 2081 | +<summary>What is a Cartesian Product?</summary><br> |
| 2082 | + |
| 2083 | +A Cartesian product is when all rows from the first table are joined to all rows in the second |
| 2084 | +table. This can be done implicitly by not defining a key to join, or explicitly by |
| 2085 | +calling a CROSS JOIN on two tables, such as below: |
| 2086 | + |
| 2087 | +Select * from customers **CROSS JOIN** orders; |
| 2088 | + |
| 2089 | +Note that a Cartesian product can also be a bad thing - when performing a join |
| 2090 | +on two tables in which both do not have unique keys, this could cause the returned information |
| 2091 | +to be incorrect. |
| 2092 | +</details> |
| 2093 | + |
| 2094 | +##### SQL Specific Questions |
| 2095 | + |
| 2096 | +For these questions, we will be using the Customers and Orders tables shown below: |
| 2097 | + |
| 2098 | +**Customers** |
| 2099 | + |
| 2100 | +Customer_ID | Customer_Name | Items_in_cart | Cash_spent_to_Date |
| 2101 | +------------ | ------------- | ------------- | ------------- |
| 2102 | +100204 | John Smith | 0 | 20.00 |
| 2103 | +100205 | Jane Smith | 3 | 40.00 |
| 2104 | +100206 | Bobby Frank | 1 | 100.20 |
| 2105 | + |
| 2106 | +**ORDERS** |
| 2107 | + |
| 2108 | +Customer_ID | Order_ID | Item | Price | Date_sold |
| 2109 | +------------ | ------------- | ------------- | ------------- | ------------- |
| 2110 | +100206 | A123 | Rubber Ducky | 2.20 | 2019-09-18 |
| 2111 | +100206 | A123 | Bubble Bath | 8.00 | 2019-09-18 |
| 2112 | +100206 | Q987 | 80-Pack TP | 90.00 | 2019-09-20 |
| 2113 | +100205 | Z001 | Cat Food - Tuna Fish | 10.00 | 2019-08-05 |
| 2114 | +100205 | Z001 | Cat Food - Chicken | 10.00 | 2019-08-05 |
| 2115 | +100205 | Z001 | Cat Food - Beef | 10.00 | 2019-08-05 |
| 2116 | +100205 | Z001 | Cat Food - Kitty quesadilla | 10.00 | 2019-08-05 |
| 2117 | +100204 | X202 | Coffee | 20.00 | 2019-04-29 |
| 2118 | + |
| 2119 | +<details> |
| 2120 | +<summary>How would I select all fields from this table?</summary><br><b> |
| 2121 | + |
| 2122 | +Select * <br> |
| 2123 | +From Customers; |
| 2124 | +</b></details> |
| 2125 | + |
| 2126 | +<details> |
| 2127 | +<summary>How many items are in John's cart?</summary><br><b> |
| 2128 | + |
| 2129 | +Select Items_in_cart <br> |
| 2130 | +From Customers <br> |
| 2131 | +Where Customer_Name = "John Smith"; |
| 2132 | +</b></details> |
| 2133 | + |
| 2134 | +<details> |
| 2135 | +<summary>What is the sum of all the cash spent across all customers?</summary><br><b> |
| 2136 | + |
| 2137 | +Select SUM(Cash_spent_to_Date) as SUM_CASH <br> |
| 2138 | +From Customers; |
| 2139 | +</b></details> |
| 2140 | + |
| 2141 | +<details> |
| 2142 | +<summary>How many people have items in their cart?</summary><br><b> |
| 2143 | + |
| 2144 | +Select count(1) as Number_of_People_w_items <br> |
| 2145 | +From Customers <br> |
| 2146 | +where Items_in_cart > 0; |
| 2147 | +</b></details> |
| 2148 | + |
| 2149 | +<details> |
| 2150 | +<summary>How would you join the customer table to the order table?</summary><br><b> |
| 2151 | + |
| 2152 | +You would join them on the unique key. In this case, the unique key is Customer_ID in |
| 2153 | +both the Customers table and Orders table |
| 2154 | +</b></details> |
| 2155 | + |
| 2156 | +<details> |
| 2157 | +<summary>How would you show which customer ordered which items?</summary><br><b> |
| 2158 | + |
| 2159 | +Select c.Customer_Name, o.Item <br> |
| 2160 | +From Customers c <br> |
| 2161 | +Left Join Orders o <br> |
| 2162 | + On c.Customer_ID = o.Customer_ID; |
| 2163 | + |
| 2164 | +</b></details> |
| 2165 | + |
| 2166 | +<a name="sql-advanced"></a> |
| 2167 | +#### Advanced |
| 2168 | + |
| 2169 | +<details> |
| 2170 | +<summary>Using a with statement, how would you show who ordered cat food, and the total amount of money spent?</summary><br><b> |
| 2171 | + |
| 2172 | +with cat_food as ( <br> |
| 2173 | +Select Customer_ID, SUM(Price) as TOTAL_PRICE <br> |
| 2174 | +From Orders <br> |
| 2175 | +Where Item like "%Cat Food%" <br> |
| 2176 | +Group by Customer_ID <br> |
| 2177 | +) <br> |
| 2178 | +Select Customer_name, TOTAL_PRICE <br> |
| 2179 | +From Customers c <br> |
| 2180 | +Inner JOIN cat_food f <br> |
| 2181 | + ON c.Customer_ID = f.Customer_ID <br> |
| 2182 | +where c.Customer_ID in (Select Customer_ID from cat_food); |
| 2183 | + |
| 2184 | +Although this was a simple statement, the "with" clause really shines is when |
| 2185 | +a complex query needs to be run on a table before joining to another. With statements are nice, |
| 2186 | +because you create a pseudo temp when running your query, instead of creating a whole new table. |
| 2187 | + |
| 2188 | +The Sum of all the purchases of cat food weren't readily available, so we used a with statement to create |
| 2189 | +the pseudo table to retrieve the sum of the prices spent by each customer, then join the table normally. |
| 2190 | +</b></details> |
| 2191 | + |
2008 | 2192 | ## Scenarios
|
2009 | 2193 |
|
2010 | 2194 | Scenarios are questions which don't have verbal answer and require you one of the following:
|
|
0 commit comments