Module 1: Course OverviewModule 4: Deriving a Logical Data Design Module 5: Normalizing the Logical Data Design Overview of DataIntegrity Implementing BusinessRules and Data Integrity Ac
Trang 1Module 7: Implementing Data Integrity
Trang 2Module 1: Course Overview
Module 4: Deriving a Logical Data Design Module 5: Normalizing the
Logical Data Design
Overview of DataIntegrity
Implementing BusinessRules and Data Integrity
Activity 7.1: Identifying Data Integrity Requirements
Activity 7.2: Determining
Business and Data Integrity
Implementations
Module 7: Implementing Data Integrity
Trang 3! Overview
In this module
At the end of this module, you will be able to:
" Identify business rules that relate to data integrity
" Identify the data integrity requirement type to which a business rule applies
" Evaluate and determine a location for implementing data integrity
" List implementation techniques for a given data integrity requirement
In this module, you will learn
how to enforce business
rules and maintain data
integrity
Trang 4! Overview of Data Integrity
This section discusses data
integrity rules and ways of
enforcing them
Trang 5Data Integrity Categories
Entity Integrity (rows)
the allowable values for an attribute
an instance of an entity is unique
Referential Integrity
Data integrity refers to the consistency and accuracy of data An important step
in database planning is deciding how to ensure this integrity
Three categories of data integrity can be employed: domain, entity, and referential Here you will learn about domain and entity integrity (Referential integrity will be discussed in detail in the following topic.)
Domain integrity
Domain (or column) integrity specifies a set of legitimate data values for a column and determines whether null values are to be allowed Implementing validity checking can often enforce domain integrity Restricting the data type, format, or range of possible values allowed in a column can also enforce domain integrity
When used together, domain and entity integrity help to ensure that each entity
in a physical design maintains consistency When planning for databases in your design, you must consider consistency among entities and data validity within the entities as important additional aspects of data integrity
Slide Objective
To introduce the concept of
data integrity
Lead-in
Data integrity refers to the
consistency and accuracy of
data and falls into three
categories: domain, entity,
and referential
Trang 6Referential Integrity
entity
The domain and entity integrity categories suffice for enforcing data integrity in
a single table; however, many databases contain multiple tables with parent and child entities that are related When both the entities in a relationship must exist and must have a valid link to one another, referential integrity makes sure that these conditions are met
Referential integrity ensures that the relationships between the primary keys (in the parent entity’s table) and foreign keys (in the child entity’s table) are always maintained
As a result of the restrictions that referential integrity imposes on tables, it is important for you to consider what to do when a primary key must be updated
or deleted If the primary key’s value in the parent entity is changed or deleted, then the instance of that entity has been modified, thus necessitating
corresponding modifications in all child entities that reference the parent By cascading, or walking, through all related child tables and updating or deleting data as necessary, the database can maintain referential integrity
Slide Objective
To explain the concept of
referential integrity
Lead-in
Whereas domain and entity
integrity help ensure
accuracy of data within a
table, referential integrity
helps ensure accuracy of
data between tables
Trang 7Data Validation
It is important to have valid data Domain, entity, and referential integrity ensure that data exists where necessary and that entities follow a basic set of rules for existence None of these data integrity categories, however, can determine whether the data is valid You can ensure that the data is correct by checking it in the following ways:
" Range checking involves making sure the data’s value falls within a set of limits determined by the functional specification
" Data format checking involves making sure the data conforms to a set of format specifications, such as currency formatting, telephone number formatting, or length-of-character strings
" Data type checking involves making sure the data belongs to the proper data type and that an invalid data type is not used to represent the data when it is written to the database
To ensure that queries return the correct information, you must make sure that the information being stored is valid You can validate data in two ways:
" Client-side checks can ensure that invalid data is not posted to a database These checks can be coded as a script, as part of an executable program, or
as part of a Web page For example, if a field denotes a monetary value, a script can make sure that the information in that field is the proper data type and format
" Server-side checks, which are executed by the DBMS engine, can be implemented with field data types, default values, and constraints These checks can also ensure that invalid data is not stored in the database
Slide Objective
To introduce the concept of
data validation
Lead-in
Validity of data is of the
utmost importance This
topic discusses ways to help
achieve data validity
Trang 8The methods or combination of methods that you use depends on the objectives and requirements of your solution; each method or combination has its value Although more difficult to maintain than server-side checks, client-side checks can help decrease the processing load on the DBMS server Although easier to maintain, server-side checks might present a bottleneck if the server has to validate many client requests
Trang 9Identifying Data Integrity Requirements
must exist (produces domain and entity integrity)
requirements must exist (produces referential integrity)
Identifying data integrity requirements helps ensure that all logical and physical requirements for a solution are met and that the physical design supports the full intent of your specification
When attempting to identify the data integrity requirements of a solution, you must start with the data requirements specified during the solution’s design When examining the data requirements, you should identify areas within the requirements in which uniqueness, or limits and constraints, have been specified or deemed necessary to help ensure that entities can exist and be implemented correctly
If limits and constraints or limits have been specified or deemed necessary, you must determine whether the limits and constraints are bound to an entity or to a relationship between entities
For example, suppose you need to determine whether a particular task can exist without a related job number If it can’t, you must implement a data integrity requirement to make sure that no instance of that task is created without a corresponding job number Alternatively, suppose a consultant must submit a weekly timesheet for a client No timesheet can duplicate another timesheet, and no two timesheets can represent the same time or work performed by a consultant Therefore, a data integrity requirement exists for guaranteeing the uniqueness of timesheet information Each timesheet within the database must
be represented by a unique attribute or a combination of unique attributes Finally, you must implement referential integrity requirements to ensure that all relationships are maintained For example, if a customer wants to be removed from Ferguson and Bardell, Inc.’s database, a referential integrity requirement must ensure that the customer cannot be deleted as long as payment has not been received for any outstanding invoices
requirements helps validate
your physical design and
also ensures valid data
Trang 10Activity 7.1: Identifying Data Integrity Requirements
In this activity, you will evaluate a set of data requirements from the Ferguson and Bardell, Inc case study to determine areas where possible data integrity issues might arise You will then formulate a set of data integrity requirements that must be followed by the development team for the Ferguson and Bardell, Inc solution
After completing this activity, you will be able to:
" Identify areas where data integrity and validity are required
" Specify data integrity requirements as they relate to data requirements
Slide Objective
To introduce this activity
Lead-in
In this activity, you will
determine data integrity
requirements for a solution
Trang 11! Implementing Data Integrity Requirements
Slide Objective
To provide an overview of
the methods used to
implement data integrity
requirements
Lead-in
This section discusses ways
in which data integrity can
be implemented
Trang 12Identifying Business Rules
thereby helping to determine solutions to events that can be predicted or automated
Business rules are the representation of logic specified within a solution When identifying business rules for a solution, you must reexamine the solution’s data requirements for the initial criteria that the rules need to satisfy You should also review any existing process documentation and use cases to determine what data-centric processes are currently being executed and what processes need to be executed in the future
It is important to consider the following three criteria when determining business rules:
" Conditions that must be satisfied for data to be considered valid Using the Ferguson and Bardell, Inc case study as an example, issues you might consider when determining applicable business rules include whether consultants can receive flat-level commissions even if they fail to bill for a period of time or whether a product can be shipped to a customer if no payment has been received
" Conditions that must be avoided Again using the Ferguson and Bardell, Inc case study as an example, issues you might consider include whether product pricing can fall below certain levels or whether inventory levels for products can drop below zero
" Sequences in which events must occur Using the Ferguson and Bardell, Inc case study as an example, issues you might consider include what to do when an inventory product falls below zero, when a new consultant is hired, or when payment for a contract is received
Slide Objective
To introduce methods for
identifying business rules
within data requirements
Lead-in
Business rules form a
foundation for encapsulating
logic from the data
requirements into the
solution
Trang 13Deploying Business Rules and Data Integrity Requirements
of the database
required often determines which strategy is used
You can implement business rules and data integrity requirements by using two means of deployment:
" Directly in the database Most DBMSs provide automated processes that can be bound to tables and columns to enforce business rules and data integrity requirements
" Programmatically within or outside of the database You can code business rules and data integrity requirements into client applications, create components that can be deployed on an application server, or use programming logic and languages that are part of the database engine
The primary distinction between the two deployment methods is that the former involves rules that are automatically processed by the database engine, whereas the latter involves rules that must be called or invoked by an application’s logic Determining where to deploy rules is often based on the nature of the
programming logic required Most relational database engines now execute automatic methods that incorporate simple and commonly required application logic This logic applies to specific business rule tasks and resides in a single location It is also easily updated and efficient to execute If more complex logic
is required, it can be implemented as application code that can reside in any of the three service layers: user, business, or data You should choose your deployment strategy by using the same criteria with which you choose your development languages
Slide Objective
To introduce the different
ways in which business
rules can be deployed
Lead-in
Business rules can be
deployed in two ways: in the
database or
programmatically within or
outside of the database
Trang 14Implementing in the Database
If you choose to enforce data integrity directly in the database, the DBMS will
do much of the work for you by using its automatic and built-in checks
Within the database engine, business rules and data integrity requirements can
be enforced through a set of criteria that data must either meet or not meet Usually, most of the data integrity requirements are implemented by using the automatic controls and properties of the database engine This automatic control involves the specification, or declaration, of the criteria at the time an object (such as a field, table, index, or key) is created
Enforcing data integrity through built-in database features has some distinct benefits: Integrity is enforced automatically, and the criteria do not have to be maintained or updated unless they change
You can use the following database features to enforce data integrity:
" Data types Setting appropriate data types for the fields in a database ensures that incorrect types of data can’t be entered into the table For example, if a data type of Date is specified, the database will reject any string or numeric value that is not in a date format Data types ensure that the format of the data is legitimate, but it cannot ensure that the value is valid
" Default values Default values specify the values to be used for a field when the values have not been explicitly supplied in INSERT statements By using default values
in your table definitions, you can ensure that a field value will be valid even when a user does not explicitly supply it
" Data validation rules Data validation rules encapsulate logic for specifying data values that are acceptable in a table’s fields They can specify the length of a field, an input mask, or a range of valid values
Trang 15" Keys Most database engines can automatically monitor referential integrity between tables The primary and foreign key relationships from the physical model directly correspond to the database engine’s key settings These key settings automatically enforce referential integrity between linked tables
" Triggers Triggers are sets of programmatic statements that are explicitly defined for a particular table When a specific action (such as an insert, update, or delete) occurs in that table, the trigger causes the statements to automatically run For example, a trigger can verify data in other tables or perform an automatic update to a different table
Trang 16Implementing Programmatically
You can use several methods to implement data integrity programmatically:
" Stored procedures Stored procedures are named collections of SQL statements that are stored
on the DBMS By using stored procedures, you can write one piece of code that performs an action, store it, and call it repeatedly as necessary
Stored procedures are useful for controlling changes to a table For example, instead of granting a user update rights to a specific table, you could allow updates to the table only through stored procedures By using the SQL code
in the stored procedure, you can determine whether the user’s change is appropriate and then either disregard or apply the change
The flow of a process can also be handled through the use of stored procedures For example, several tables could be changed or reordered by the code of a stored procedure
" Scripts Scripts can also be used to enforce data integrity within a database
Generally, you write a script to automate a process that is either inefficiently handled by the DBMS engine or impractical as a whole For example, you might write a script that maintains a database by importing a series of mainframe downloads, re-indexing the database, and then copying a report file to another file server
The script logic can be written in several languages Each script executes outside the memory space of the DBMS and might perform more tasks than simply manipulating data Scripts are generally used in a command-line environment or as part of a batch process that performs other tasks
Slide Objective
To introduce methods for
implementing data integrity