sql Flashcards
- What is SQL and how is it different from languages like JavaScript?
a. Structured Query Language (SQL) is the primary way of interacting with relational databases.
b. It is a powerful way of retrieving, creating, and manipulating data in a relational database.
c. Difference: JavaScript is an imperative language while because SQL is a declarative language
- How do you retrieve specific columns from a database table?
a. Use the select keyword followed by the “columns” in double quotes, separated by commas.
- How do you filter rows based on some specific criteria?
a. Use the “where” keyword followed by a condition you are looking to compare or match.
- What are the benefits of formatting your SQL?
a. Cleaner and easier to read
- What are four comparison operators that can be used in a where clause?
a. “=” / “ < ” / “ > ” / “ != ”
- How do you limit the number of rows returned in a result set?
a. Use the limit keyword
- How do you retrieve all columns from a database table?
a. Replace the list of column names with an asterisk ( * )
i. The order of the results is NOT predictable.
ii. The asterisk is NOT in quotes.
- How do you control the sort order of a result set?
a. Use the order by keywords, followed by desc or asc abbreviated keywords without double quotes.
- How do you add a row to a SQL table?
a. Use the INSERT statement
- What is a tuple?
a. Tuples are unordered sets of known values with names.
b. Tuple is often referred to as rows in a relational database model.
c. They are effectively a data structure like an array – New Tim.
- How do you add multiple rows to a SQL table at once?
a. Data rows can be batch inserted into a database table by specifying more than one tuple of values, separated by commas.
- How do you get back the row being inserted into a table without a separate select statement?
a. returning *;
b. sometimes you don’t need to use the return keyword and can specify the columns.
- How do you update rows in a database table?
a. Use the ‘UPDATE’ statement
- Why is it important to include a where clause in your update statements?
a. If you don’t use a WHERE statement, it will updated EVERY row in the table.
b. Great care must be taken to include a “WHERE” clause in order to ONLY target specific rows.
- How do you delete rows from a database table?
a. Use the “DELETE” statement