mode 2 SQL Flashcards

1
Q

What is SQL?

A

Structured Query Language

It’s a syntax used to communicate with the database (DBMS)

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

Types of SQL Languages:

A
  • PostgreSQL
  • Oracle SQL (aka PL/SQL)
  • MySQL
  • SQL Server
  • etc
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What…..are the sublanguages of core SQL?

A

DML, DDL, DQL, DCL, TCL

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

What is DML?

A

> DML - Data Manipulation Language
»DML operates on records/data
»These are the CRUD methods: create, read, update, delete
»keywords: INSERT, SELECT, UPDATE, DELETE
(c) (r) (u) (d)
»DML needs to be commited, the other sublanguages are generally AUTOCOMMIT

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

What is DDL?

A

> DDL - Data Definition Language
»DDL operates on schema
»The “schema” refers to your DB’s structures (aka its containers like tables, views, etc)
»keywords: CREATE, ALTER, DROP, TRUNCATE
(c) (u) (d)

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

What is DQL?

A

> DQL - Data Query Language
»Request data from the table
»Some DBs consider select as its own sublanguage
»keywords: SELECT
»SELECT column1 FROM tableA WHERE attr1 = value

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

What is DCL?

A

> DCL - Data Control Language
»DCL controls WHO has access to your data
»keywords: GRANT, REVOKE

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

What is TCL?

A
TCL - Transaction Control Language
	>>TCL deals with creating "transactions" and persisting data
	>>keywords: COMMIT, SAVEPOINT, ROLLBACK
	>>COMMIT is like "git commit"
	>>ROLLBACK is like "git stash"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a transaction?

A

it’s a commit; a change to the state of the database (or group of changes)
>example
insert (2record); delete (5records); update
(9records); commit;

how many transactions have occured?
>1 transaction has occurred
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is rollback?

A

the rollback will delete changes back to the most RECENT commit

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

what is savepoint?

A

Savepoint creates checkpoints that you can rollback to without rolling back EVERYTHIGN since the last commit

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

What are the properties of a transaction?

A

The ACID properties

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

The ACID properties?

A

Atomicity
»“all or nothing”; a transaction cannot be broken down any further into separate parts

> Consistency
»after a transaction the state of your schema is intact
»the data should LOGICALLY be consistent; there shouldn’t be a mix of old and new data.

> Isolation
»transactions cannot interfere with one another

> Durability
»changes you make to the state of the DB persists

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

DATATYPES IN POSTGRESQL:

A
  • Integer, varchar, timestamp, date, numeric, serial, bigserial, smallserial, bigint, smallint
  • text, etc
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are constraints?

A

CONSTRAINTS: they are restrictions on the data that can be entered into a column; or to think of it another way, they are conditions that have to be met

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

What is a primary key(pk)?

A

PRIMARY KEY (PK) irepresents the official unique identifier for the record

Primary key is a combination of unique and not null
* >Additional note: you should probably NEVER change your PK, not because it isn’t possible but because it’s dangerous.

17
Q

What is Foreign Key(FK)?

A

FOREIGN KEY (FK) is a reference pointer to another table’s PK

FK does not have to be not-null and unique (but it does have to exist)

example syntax
	FOREIGN KEY (refAttr_from_THIS_table) REFERENCES other_table (PK_column_from_other_table)
18
Q

What is unique?

A

UNIQUE ensures that any two records will NOT have the same value in this column

19
Q

What is not null?

A

NOT NULL ensures that the record DOES have a value in this column (can’t be null)

20
Q

What is check?

A

CHECK ensures that the records meet a certain condition

example syntax
CONSTRAINT constraint_name CHECK (column_amount>15)