Getting started with Accurately Storing Data

Slides:



Advertisements
Similar presentations
MSc IT UFCE8K-15-M Data Management Prakash Chatterjee Room 2Q18
Advertisements

Introduction to Structured Query Language (SQL)
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
Concepts of Database Management Sixth Edition
Introduction to Structured Query Language (SQL)
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
Database Lecture # 1 By Ubaid Ullah.
Database Management System Lecture 6 The Relational Database Model – Keys, Integrity Rules.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
An Investigation of Oracle and SQL Server with respect to Integrity, and SQL Language standards Presented by: Paul Tarwireyi Supervisor: John Ebden Date:
Chapter 4 The Relational Model 3: Advanced Topics Concepts of Database Management Seventh Edition.
Database Technical Session By: Prof. Adarsh Patel.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
SQL Server 7.0 Maintaining Referential Integrity.
Brian Alderman | MCT, CEO / Founder of MicroTechPoint Pete Harris | Microsoft Senior Content Publisher.
Discovering Computers Fundamentals Fifth Edition Chapter 9 Database Management.
DAY 12: DATABASE CONCEPT Tazin Afrin September 26,
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
Constraints cis 407 Types of Constraints & Naming Key Constraints Unique Constraints Check Constraints Default Constraints Misc Rules and Defaults Triggers.
Chapter 9 Constraints. Chapter Objectives  Explain the purpose of constraints in a table  Distinguish among PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK,
Oracle 11g: SQL Chapter 4 Constraints.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
06 | Modifying Data in SQL Server Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program Manager.
Visual Programing SQL Overview Section 1.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Session 1 Module 1: Introduction to Data Integrity
Understand Primary, Foreign, and Composite Keys Database Administration Fundamentals LESSON 4.2.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
SQL Triggers, Functions & Stored Procedures Programming Operations.
Constraints Advanced Database Systems Dr. AlaaEddin Almabhouh.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
In this session, you will learn to: Manage databases Manage tables Objectives.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Database Constraints ICT 011. Database Constraints Database constraints are restrictions on the contents of the database or on database operations Database.
Database Constraints Ashima Wadhwa. Database Constraints Database constraints are restrictions on the contents of the database or on database operations.
CompSci 280 S Introduction to Software Development
Fundamentals of DBMS Notes-1.
Logical Database Design and the Rational Model
Fundamental of Database Systems
Understanding Data Storage
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Chapter 6 - Database Implementation and Use
Lecture # 13 (After 1st Exam)
SQL: Constraints and Triggers
Module 5: Implementing Data Integrity by Using Constraints
STRUCTURED QUERY LANGUAGE
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Normalization Referential Integrity
Primary key Introduction Introduction: A primary key, also called a primary keyword, is a key in a relational database that is unique for each record.
SQL DATA CONSTRAINTS.
Database solutions Chosen aspects of the relational model Marzena Nowakowska Faculty of Management and Computer Modelling Kielce University of Technology.
Oracle9i Developer: PL/SQL Programming Chapter 8 Database Triggers.
Relational Database Design
Database Design: Relational Model
Chapter 11 Managing Databases with SQL Server 2000
SQL – Constraints & Triggers
Instructor Materials Chapter 5: Ensuring Integrity
Including Constraints
INTRODUCTION A Database system is basically a computer based record keeping system. The collection of data, usually referred to as the database, contains.
Presentation transcript:

Getting started with Accurately Storing Data Data Integrity Getting started with Accurately Storing Data

Objectives What is data integrity? What is entity integrity? What is referential integrity? What are the methods to maintain database integrity?

Data Integrity Key benefits to Data Integrity: Data Integrity Truthful Accurate Complete Retrievable Verifiable Key benefits to Data Integrity:

Data Integrity Data integrity is a fundamental component of information security. In its broadest use, “data integrity” refers to the accuracy, reliability and consistency of data stored over its entire life-cycle in a database, data warehouse, data mart or other construct. The term – Data Integrity - can be used to describe a state, a process or a function – and is often used as a proxy for “data quality”. Software developers as well as Database Administrators must also be concerned with data integrity. They can define integrity constraints to enforce business rules on data when entered into an application or database. Data integrity is imposed within the computerized system at it’s design stage through the use of standard rules and procedures and is maintained through the use of validation and/or qualification protocols.

Data Integrity Data integrity means, in part, that you can correctly and consistently navigate and manipulate the tables in the database. There are three basic rules to ensure data integrity; entity integrity, referential integrity and domain integrity. The entity integrity rule states that the value of the primary key can never be a null value (a null value is one that has no value and is not the same as a blank). Because a primary key is used to identify a unique row in a relational table, its value must always be specified and should never be unknown. The integrity rule requires that insert, update, and delete operations maintain the uniqueness and existence of all primary keys. The referential integrity rule states that if a relational table has a foreign key, then every value of the foreign key must either be null or match the values in the relational table in which that foreign key is a primary key. Domain integrity validates data for a column of the table.

