Professional Documents
Culture Documents
Review
The Big 3 categories
DML = manipulation (adding, deleting, modifying rows)
DCL = controlling access
DDL = creating tables, etc
this is where we are in Chapter 7
Database specific?
How much difference is there?
DML is the most common between vendors
DDL is probably the next most common
er, well... using ISO data types
DDL Statements
Create Table, p327
Create Table TableName (
3-part column definition,
optional table contraints
)
Table Contraints
Primary Key, Foreign Key, Unique
each constraint has a name!
Column/Data constraints
NULL/NOT NULL, Check
FK constraints actions
No Action (the default)
so, what happens if there is a RI violation?
Cascade
so, what happens if you delete the parent with "on delete
cascade"?
Set Null
Set Default
Relationships, p334
* fig 7-10, p334
Mostly a review from Chapter 6
... only thing added is the "unique" constraint
Unique vs PK
Defaults, 335
in MSSQL.. after NULL/NOT NULL
but I'd hardly call them a column/data "constraint"?!?!?!
Can also be done via a table constraint
skip a bit...
So, what about FKs (in child tables) that point to this parent table?
Truncate, p341
whack only the data
does this affect RI differently that a drop????
Index, p341
Index helps speed up queries...
it's all about the "where" clause
what about update and deletes?
kinda depends on the complexity of the where clause
what about inserts?
So, 3 separate inserts using a constant as the value for the 2nd
column
...and the specific version of the phone column we want
Update, p349
Update Student Set Major=10
Where StudentID = 1
Carefull... I'd suggest that you do a "dry run" with a Select statement
first
what happens if you don't have a "where" clause?
Multiple items
column / value pairs
separate by commas
Merge, p350
skip...
Delete, p351
Delete from Student
where StudentID=1
Update Student
set Active=1
So, now instead of deleting a record... you just change the Active to 0
Update Student
set Active=0
where StudentID=1
During transition, I can rename tables, and use views (with the old
names)
until everything has been ported over.
You'll need to know how to create views for the Term Project
Skip a bit...
Programming... 362
I'll keep this to a minimum...
Functions, p364
Sometimes called a "User Defined Function" (UDF)
3 types... scalar, inline table-valued, multi-statement table-valued
so what's a scalar?
what's the difference between a "scalar" and "vector aggregate"?
A scalar used with group by is called a aggregate
1) Notice that a "table function" is used via the Select clause just like a
table
Types:
before (not MS SQL)
after
instead of
Use:
defaults values
data contraints
business rules
discount based upon size of order
must have exactly 4 items...
update views
RI
that can't be done normally
Delete the department row when no more employees assigned???
Use:
Surgical application of security
you don't have write permission on a table,
but you have execute permission on SP!
Very common!!!!
Optimization
this used to be a big advantage... not so much now
Hiding complexity
Application programming
all business logic in one place (not distributed between code and
DB)
Triggers vs SP
* fig 7-30, 375
Advantages of SP
* fig 7-31, 375
Comparison, p376
Functions, triggers, SPs
* fig 7-33
hint, hint...