UrbanPro
true

Learn SQL Server from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Data Integrity in SQL Server

Pritam Chatterjee
14/07/2020 0 0

It is often told, data without integrity is just numbers.

There are different situations like
1. When a user enters data which is not in proper range or invalid
2. A wrong DML operation is attempted by the user or by any bug in the code
3. Data from the related table are tried to be modified, and many other situations where data accuracy need to be verified.
Here is the use of data integrity.

It defines the consistency, accuracy, completeness and reliability of data.

To implement this data integrity, we use various constraints in the database.

In SQL Server, there are mainly two kinds of data integrity:
1. System-defined or Predefined integrity
2. User-Defined integrity

System defined / Predefined integrity:

Entity Integrity
- This integrity is used to ensure uniqueness and availability of data.
- Primary Key, Unique, Not null
Code:
create table Student
(
student_id varchar(10) primary key,
name varchar(30)not null,
email varchar(50) unique,
contact_number varchar(12) unique not null,
)


Referential Integrity
- this integrity is used when we refer to other tables
- foreign key
- When we use the primary key of one table in another table, it is called a foreign key
Code:
create table usertable (userid varchar(10) primary key,name varchar(20));

create table logintable(userid varchar(10) foreign key references usertable(userid),password varchar(20));


Domain Integrity
- Entity and referential integrity apply to the columns
- domain integrity will apply to the values of the data
- it is implemented using Check and Default constraints
Code:
create table Student
(
student_id varchar(10) primary key,
name varchar(30)not null,
email varchar(50) unique,
contact_number varchar(12) unique not null,
university varchar(30) not null default 'MyUniversity'
)


create table Student
(
student_id varchar(10) primary key,
name varchar(30)not null,
email varchar(50) unique,
age int check(age between 18 and 22),
contact_number varchar(12) unique not null,
university varchar(30) not null default 'MyUniversity'
)

 

User-defined Integrity
-User-defined integrity allows the user to apply business rules to the database that aren’t covered by any of the other three data integrity types.
- we implement this using stored procedures, triggers and constraints on column and table label.

0 Dislike
Follow 1

Please Enter a comment

Submit

Other Lessons for You

Microsoft Outlook
Microsoft Outlook is the preferred email client used to access Microsoft Exchange Server email. Not only does Microsoft Outlook provide access to Exchange Server email, but it also includes contact, calendaring...

An Introduction to Business Intelligence Concepts
Looking for a Business Intelligence (BI) solution for your company can be intimidating. BI uses its own special terminology and the database design concepts can be difficult to grasp. So where do you...

What is a SQL join?
A SQL join is a Structured Query Language (SQL) instruction to combine data from two sets of data (e.g. two tables). Before we dive into the details of a SQL join, let’s briefly discuss what SQL...

Chart
A chart is a set of coordinates When you make a chart you start with an empty, two-dimensional space, a vertical dimension (y) and a horizontal dimension (x) . You also have a data source. Your job is...

Big Data & Hadoop - Introductory Session - Data Science for Everyone
Data Science for Everyone An introductory video lesson on Big Data, the need, necessity, evolution and contributing factors. This is presented by Skill Sigma as part of the "Data Science for Everyone" series.
X

Looking for SQL Server Classes?

The best tutors for SQL Server Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn SQL Server with the Best Tutors

The best Tutors for SQL Server Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more