{"id":514,"date":"2026-06-10T04:04:29","date_gmt":"2026-06-10T04:04:29","guid":{"rendered":"https:\/\/mitalgoswami.in\/?p=514"},"modified":"2026-06-17T03:11:11","modified_gmt":"2026-06-17T03:11:11","slug":"integrity-constraints","status":"publish","type":"post","link":"https:\/\/mitalgoswami.in\/?p=514","title":{"rendered":"Integrity Constraints"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The constraints you listed are <strong>Integrity Constraints<\/strong> in DBMS\/RDBMS. They help maintain the accuracy and consistency of data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. NOT NULL Constraint<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Ensures that a column cannot have a NULL (empty) value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE Student (<br>    StudentID INT,<br>    Name VARCHAR(50) NOT NULL<br>);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, the <code>Name<\/code> column must contain a value.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. UNIQUE Constraint<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Ensures that all values in a column are unique.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE Student (<br>    StudentID INT,<br>    Email VARCHAR(100) UNIQUE<br>);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">No two students can have the same email address.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3. PRIMARY KEY Constraint<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Uniquely identifies each record in a table.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Properties:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Must be unique<\/li>\n\n\n\n<li>Cannot be NULL<\/li>\n\n\n\n<li>Only one primary key per table<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE Student (<br>    StudentID INT PRIMARY KEY,<br>    Name VARCHAR(50)<br>);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>StudentID<\/code> uniquely identifies each student.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">4. FOREIGN KEY Constraint<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Establishes a relationship between two tables.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Student Table<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE Student (<br>    StudentID INT PRIMARY KEY,<br>    Name VARCHAR(50)<br>);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Course Table<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE Course (<br>    CourseID INT PRIMARY KEY,<br>    StudentID INT,<br>    FOREIGN KEY (StudentID)<br>    REFERENCES Student(StudentID)<br>);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, <code>StudentID<\/code> in the <code>Course<\/code> table refers to <code>StudentID<\/code> in the <code>Student<\/code> table.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Summary Table<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Constraint<\/th><th>Purpose<\/th><\/tr><\/thead><tbody><tr><td>NOT NULL<\/td><td>Prevents NULL values in a column<\/td><\/tr><tr><td>UNIQUE<\/td><td>Ensures all values are different<\/td><\/tr><tr><td>PRIMARY KEY<\/td><td>Uniquely identifies each row<\/td><\/tr><tr><td>FOREIGN KEY<\/td><td>Maintains relationship between tables<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Example Combined<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE Student (<br>    StudentID INT PRIMARY KEY,<br>    Name VARCHAR(50) NOT NULL,<br>    Email VARCHAR(100) UNIQUE<br>);<br><br>CREATE TABLE Result (<br>    ResultID INT PRIMARY KEY,<br>    StudentID INT,<br>    Marks INT,<br>    FOREIGN KEY (StudentID)<br>    REFERENCES Student(StudentID)<br>);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>StudentID<\/code> \u2192 PRIMARY KEY<\/li>\n\n\n\n<li><code>Name<\/code> \u2192 NOT NULL<\/li>\n\n\n\n<li><code>Email<\/code> \u2192 UNIQUE<\/li>\n\n\n\n<li><code>StudentID<\/code> in <code>Result<\/code> \u2192 FOREIGN KEY<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The constraints you listed are Integrity Constraints in DBMS\/RDBMS. They help maintain the accuracy and consistency of data. 1. NOT NULL Constraint Ensures that a column cannot have a NULL (empty) value. Example: Here, the Name column must contain a value. 2. UNIQUE Constraint Ensures that all values in a column are unique. Example: No [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[],"class_list":["post-514","post","type-post","status-publish","format-standard","hentry","category-oracle"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=514"}],"version-history":[{"count":1,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/514\/revisions"}],"predecessor-version":[{"id":515,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/514\/revisions\/515"}],"wp:attachment":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}