Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

TABLES AND INTEGRITY CONSTRAINTS

TYPE A: Very Short Answer Questions


1 What is a constraint? Name some constraints that you can apply to enhance database integrity.
Ans. A constraint is a property assigned to column or the set of columns in a table that prevents certain types of
inconsistent data values from being placed in the column(s).
1. Primary key constraint
2. Not null constraint
3. Default constraint
2 What is primary key? What is PRIMARY KEY constraint?
Ans. A primary key is a unique identifier for a database record. When a table is created, one of the fields is typically
assigned as the primary key. While the primary key is often a number, it may also be a text field or other data type.
The PRIMARY KEY constraint uniquely identifies each record in a database table.
3 What is NOT NULL constraint? What is DEFAULT constraint?
Ans. The not-null constraint is a restriction placed on a column in a relational database table. It enforces the condition
that, in that column, every row of data must contain a value - it cannot be left blank during insert or update
operations. If this column is left blank, this will produce an error message and the entire insert or update operation
will fail.
The DEFAULT constraint is used to insert a default value into a column.

TYPE B: Short Answer Questions


1 What is foreign key? How do you define a foreign key in your table?
Ans. A foreign key is a field that points to the primary key of another table. The purpose of foreign key is to ensure
referential integrity of the data.

Whenever two tables are related by a common column (or set of columns), then the related column(s) in the parent
table (or primary table) should be either declared a PRIMARY KEY or UNIQUE key and the related column(s) in the
child table (or related table) should have FOREIGN KEY constraint.
For example, if there are two tables:
Items (Itemno, Description, Price, QOH)
Orders (Orderno, Orderdate, itemno, Qty)
Both the tables are related through common column Itemno.
The column Itemno is primary key in parent table Items and it should be declared as foreign key in the child table
Orders to enforce referential integrity.

2 How are FOREIGN KEY commands related to the PRIMARY KEY?

You might also like