sql Flashcards
(24 cards)
Standard numerical operators
=, !=, < <=, >, >=
Number is [not] within range of two values (inclusive)
… WHERE col_name [NOT] BETWEEN … AND …;
Number exists in a list
… WHERE col_name IN (2, 4, 6);
Number does not exist in a list
… WHERE col_name NOT IN (1, 3, 5);
Case sensitive exact string [inequality] comparison
… WHERE col_name [!]= “abc”;
Case insensitive exact string [inequality] comparison
… WHERE col_name [NOT] LIKE “abc”;
Match a single character
… WHERE col_name [NOT] LIKE “_bc”;
String [does not] exists in a list
… WHERE col_name [NOT] IN (“A”, “B”, “C”);
Match a sequence of zero or more characters
… WHERE col_name [NOT] LIKE “%abc”;
Database normalization is useful because
minimizes duplicate data in any single table, and allows for data in the database to grow independently of each other
Database normalization is useful because
minimizes duplicate data in any single table, and allows for data in the database to grow independently of each other
Database normalization trade-off
Queries get slightly more complex since they have to be able to find data from different parts of the database, and performance issues can arise when working with many large tables.
inner join - only contains data that belongs in both of the tables
SELECT title, domestic_sales, international_sales
FROM movies
INNER JOIN boxoffice ON movies.id=boxoffice.movie_id;
Stored procedure
Create once, store and call for several times whenever it is required, it can be executed only in the database and utilizes more memory in the database server.
A view
A virtual table, Restricting access to data, Making complex queries simple.
Alias
A name given to table or column.
‘HAVING’ CLAUSE and a ‘WHERE’ CLAUSE
Having Clause is only used with the GROUP BY function in a query whereas WHERE Clause is applied to each row before they are a part of the GROUP BY function in a query.
MERGE statement
UPDATE if a row exists, or an INSERT if the row does not exist.
What is the need for group functions in SQL?
Group functions work on the set of rows and returns one result per group. AVG, COUNT, MAX, MIN, SUM
“Trigger” in SQL
Stored procedures that are defined to execute automatically in place or after data modifications.
ACID
Atomic: all or nothing,
Consistency: (?)
Isolation: concurrency controll
Durability: after commit you have it
Normalization
Organizing data to avoid duplication and redundancy:
1NF, 2, 3
DROP and TRUNCATE
no rollback, deletes a tables rollback, deletes all rows
Index
Performance tuning method of allowing faster retrieval of records from the table.