0
0
DBMS Theoryknowledge~10 mins

Integrity constraints in DBMS Theory - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a primary key constraint to the 'id' column.

DBMS Theory
ALTER TABLE employees ADD CONSTRAINT pk_employee_id [1] (id);
Drag options to blanks, or click blank then click option'
APRIMARY KEY
BCHECK
CUNIQUE
DFOREIGN KEY
Attempts:
3 left
💡 Hint
Common Mistakes
Using FOREIGN KEY instead of PRIMARY KEY
Using UNIQUE which allows nulls
Using CHECK which is for conditions
2fill in blank
medium

Complete the code to ensure the 'age' column cannot have NULL values.

DBMS Theory
ALTER TABLE persons MODIFY age [1];
Drag options to blanks, or click blank then click option'
ANULL
BNOT NULL
CDEFAULT 0
DUNIQUE
Attempts:
3 left
💡 Hint
Common Mistakes
Using NULL which allows nulls
Using UNIQUE which only enforces uniqueness
Using DEFAULT which sets a default value but allows NULL
3fill in blank
hard

Fix the error in the code to add a foreign key constraint referencing 'departments(id)'.

DBMS Theory
ALTER TABLE employees ADD CONSTRAINT fk_dept_id [1] (department_id) REFERENCES departments(id);
Drag options to blanks, or click blank then click option'
AFOREIGN KEY
BPRIMARY KEY
CUNIQUE
DCHECK
Attempts:
3 left
💡 Hint
Common Mistakes
Using PRIMARY KEY instead of FOREIGN KEY
Using UNIQUE which does not create relationships
Using CHECK which is for conditions
4fill in blank
hard

Fill both blanks to create a check constraint that ensures salary is greater than 0.

DBMS Theory
ALTER TABLE employees ADD CONSTRAINT chk_salary [1] (salary [2] 0);
Drag options to blanks, or click blank then click option'
ACHECK
B>
C<
DNOT NULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using NOT NULL which only prevents nulls
Using < instead of > causing wrong condition
Omitting CHECK keyword
5fill in blank
hard

Fill all three blanks to create a unique constraint on the combination of 'email' and 'phone' columns.

DBMS Theory
ALTER TABLE contacts ADD CONSTRAINT [1] UNIQUE ([2], [3]);
Drag options to blanks, or click blank then click option'
Auq_email_phone
Bemail
Cphone
Dpk_contacts
Attempts:
3 left
💡 Hint
Common Mistakes
Using primary key name instead of unique constraint name
Swapping column names or missing one
Omitting the UNIQUE keyword