文档介绍:Chapter 6: Integrity and Security(完整性与安全性)
Domain Constraints(域约束)
Referential Integrity(参照完整性)
Assertions(断言)
Triggers(触发器)
Security(安全性)
Authorization (授权)
Authorization in SQL(SQL中的授权)
Domain Constraints
Integrity constraints guard against accidental damage to the database, by ensuring that authorized changes to the database do not result in a loss of data consistency.
Domain constraints are the most elementary form of integrity constraint.
They test values inserted in the database, and test queries to ensure that parisons make sense.
New domains can be created from existing data types
. create domain Dollars numeric(12, 2) create domain Pounds numeric(12,2)
We cannot assign pare a value of type Dollars to a value of type Pounds.
However, we can convert type as below (cast as Pounds)
Domain Constraints (Cont.)
The check clause in SQL permits domains to be restricted:
Use check clause to ensure that an hourly-wage domain allows only values greater than a specified value.
create domain hourly-wage numeric(5,2) constraint value-test check(value > = )
The domain has a constraint that ensures that the hourly-wage is greater than
The clause constraint value-test is optional; useful to indicate which constraint an update violated.
Can plex conditions in domain check
create domain AccountType char(10) constraint account-type-test check (value in (‘Checking’, ‘Saving’))
check (branch-name in (select branch-name from branch))
Referential Integrity
Ensures that a value that appears in one relation for a given set of attributes also appears for a certain set of attributes in another relation.
Example: If “Perryridge” is a branch name appearing in one of the tuples in the account relation, then there exists a tuple in the branch relation for branch “Perryridge”.
Formal Definition
Let r1(R1) and r2(R2) be relations with primary keys K1 and K2 respectively.
The subset of R2 is a foreign key referencing K1 in relation r1, if for every t2 in r