SQL 2 Flashcards
AWS
Provides a platform as a service
You buy the services you need, Amazon houses and maintains it
AWS and GoDaddy are essentially the same service, but AWS is a little more robust. AWS is very granular in service, lots of configurability, load balancing. More control over what happens behind the scenes. GoDaddy is more out-of-the-box.
Database
A collection of data stored as related entities or tables with entries expressed as rows.
Distributed Architectures
keeping everything in one related model.
Multiplicity
Multiplicity (a.k.a Cardinality) - description of relationships between fields and tables
1-1
1-Many
Many-Many
1-1
Person-to-SSN
1-Many
Teacher-to-students
Person-to-toes
Car-to-people (if you’re carpooling)
Many-Many
Authors-to-books
Students-to-courses
Users-to-websites
WHY Referential Integrity
You want relationships between tables to remain consistent when entries are changed. If we delete the Checking Account in the above table, Craig’s AcctID (Foreign Key) will point to something that no longer exists.
All Foreign Keys should match to the correct value.
Entity Relation Diagram (ERD)
lets you map out the relationships between different entities in a database.
DOES SQL AUTO COMMIT
SQL Developer does not auto-commit, so if you want to commit, click the little green checkmark button.
JDBC
Java Database Connectivity
Package that all this stuff comes in is java.sql.
Exceptions: SqlException
JDBC INTERFACES
Connection
Statement
ResultSet
Connection
A session with a particular database.
Obtained from the DriverManager object.
We’re going to give our DriverManager the URL, Username, Password to our database, and it’ll give us the type of connection we need..
Statement
If we want to execute a query or use our tables.
Takes a raw string and executes it as an SQL query.
Don’t use this. It’s BAD. We’re worried about SQL injections, and Statements make it very easy to perform SQL injections. You can have malicious code injected, since it’s a raw query.
Forms the backbone for other statements.
ResultSet
Not actually a Connection, but it behaves similarly to a Connection.
Table of results returned by execution of SQL query.
Also maintains a cursor which starts off pointing to the first row.
Has a method called next() which moves the cursor to the next row. Similar to an Iterator. Does not contain a hasNext() method, but it next() returns a boolean, so it can be used as an argument within a while-loop condition.
DAO Design Pattern
Data Access Object
Modularity and loose coupling
You want to make absolutely sure that the only thing that is interacting with your database is your DAOImpl.
DAO is an open interface with multiple implementations
Query
Operation that retrieves data from one or more tables or a view.
Top level SELECT statement
Query Makeup
SELECT [column list] -Required FROM [table list]-Required WHERE [condition1] AND[condition2]... GROUP BY [column list] HAVING [condition] WHERE HAVING clause places conditions on groups created by the GROUP BY clause Aggregate ORDER BY [column list] Default is ascending DESC for descending
GROUP BY
Groups your result set so far. Wide to narrow. Aggregate functions (avg, Max,min,etc)
HAVING
HAVING clause when used with the GROUP BY clause in a query tells the GROUP BY which groups to include in the output
Aggregate
ORDER BY
Default is ascending
DESC for descending