Chapter 2, Level 2: Constraints Flashcards

1
Q

What are SQL constraints?

A

SQL constraints are used specify rules for data in a table. They are used to prevent bad or unwanted data from getting into the tables.
If there is any violation between the constraint (‘rule’) and the data action (e.g. inserting a null value when the constraint forbids a null value), then the action is aborted by the constraint.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the six constraints?

A
  • NOT NULL
  • UNIQUE
  • PRIMARY KEY
  • FOREIGN KEY
  • CHECK
  • DEFAULT
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What statement would add a constraint preventing null values from being entered into a table column?

A

ALTER TABLE table_name
(
CONSTRAINT not_null_name NOT NULL (column_name)
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the Primary Key Constraint?

A

This constraint (rule) means that a column cannot be NULL but must be UNIQUE.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between a PRIMARY KEY vs. NOT NULL + UNIQUE constraints?

A

A PRIMARY KEY can only be defined once per table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When a column in one table references the primary key of another table, it’s called a ______?

A

Foreign Key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

A row in a table containing a FOREIGN KEY that references a missing row in another table is called a ______ record?

A

An orphan record

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

The ______ constraint is used to validate the value that can be placed in a column.

A

CHECK

How well did you know this?
1
Not at all
2
3
4
5
Perfectly