Presentation is loading. Please wait.

Presentation is loading. Please wait.

DBMS Spring 2014 Database Integrity Sources: Security in Computing, Pfleeger and Pfleeger, Prentice Hall, 2003 Lecture Slides, CSE6243, MSU, Rayford B.

Similar presentations


Presentation on theme: "DBMS Spring 2014 Database Integrity Sources: Security in Computing, Pfleeger and Pfleeger, Prentice Hall, 2003 Lecture Slides, CSE6243, MSU, Rayford B."— Presentation transcript:

1 DBMS Spring 2014 Database Integrity Sources: Security in Computing, Pfleeger and Pfleeger, Prentice Hall, 2003 Lecture Slides, CSE6243, MSU, Rayford B. Vaughn, 2005 http://www.postgresql.org/docs/9.0/static/ddl-constraints.html

2 First, a followup from Tues  R(A, B, C, D, E) with FDs  AB -> C  C -> D  A -> E  What violations of 3nf are found?  How would you decompose this?

3 Followup from Tues  R(A, B, C, D) with FDs  AB -> C  C -> D  D -> A  What are the possible keys to this relation?  What violations of 3nf are found?  How would you decompose this? Book, page 92, 3.3.5.1

4

5 Traditional Security Concerns  Confidentiality  Integrity  Availability  Accountability

6 Traditional Security Concerns  Confidentiality  Integrity  Availability  Accountability

7 Integrity  DB integrity types  Physical Database Integrity –Data in Database is safe –Data can be reconstructed  Logical Database Integrity –Structure of Database is preserved –No inconsistency  Element Integrity –Correctness/accuracy of data is maintained

8 Integrity Goals  Database integrity protection must achieve:  Internal consistency: database entries must obey prescribed rules;  External consistency: database entries are correct - combine checking data entered with auditing to check consistent state.

9 Integrity Rules  Most rules are application specific, but two rules inherent to relational database model:  Entity integrity rule: –no component of primary key can accept nulls.  Referential integrity rule: –database must not contain unmatched foreign key values.

10 Application Specific Integrity Checks  field checks: check that entries are valid elements of domain  consistency checks: check that entries in different relations do not conflict  scope checks: checks that query results are not computed for too small a sample (for specialized DB)  change logs: check that all changes are recorded with original and modified entry values

11 Integrity in postresql  Primary keys  Must be unique  Must be non-null  Foreign keys - http://www.postgresql.org/docs/8.1/static/tutorial- fk.html http://www.postgresql.org/docs/8.1/static/tutorial- fk.html  Field can be null or not-null  If null, we can have a row without the foreign key attribute present, but if the attribute is filled in, it must match a row in the referenced table.

12 Thinking about foreign keys  If a Foreign Key references another table and the other table row is deleted, what should happen to the referencing row.  For example, dlangs references languages. What if we decide that a language really isn’t a language and so we remove it. ie. PigLatin. What should happen?  No Action / Restrict  On Delete Cascade  On Update Cascade (what happens if we change)

13 Other constraints  “Table constraints”  Field contraints  Can be built into the CREATE TABLE OR  Can be added using the ALTER TABLE

14 Other constraints  Null is assumed for a non-key attribute added to a table.  NOT NULL requires a value to be filled in.  SSN int NOT NULL,  UNIQUE requires that no other row can have the same value.  SSN int UNIQUE NOT NULL,

15 Field vs Table level from Postgresql reference CREATE TABLE products ( product_no integer UNIQUE, name text, price numeric ); CREATE TABLE products ( product_no integer, name text, price numeric, UNIQUE (product_no) ); CREATE TABLE example ( a integer, b integer, c integer, UNIQUE (a, c) );

16 Check Constraints  Allow us to more finely define field values beyond the overall domain (data type)  For example, can a driver have a vehicle with -5 seats? Can a driver have a vehicle with 192 seats? What is the restriction to insure that we have a reasonable number. CREATE TABLE products ( product_no integer, name text, price numeric CHECK (price > 0) );

17 Named constraints CREATE TABLE products ( product_no integer, name text, price numeric CONSTRAINT positive_price CHECK (price > 0) ); Table level CREATE TABLE products ( product_no integer, name text, price numeric CHECK (price > 0), discounted_price numeric CHECK (discounted_price > 0), CHECK (price > discounted_price) );

18 Adding constraints  ALTER TABLE  Can add table level constraints.

19 Default values CREATE TABLE distributors ( name varchar(40) DEFAULT 'Luso Films', did integer DEFAULT nextval('distributors_serial'), modtime timestamp DEFAULT current_timestamp );


Download ppt "DBMS Spring 2014 Database Integrity Sources: Security in Computing, Pfleeger and Pfleeger, Prentice Hall, 2003 Lecture Slides, CSE6243, MSU, Rayford B."

Similar presentations


Ads by Google