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

How To Minimize The Page Splits In Sqlserver To Improve The Performane Of Database?
How to minimize the page splits in sqlserver to improve the performane of database? Page Splits: A page is 8Kbytes of data which can be index related, data related, large object binary (lob’s)...

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

Power View
Power View is now a feature of Microsoft Excel 2013, and is part of the Microsoft SQL Server 2012 Reporting Services add-in for Microsoft SharePoint Server 2010 and 2013 Enterprise Editions. Power View...

Interview questions based on "level", a pseudocolumn
1. Write a query to get the below output, 1 11 21 31 .. .. 91 2 12 22 32 .. .. 92 3 13 23 33 .. .. 93 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 10 20 30 40 ...

What is the difference between Analytics and analysis?
Analysis> Separation of a whole into its component parts> Looks backwards over time, providing marketers with a historical view of what has happened Analytics > Defines the science behind the...
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