1
© BELGIUM CAMPUS 2021
2
© BELGIUM CAMPUS 2021
3
Using the basic structure: ALTER OBJECTTYPE OBJECTNAME
4
It is a way of distinguishing Domain integrity is concerned Referential integrity refers to the
between different entities. In with ensuring that column values requirement that primary and
other words, a way to uniquely fall within an acceptable range of foreign keys remain synchronized
identify every row in a table. values (the domain). Domain between parent and child tables.
integrity also refers to the data
type and nullability of a column.
© BELGIUM CAMPUS 2021
5
CREATE TABLE Student
(ID INT IDENTITY(1,1),
Name VARCHAR(20),
LastName VARCHAR(20),
DateStarted DATETIME,
Street VARCHAR(20),
Suburb VARCHAR(10),
City VARCHAR(10),
PostalCode VARCHAR(4),
For this section we will be
PhoneNumber VARCHAR(10) ,
working with a Student table:
QualificationID INT)
Details about main Details about main Details about main
point 1. point 2. point 3.
6
ALTER TABLE Student ALTER TABLE Student
ADD Age VARCHAR(10) ALTER COLUMN Age INT
For this section we will be
working with a Student table:
ALTER TABLE Student
ADD CONSTRAINT CK_StAge CHECK (Age >= 18)
7
ALTER TABLE Student ALTER TABLE Student
ADD CONSTRAINT DF_City ADD CONSTRAINT UC_Name UNIQUE (Nam
DEFAULT ’Pretoria' FOR City e)
For this section we will be
working with a Student table:
ALTER TABLE Student ALTER TABLE Student
DROP COLUMN PhoneNumber DROP CONSTRAINT CK_StAge
8
ALTER TABLE Student DROP TABLE Student
ADD PRIMARY KEY (ID)
For this section we will be
working with a Student table:
ALTER TABLE Student
ADD FOREIGN KEY (QualificationID) REFERENCES Qualification(ID)
9
Complete the Review Questions on PG 58 of
your textbook.
© BELGIUM CAMPUS 2021