You must complete Data Model to unlock this Lesson.

RELATIONAL MODEL III

CONTENT

  • Enforcing Integrity Constraints
  • Querying Relational Data

Enforcing Integrity Constraints

We will consider the following constraints:

SQL NOT NULL Constraint

The following SQL enforces student_id and Firstname column to not accept NULL values:

CREATE TABLE student

               (

                Student_id int NOT NULL,

                FirstName varchar(255) NOT NULL,

                LastName,

                Age,

               Class,

               Scores

               )

SQL UNIQUE KEY Constraint

The following SQL enforces gsm_no column  not to accept duplicate values on the teachers’ table below. Meaning two teachers cannot be sharing one gsm_no

CREATE TABLE teachers

               (

                teacher_id int NOT NULL,

                FirstName varchar(255) NOT NULL,

                LastName,

                Age,

               email_address,

               gsm_no int(11) UNIQUE KEY

               )

SQL PRIMARY KEY Constraint

The following SQL constraint uniquely identifies each record in a database table. It must contain unique values. Each table should have a primary key and cannot be NULL. In most cases, the id is used as the primary key so we will enforce it on the teacher_id in the SQL syntax below.

Lesson tags: Data Processing, Data Processing First Term, SS2 Data Processing Evaluation Questions First Term, SS2 Data Processing First Term, SS2 Data Processing Lesson Notes First Term, SS2 Data Processing Objective Questions First Term, SS2 Data Processing Questions and Answers First Term
Back to: Data Processing – SS2 > First Term
© [2022] Spidaworks Digital - All rights reserved.
error: Alert: Content is protected !!