Tài liệu Module 7: Implementing Data Integrity docx

24 440 0
Tài liệu Module 7: Implementing Data Integrity docx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Module 7: Implementing Data Integrity Module 9: Data Storage Considerations Module 1: Course Overview Module 8: Designing Data Services Module 7: Implementing Data Integrity Module 2: Solution Design Processes Designing Data Services and Data Models Module 6: Deriving a Physical Data Design Module 3: Using a Conceptual Design for Data Requirements Module 4: Deriving a Logical Data Design Module 5: Normalizing the Logical Data Design Overview of Data Integrity Module 7: Implementing Data Integrity Activity 7.2: Determining Business and Data Integrity Implementations Implementing Business Rules and Data Integrity Activity 7.1: Identifying Data Integrity Requirements Module 7: Implementing Data Integrity 147 ! Overview Slide Objective To provide an overview of this module’s topics and objectives Lead-in In this module, you will learn how to enforce business rules and maintain data integrity " Overview of Data Integrity " Implementing Data Integrity Requirements " Review In In this this module 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 148 Module 7: Implementing Data Integrity ! Overview of Data Integrity Slide Objective To provide an overview of data integrity Lead-in This section discusses data integrity rules and ways of enforcing them " Data Integrity Categories " Referential Integrity " Data Validation " Identifying Data Integrity Requirements " Activity 7.1: Identifying Data Integrity Requirements In In this this section section In this section, you will learn about different types of data integrity requirements Module 7: Implementing Data Integrity 149 Data Integrity Categories Slide Objective To introduce the concept of data integrity Domain Integrity (columns) Referential Integrity Lead-in Data integrity refers to the consistency and accuracy of data and falls into three categories: domain, entity, and referential Entity Integrity (rows) " Domain integrity determines the allowable values for an attribute " Entity integrity ensures that an instance of an entity is unique 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 Entity integrity Entity (or row) integrity requires that all rows in a table have a unique identifier, known as the primary key value Whether the primary key value can be changed, or whether an entire row can be deleted, depends on the level of referential integrity required between the primary key of the table and the foreign keys of any other tables 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 150 Module 7: Implementing Data Integrity 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 " Ensures that each child entity has a related parent entity " Is built on domain and entity integrity principles 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 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 Module 7: Implementing Data Integrity 151 Data Validation 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 " Ensures that proper values are supplied $ Range checking $ Data format $ Data type checking Is implemented by two means of checking $ Client-side $ Server-side 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 152 Module 7: Implementing Data Integrity The 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 Module 7: Implementing Data Integrity 153 Identifying Data Integrity Requirements Slide Objective To introduce the method for identifying integrity requirements within a physical design Lead-in Identifying integrity requirements helps validate your physical design and also ensures valid data " Use data requirements as a guide " Look for explicit or implicit constraints or limits " Determine where uniqueness within the requirements must exist (produces domain and entity integrity) " Determine where relationships within the 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 154 Module 7: Implementing Data Integrity Activity 7.1: Identifying Data Integrity Requirements Slide Objective To introduce this activity Lead-in In this activity, you will determine data integrity requirements for a solution 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 Module 7: Implementing Data Integrity 155 ! 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 " Identifying Business Rules " Deploying Business Rules and Data Integrity Requirements " Implementing in the Database " Implementing Programmatically " Implementation Guidelines " Activity 7.2: Determining Data Integrity Implementations In In this this section section You can use several methods to implement data integrity requirements In this section, you will learn about these methods and examine how to implement business rules automatically and programmatically 156 Module 7: Implementing Data Integrity Identifying Business Rules 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 " Reexamine data requirements " Look for conditions that must be satisfied and avoided " Observe sequences in which events must occur, 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 when an inventory product falls below zero, when a new consultant is hired, or when payment for a contract is received Module 7: Implementing Data Integrity 157 Deploying Business Rules and Data Integrity Requirements Slide Objective To introduce the different ways in which business rules can be deployed " Two deployment strategies $ Lead-in Business rules can be deployed in two ways: in the database or programmatically within or outside of the database $ " Directly in the database Programmatically within or outside of the database Complexity of programming logic 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 158 Module 7: Implementing Data Integrity Implementing in the Database Slide Objective To introduce declarative ways of implementing data integrity Lead-in One way to implement data integrity is to implement it directly in the database " Data integrity enforced automatically " Criteria defined in table definitions " Built-in database features $ Data types $ Default values $ Data validation rules $ Keys $ Triggers If you choose to enforce data integrity directly in the database, the DBMS will 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 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 Module 7: Implementing Data Integrity " 159 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 160 Module 7: Implementing Data Integrity Implementing Programmatically Slide Objective To introduce methods for implementing data integrity programmatically " Lead-in If a data integrity requirement is complex, you can implement it programmatically " Data integrity enforced through logic $ Encapsulated in an executable package $ Called or invoked as needed Programmatic implementation methods $ Stored procedures $ Scripts $ Components You can enforce data integrity through logic that is encapsulated in an executable package and then called or invoked as needed The criteria for the logic are determined by the business rules, including any additional data integrity requirements that have been identified for the solution 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 Module 7: Implementing Data Integrity " 161 Components Components are executable collections of code that reside on a server or within another program Components are much like scripts, but allow for tighter integration with development environments, database engines, and custom code Using components installed on a separate computer has many advantages Because the code is stored in only one or a few locations, it is much easier to maintain than if it were included in the application itself When separate computers enforce business rules, more computers can be added to handle the additional workload as the load on the system grows 162 Module 7: Implementing Data Integrity Implementation Guidelines Slide Objective To introduce specific guidelines for implementing different types of rules Business rule, data integrity requirement Implementation option Checking for valid values in fields Default, validation rule Lead-in Making simple comparisons Default, validation rule Automatically ensuring referential integrity Key Performing cascading updates and deletes Trigger Certain situations require the use of one implementation option over another Evaluating data with full power of Transact-SQL Stored procedure Automating tasks programmatically Stored procedure, component Bulk processing of data Component Performing administration tasks Stored procedure Many situations dictate when to use one logic implementation method over another Depending on the result desired and the amount of processing necessary for your design, you will almost certainly prefer one method over another The table in the slide suggests some guidelines on which specific logic implementation method to use for certain types of rules Keep in mind that triggers encapsulate all the functionality of a stored procedure but are most useful in more specialized cases, when interactivity is not wanted or required Module 7: Implementing Data Integrity Activity 7.2: Determining Data Integrity Implementations Slide Objective To introduce this activity Lead-in In this activity, you will examine the implementation of data integrity and business rules in a DBMS In this activity, you will evaluate a physical design for the Ferguson and Bardell, Inc case study and then determine areas within the physical design where data integrity requirements and business rules should be implemented with the methods presented in this module After completing this activity, you will be able to: " Identify areas where data integrity should be enforced " Choose a method for implementing business rules and data integrity requirements 163 164 Module 7: Implementing Data Integrity ! Review Slide Objective To explain the purpose of this section and what you have learned Lead-in This section reviews what you have learned and prepares you for the next module " Guidelines " Review Questions " Looking Forward In In this this section section ... where data integrity and validity are required " Specify data integrity requirements as they relate to data requirements Module 7: Implementing Data Integrity 155 ! Implementing Data Integrity. .. Design Overview of Data Integrity Module 7: Implementing Data Integrity Activity 7.2: Determining Business and Data Integrity Implementations Implementing Business Rules and Data Integrity Activity... given data integrity requirement 148 Module 7: Implementing Data Integrity ! Overview of Data Integrity Slide Objective To provide an overview of data integrity Lead-in This section discusses data

Ngày đăng: 21/12/2013, 06:18

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan