Reading List

advertisement
IST 318 – Spring 2013
Reading List
1. What is DBA? (online at Amazon.com)
[Chapter 1 – Mullins, Database Administration, 2nd Ed ]
a. Data, DB, DBMS, RDBMS; and What functions does a DBMS provide?
b. DBA, DA, and SA
c. DBA tasks
d. Types of DBAs
e. Impacts of newer technologies: cloud, NoSQL, Big Data, eDBA
2. RDBMS: An Introduction (handout)
[Chapter 1 – Petkovic, Microsoft SQL Server 2012: A Beginner’s Guide, 5th Ed]
a. DB, DBMS, DB Apps; and logical independence, physical independence
b. Client-server set up; and various client tools/GUIs
c. Relational data model: relation (table: both define and store data) and relationship
d. Using the Management Studio GUI to login, create tables, insert data, view data, etc
3. An Intro to (RDB and) SQL
[Chapter 1 – Syverson & Murach, SQL Server 2013 for Developers]
a. Review concepts mentioned in two previous classes: using charts and definitions
b. A brief history of SQL; T-SQL and SQL
c. Intro to SQL statements
i. DDL: Create and alter table
ii. DML (for CRUD operations)
1) Queries: select data from 1 or more tables (join); clauses
2) Updates: add, update, and delete data
d. A broader view: other DB objects; DB app programming
4. Lab 1 – Basic SQL syntax and essential language components
[The sample DB from Petkovic/ch1; SQL statements from Syverson&Murach/ch1; and
language elements & data types from Petkovic/ch4]
a. DML basics: CRUD
i. SELECT and FROM clauses: mandatory and always the first two
ii. WHERE clause: usually needed though not required
iii. ORDER BY: needed for sorting results; can use multiple sorting rules
iv. INSERT INTO tablename [(…)] VALUES (…)
v. UPDATE tablename SET column = new_value [, column2 = new_value2 …]
[WHERE…]
vi. DELETE FROM tablename [WHERE …]
b. DDL – table management
i. CREATE TABLE tablename ()
ii. ALTER TABLE tablename ADD|DROP|ALTER
iii. DROP TABLE tablename
c. Language components
1
i.
ii.
iii.
iv.
5.
6.
7.
8.
9.
Literals (or constants): ‘textual’, 123 (numerals)
Reserved keywords & naming convention
Comments: /* … */ (multiple lines); -- (single-line)
Data types
1) Numeric: INTEGER/SMALLINT; DECIMAL/NUMERIC(p[, s])
2) Character: CHAR[(n)]; VARCHAR(n); NCHAR/NVARCHAR(n)
3) Temporal: DATETIME/DATE/TIME
4) Other misc.: binary, large object, CURSOR, XML, spatial, TIMESTAMP
SELECT with conditions and from more than one table
a. Calculation terms in select clause
b. ORDER BY: more examples
c. WHERE: ways to specify conditions
i. Comparison: =,>,<, and BETWEEN … AND
ii. IN (…, …[, …])
iii. LIKE: with wildcard character
1) % representing any number of (0 to many) characters
2) _ representing any single character
d. JOIN syntax
i. Freestyle
ii. Using JOIN keyword
Lab 2 – Joining tables
DB design
a. Entity and Relationship; ER modeling
b. Converting ERM into Table Schemas
c. The ADLC
Lab 3 – DB analysis and design
Aggregation
a. Aggregate functions: max, min, sum, average, and count
b. New clauses in SELECT statement: GROUP BY and HAVING
i. When a normal expression and an aggregate term are listed in a SELECT clause,
the normal term must appear in the GROUP BY clause

