SQL Flashcards

1
Q

What is a database?

A

Collection of data, a method for accessing and manipulating that data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

DBMS
RDBMS
SQL

A

Database Management System
Relational DBMS
Structured Query Language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Types of DBs

A
  1. Relational – works well with SQL
  2. Document – MongoDB, CouchBase, FireBase
  3. KeyValue – Redis, DynamoDB
  4. Graph – Neo4j, Nephew - for social media looking at relations.
  5. Wide Columnar – BigTable, Apache Cassandra
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Query?

A

Instructions for the RDBMS that will return us output.

SQL is a declarative language.
– What will happen?

Imperative:
– How will happen?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Database Models

A
Hierarchial - IBM 60s 70s - One-to-many -- XML
Networking - Many-to-many
Entity-Relationship
Relational
Object Oriented
Flat
Semi-Structured
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

CRUD Operation

A

Create
Read
Update
Delete

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

DBMS Functions

A
  • Management of Data
  • Encryption
  • Transaction Management
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Relational Model

A

Relation Schema
Attribute - data in a cell
Degree - collection of all columns
Cardinality - collection of all rows
Tuple/Row - a single set of data
Column - may or may not store a specific type of data
Relation Key
– Primary key - uniquely identifies a row
– Foreign key - reference primary key of another table
Domain/Constraint - what kind of data can be stored in a column
Table - collection of tables and rows
Relation Instance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

OLTP

OLAP

A

Online Transaction Processing - Day to day business

Online Analytical Processing - Predict/Analyse

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

\du

A

List role names and attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

DCL
DDL
DQL
DML

A
Data Control Language
-- Grant
-- Revoke
Data Definition Language
-- Create
-- Alter
-- Drop
-- Rename
-- Truncate
-- Comment
Data Query Language
-- Select
Data Modification Language
-- Insert
-- Update
-- Delete
-- Merge
-- Call
-- Explain Plan
-- Lock Table
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Change name of a column

A

select title as “JOB TITLE” from titles where emp_no = 10006

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Concat two columns and print in a custom column

A

select CONCAT(first_name, ‘ ‘, last_name) AS “Employee Name” from employees

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Function in SQL

A

e.g. CONCAT

Receives an input and generates an output.

    • Aggregate - receives multiple values and generates 1 output.
  • —AVG
  • —COUNT
  • —MIN
  • —MAX
  • —SUM
    • Scalar - runs against each row and generates multiple output.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Youngest employee in the table

A

select * from employees order by birth_date ASC limit 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Common mistakes with SQL

A
  1. Spelling error
  2. Misplacing ; and ,
  3. Use double commas
  4. Using “ instead of ‘
  5. Invalid column name.

” for Tables
‘ for Strings

17
Q

Order of operations

A
FROM
  |
WHERE
  |
SELECT

AND is chained with previous query
OR starts a new search
NOT

Comparison operators:
>
<
>=
<=
!=
=
'abc' > 'ace'   -- true

Logical Operators:

18
Q

Operator Precedence

A
()
*/
-+
NOT
AND
OR