Data Integrity Entity Integrity – Applies to Rows and is enforced through indexes, UNIQUE constraints and PRIMARY Key constraints. Domain Integrity – Applies to Column and is enforced using FOREIGN Key constraints, CHECK constraints, DEFAULT definitions and NOT NULL. Data Types Rules Triggers XML Referential Integrity – enforced using FOREIGN Key and CHECK constraints.

Data Integrity Domain Integrity (Columns) Entity Integrity (Rows) Table 1 Domain Integrity (Columns) Entity Integrity (Rows) Referential Integrity Table 2

Data Integrity Data integrity is important because: Ensure product / service quality Safety and Privacy of customers Key business processes are managed via electronic controlled systems Increasing of interaction between computer systems that support business processes (internet, enterprise systems, wireless, mobile devices) Increasing focus by Authorities and Regulations on data integrity related issues

Referential Integrity Referential Integrity (RI) is a database concept used to ensure that the relationships between your database tables remains synchronized during data modifications. Referential integrity, also known as relational integrity, means that if a table contains a foreign key column, then every value in that column (except NULL, if it is allowed) will be found in the primary key of the table that it is related to, or references (the syntax for declaring the foreign key uses the keyword REFERENCES). RI can be used to ensure the data is lean, may be helpful in optimizing your database environment and can assist in early detection of errors. A combination of Primary Key and Foreign Key constraints can be used to help enforce referential integrity of you r database. In addition to a foreign key referencing a primary key constraint, a foreign key can also reference a Unique constraint to help maintain referential integrity.

Referential Integrity Users Table: Images Table: UsersID UserName 23 Tom 25 Dick 31 Harry ImageId UserId ImagePath 187 23 /images/emo.jpg 188 31 /images/kitten.jpg 189 24 /images/manamana.jpg 190 25 /images/pglogiston.jpg

Referential Integrity Method for enforcing referential integrity There are several methods available in SQL Server to help maintain database integrity: Primary key constraint Foreign key constraint Unique constraint Indexes Triggers Any of these methods can be created as a composite key which is an index or constraint created using more than one column. It may be necessary to use more than one column. It may be necessary to use more than one column to create a unique value for each row in a table.

Primary Key Constraint An important concept of designing a database table is the use of a primary key – an attribute or set of attributes used to uniquely identify each row A primary key’s main features are: It must contain a unique value for each row of data. It cannot contain null values. A table can only have one primary key which is created using a primary key constraint and enforced by creating a unique index on the primary key columns A column that participates in the primary key constraint cannot accept null values

Composite Primary Key Constraint Composite key, or composite primary key, refers to cases where more than one column is used to specify the primary key of a table. In such cases, all foreign keys will also need to include all the columns in the composite key. Note that the columns that make up a composite key can be of different data types. Below is the SQL syntax for specifying a composite key: CREATE TABLE TABLE_NAME (COLUMN_1 DATA_TYPE_1, COLUMN_2 DATA_TYPE_2, … PRIMARY KEY (COLUMN_1, COLUMN_2, …));

Foreign Key Constraint A foreign key is a column or combination of columns that are used to establish a link between data in two tables. The columns used to create the primary key in one table are also used to create the foreign key constraint and can be used to reference data in the same table or in another table. A foreign key does not have to reference a primary key, it can be defined to reference a unique constraint in either the same table or in another table. A columns that participates in the foreign key constraint can accept null values but if it contains a null value, the verification process is skipped.

Check Constraint The CHECK constraint is used to limit or restrict the value range that can be placed in a column. If you define a CHECK constraint on a single column it allows only certain values for this column. If you define a CHECK constraint on a table it can limit the values in certain columns based on values in other columns in the row. CREATE TABLE Persons ( P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255), CONSTRAINT chk_Person CHECK (P_Id>0 AND City='Sandnes') )

Default Constraint The DEFAULT constraint is used to insert a default value into a column. The default value will be added to all new records, if no other value is specified. Defaults can’t be used on columns that are automatically increasing or changing like timestamp and identity columns. However, they can be used on duplicating rows. CREATE TABLE Orders ( O_Id int NOT NULL, OrderNo int NOT NULL, P_Id int, OrderDate date DEFAULT GETDATE() )

Triggers A trigger is a database object that is attached to a table. In many aspects it is similar to a stored procedure. As a matter of fact, triggers are often referred to as a "special kind of stored procedure." The main difference between a trigger and a stored procedure is that the former is attached to a table and is only fired when an INSERT, UPDATE or DELETE occurs. You specify the modification action(s) that fire the trigger when it is created.

Summary The concept of data integrity ensures that all data in a database can be traced and connected to other data. Referential Integrity is used to ensure that data contained in the database remains consistent. Tools that can be used to help with referential integrity include (Primary Key constraint, Foreign Key constraint, Unique constraint, Unique Indexes and Triggers) Primary key constraint – an attribute or set of attributes used to uniquely identify each row Foreign key constrain – a column or combination of columns used to establish a link between data in the two tables Unique constraint – allows you to enforce uniqueness in columns other than the primary key Unique Index – ensures the index key contains no duplicate values and that every row in the table or view is unique in someway Triggers – complex T-SQL statements used to provide data integrity when table data is modified