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

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

Microsoft Power BI
Microsoft Power BI is a free, self-service business intelligence cloud service that provides non-technical business users with tools for aggregating, analyzing, visualizing and sharing data. Power BI's...

Interview questions on Packages in Oracle
Let me list few standard questions asked in the interviews on plsql package. 1. Why packages are used? What are it's advantages? 2. Name few bulin-in Oracle packages. 3. Can we have a function or procedure...

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

SQL Subqueries - Used in various ways
If you master the concepts of subqueries, you would gain a lot of flexibility in writing complex SQL queries. Let's not get into Correlated subqueries, let us see the different versions of nested subquery...
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