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

5 Tips For Improving Your Documentation Immediately.
Tip 1) Quit it with the Passive Voice The passive voice is a plague on effective documentation. It reduces its clarity, its consistency, and the efficiency and tightness of the writing. The passive voice...

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...

How to read and understand the Compilation errors?
Today, we will understand how to interpret the compile time erros and fix them. Don't confuse with runtime errors which is altogether a different subject called Exception Handling. Compilation erros are...

Why Windows Administration knowledge is required for SQL DBA.
As the RDBMS system runs on the windows server operating system and for most of its function is depended on windows OS. Hence SQL DBA should know the basic windows to review various services, events and...

R programming language
R is a programming language and software environment for statistical computing and graphics supported by the R Foundation for Statistical Computing. The R language is widely used among statisticians and...
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