Exam 2 Flashcards
LIKE wildcards
_ single char, % multichar
Get all employee last names starting with G
SELECT EmpLast FROM EMPLOYEE WHERE EmpLast LIKE ‘G%’;
Sort all employee records by first name
SELECT * FROM EMPLOYEE ORDER BY EmpFirst ASC;
Using EMPLOYEE, display a count of employees (‘EmpNum’) in each department that has more than 4 employees
SELECT DeptID, COUNT() AS EmpNum FROM EMPLOYEE GROUP BY DeptID HAVING COUNT() > 3;
What’s a view?
A virtual table created from SELECT statements on other tables/views that has no data of its own.
Why use a view?
To hide columns or rows, assign different permissions to different views, display computation results, hide messy JOINS, and layer built-in functions.
DML 3 syntax
INSERT UPDATE DELETE
DDL 3 syntax
CREATE ALTER DROP
Add record with EmpID = 62 and SalaryCode = 11 to EMPLOYEE
INSERT INTO EMPLOYEE (EmpID, SalaryCode) VALUES (62, 11);
Best practices for redesign?
Understand the current db, backup errything, and test changes on a test db
Dependency graphs
Diagrams portraying dependencies of elements (tables, views, triggers) on each other
Diagrams portraying the relationships between tables/views/triggers
Dependency graphs
How to add a NOT NULL col to an existing table
1–Add col as NULL 2–Add data to every row 3–ALTER to NOT NULL
Turning 1:1 into 1:N
Remove UNIQUE constraint on FK, or move FK to the other table (w/ no UNIQUE)
Turning 1:N into N:M
Make an intersection table!
Turning N:M into 1:N
Put FK in parent and move values from intersection to there
Turning 1:N into 1:1
Remove duplicates in FK and make it UNIQUE
Indices
Structures to improve db performance. Contains a copy of some table data.
B-tree
Root/branch/leaves; way to do indices.
Clustered Index
Table sorted to match–can only be 1.
Index where table is sorted to match
Clustered Index
Unclustered Index
Unsorted rows in heap
Index with unsorted rows in heap
Unclustered Index
API
Application Programming Interface. Collection of obj/meth/props.
ODBC
Open DB Connectivity. API standard for DBMS-independent way to process relational db data.
ODBC data source
A db, dbms, and its hardware. Could even be a spreadsheet!
Driver manager
Intermediary between app and DBMS drivers. Determines type of DBMS for a data source and loads the right driver.
Driver
Processes requests and submits them to the data source. Can also process requests for shit sources, and translate errors.
SQL/PSM
Persistent Stored Modules. Standard for embedding procedural prog. funct. Adds user-def fns, triggers, and stored procedures.
User-defined functions
Called by name from a statement. Returns an output value.