mode 2 SQL Flashcards
What is SQL?
Structured Query Language
It’s a syntax used to communicate with the database (DBMS)
Types of SQL Languages:
- PostgreSQL
- Oracle SQL (aka PL/SQL)
- MySQL
- SQL Server
- etc
What…..are the sublanguages of core SQL?
DML, DDL, DQL, DCL, TCL
What is DML?
> 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
What is DDL?
> 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)
What is DQL?
> 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
What is DCL?
> DCL - Data Control Language
»DCL controls WHO has access to your data
»keywords: GRANT, REVOKE
What is TCL?
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"
What is a transaction?
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
what is rollback?
the rollback will delete changes back to the most RECENT commit
what is savepoint?
Savepoint creates checkpoints that you can rollback to without rolling back EVERYTHIGN since the last commit
What are the properties of a transaction?
The ACID properties
The ACID properties?
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
DATATYPES IN POSTGRESQL:
- Integer, varchar, timestamp, date, numeric, serial, bigserial, smallserial, bigint, smallint
- text, etc
What are constraints?
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