SELECT state, COUNT(customer#)
FROM customers
GROUP BY state;
ii. All conditions applicable for groups should be included in the HAVING clause (in
aggregate terms only), whereas general conditions in the WHERE clause

SELECT state, COUNT(customer#)
FROM customers
WHERE referred > 0 /* may also use IS NOT NULL */
GROUP BY state
HAVING COUNT(customer#) >= 10;
10. Lab 4 – Group Functions
11. Built-in functions
2
a. Math functions: round, abs, ceiling/floor, sqrt/square
b. String functions:
i. Extractors: left, right, substring, ltrim, rtrim
ii. Case changers: upper, lower
iii. String info: len, charindex
c. Date functions: dateadd, datediff, datepart, year/month/day, getdate
d. Other function: case, convert/cast
Follow the link below to access resources at SQLServerPedia.com for Aggregate and other
functions used in SQL Server
http://sqlserverpedia.com/wiki/Built-in_Functions_-_Aggregate_Functions#More_SQL_Server_Functions
12. Lab 5 – Built-in Functions
13. Creating tables and setting constraints
a. Five types of constraints
i. PRIMARY KEY: implies NOT NULL and UNIQUE; may have one in a table
ii. NOT NULL: used for “required” fields; specified using in-line style
iii. UNIQUE: also known as “candidate key”; may be consist of one or more fields
iv. CHECK: for specifying value range or set of legal values
CHECK (condition)
v. FOREIGN KEY: must refer to a PK or UQ in another table (or the same table for a
recursive relationship) [The only inter-table constraint]
[FOREIGN KEY] REFERENCES table_name (ref_col_nm1[, ref_col_nm2…])
[ON DELETE {CASCADE|NO ACTION}]
[ON UPDATE {CASCADE|NO ACTION}]
b. Two ways to set constraints
i. During table creation
ii. After a table is created by using the ALTER TABLE statement to add constraint
c. Two places to add a constrain
i. In-line style: add the constraint keyword right after data type is specified
 Cannot be used for PK/UQ/FK that consist of multiple columns
ii. At table level: use the CONSTRAINT keyword followed with one of 5 types
 May optionally provide a constraint-name
 Naming convention for a constraint-name is:
PK|NN|UQ|FK|CK__table_name__column_name
b. Syntax for the ALTER TABLE statement
i. ALTER TABLE table_name ADD|DROP
 ALTER TABLE Vendors
ADD LastTransDate SMALLDATETIME; // add a column
 ALTER TABLE Vendors
DROP COLUMN LastTransDate; // drop a column
 ALTER TABLE Invoices
ADD CHECK (InvoiceTotal >= 1); // add a constraint
3
ii. ALTER TABLE table_name ALTER COLUMN
 ALTER TABLE InvoiceLineItems
ALTER COLUMN InvoiceLineItemDesc VARCHAR(200); // modify data
type for a column
14. Lab 6 - Creating tables and setting constraints
15. Subqueries
a. SELECT statements used in another SQL statement (CRUD)
b. Used in a SELECT statement
i. In WHERE clause
ii. In HAVING clause
iii. In FROM clause
iv. In SELECT clause
c. Returns one value
i. May use comparison operators: =, >, <
d. Returns multiple values
i. Need to use ALL, SOME/ANY with comparison operators
ii. May use IN
16. Lab 7 - Subqueries
17. Views
a. What is a view: a DB object that embeds a SELECT statement
i. Referring to data in the base table(s) (those appear in its FROM clause)
ii. A virtual table never really has data physically stored in it
iii. Reflects the current data: contents of the virtual table gathered when executed
b. Why using views: relational tables are normalized – not necessarily in ways how the end
users see data  use views can organize data to fit specific user needs
i. View can be used in the FROM clause just as a normal (physical) table
ii. Used to restrict data: a view can be made to show only the insensitive data
iii. Embed a (complex) SELECT statement and don’t have to write it all the time
c. How to create a view:
i. use the CREATE VIEW statement
CREATE VIEW view_name AS SELECT … //everything we discussed can go here
// Or provide column names in view with …
CREATE VIEW view_name (col_1, …, col_n) AS SELECT …
ii. use the View Designer: right mouse on Views and then select New View
d. How to use a view to update: generally speaking, it’s not a good idea
i. First need to make sure the view is updatable, i.e. it include PK in base table(s)
1. And do NOT include: calculated term, aggregate terms, DISTINCT, TOP
2. Views that don’t meet the requirements above are read-only
ii. Can only affect (CUD) record(s) in one (of the) base table(s)
e. SQL Server catalog views
18. Lab 8 – Views
19. Selected topic: C# ADO programming
4
20.
21.
22.
23.
Lab 9 – Windows Form Programming
Other DB objects, such as sequence, index, etc.
Security: user & role management
Another DB system: MySQL/PostgreSQL/MongoDB/HBase (TBD)
5
Download