Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Integrity An empty database is a correct database.

Similar presentations


Presentation on theme: "Data Integrity An empty database is a correct database."— Presentation transcript:

1 Data Integrity An empty database is a correct database

2 Overview Review Domains What are integrity constraints? Gulf between the theory and the implementation Testing insertions into database? NULLS

3 Review Tuple Cardinality Attribute Degree Domain

4 Domains Conceptual pool of values from which one or more columns draw their values Named set of scalar values all the same type –scalar is smallest semantic unit of data, individual data value CREATE DOMAIN …? ? Domain contains ALL permitted values, static Which relations in the database contain any information pertaining to suppliers?

5 Comparisons with Domains Domains constrain comparisons, =,<> domain-check override Codd Logically equivalent statements must have same semantic interpretation Logic cannot be nullified a = cT b = c T a = bF Arithmetic operators

6 Data Types Hide complexity within domain DATE domain –three integers (d,m,y) –interpreted by operators Address domain –USA - street, city, state, zip

7 ADT in Oracle Simulate a domain CREATE TYPE ADDR_TY AS OBJECT –(STREETVARCHAR2(50), –CITYVARCHAR2(25), –STATECHAR(2), –ZIPVARCHAR(9)); CREATE TABLE NEW_CUSTOMER –( CUSTID VARCHAR2(9) PRIMARY KEY, –CUST_NAME VARCHAR2(25), –ADDRESS ADDR_TY);

8 Relations Abstract object A relation, r, on a collection of domains, D1, D2 …Dn consists of two parts a heading and a body –heading - fixed set of attributes, pairs –body - set of tuples, pairs Named relation is really a variable Relations dynamic Table is concrete picture

9 Candidate Keys Subset of all attributes that are –Unique –Irreducibile Does not relate to current data set but to set of ALL POSSIBLE values –simple –composite Provide tuple-level addrressing mechanism Primary key is selected from candidate key. Others called Alternate keys

10 Is our information Correct ? Consistent ? Logical ?

11 Start with a consistent database Update the database Result a consistent database

12 Is the data consistent? t Is the data consistent between tables? t Are the same values equivalent? t Do foreign keys reference existent primary keys? t Has logical consistency been maintained? t Have the business rules been enforced? t All constraints valid?

13 How do we maintain correct, consistent data ? t Data Integrity Rules –Candidate keys –Domains t Referential Integrity Rules –Foreign keys t Business Rules –Constraints –Stored Procedures, Triggers

14 Where do we maintain correct, consistent data ? Database creation –base tables –views Implementation –back end –front end applications –middleware Integrity rules are database specific

15 Foreign Keys If the foreign key contains either matching values or nulls, the table(s) that make use of such a foreign key are said to exhibit referential integrity. An attribute in one table refers to a primary key in another table –can it be a candidate key? –can it be the same table? A FK is composite if the primary key is composite.Referential Integrity assures that no invalid foreign keys permitted Relationships formed through foreign keys but not exclusively

16 Maintaining Integrity with Foreign Keys Correct DB Transform thru update Delete Parent restrict cascades Update Parent restrict cascade How many levels of cascade? Define procedures Note: Correct database satisfies logical AND of all known rules

17 Entity Integrity No component of the primary key of a base relation is allowed to accept NULLS. In a relational database, we never record information about something we cannot identify. No attribute included in composite primary key can be NULL. Can alternate keys have NULLS?

18 Null Foreign Keys Can a foreign key be null? –definition - matches primary key or is null Can a composite foreign key have some attributes null? ON DELETE SET NULL –allows child record to remain but deleted key attribute becomes null

19 Rules or Constraints Theory –CREATE INTERGIRTY RULE PR4 FORALL PX(PX.WEIGHT>0) ON ATTMPTED VIOLATION REJECT; Oracle –CREATE TABLE PX... WEIGHT NUMBER CONSTRAINT PR4 CHECK (WEIGHT >0); Components name, truth-statement, violation response

20 Relation Rules or Constraints Theory –CREATE INTERGIRTY RULE SR8 FORALL S(IF S.CITY = ‘LONDON’ THEN S.STATUS = 20) ON ATTMPTED VIOLATION REJECT; Oracle Must be closed WFF

21 Database Rules CREATE INTEGRITY RULE C95 –FORALL SX (FORALL SPX –(IF SX.STATUS < 20 AND –SX.S# = SPX.S# –THEN SPX>QTY <=500)); Oracle Note required join condition

22 Database Rules How do we execute the following: –For every orderline there must exist an order. –Every customer must place an order. –No salesrep can have more than 200 customers. –Every orderline must contain a valid part. When do we execute

23 Transition Rules Applied as go from one state to another Employee marries CREATE INTEGRITY RULE S12 –IF S’.S# = S.S# THEN –S’.STATUS < S.STATUS;


Download ppt "Data Integrity An empty database is a correct database."

Similar presentations


Ads by Google