DBMS Interview Questions - Set 2

DBMS Interview Questions

This page consists of DBMS interview questions and answers.

Q1: What is a super key?

A super key is a set of columns that can uniquely identify a row in a table.

Following is a simple customer table.

Note! Every customer gets a unique customerid and has a unique email address.

customeridfirstnamelastnamephoneemailmodified_atcreated_at
c1YusufShakeel6007008009yusuf@example.com2018-01-01 10:00:012018-01-01 10:00:01
c2JaneDoe1002003004jane@example.com2018-01-01 10:01:102018-01-01 10:01:10
c3JohnDoe2003004005john@example.com2018-01-01 10:02:002018-01-01 10:02:00
c4JaneDoe9002003004jane2000@example.com2018-02-04 10:02:102018-02-04 10:02:10
c5JohnDoe6003004005john8991@example.com2018-05-01 13:49:502018-05-01 13:49:50

Following are some of the superkeys for the above customer table that can uniquely identify a row in the table.

  • customerid, phone
  • customerid, email
  • phone, email
  • customerid, phone, email
  • phone, email, modified_at, created_at
  • firstname, lastname, phone, email

Q2: What is a candidate key?

A candidate key is a set of minimum number of columns that can uniquely identify a row in a table.

There can be more than one candidate key for a given table.

Value of a candidate key is unique and non-null value for all tuple (rows).

Following are some of the candidate key for the customer table that can uniquely identify a row in the table.

  • customerid
  • email
  • customerid, phone
  • customerid, email
  • phone, email

Q3: What is a composite candidate key?

A candidate key can have one colume and it can also have multiple columns.

A candidate key with multiple columns is called a composite candidate key.

Following are some of the composite candidate key for the customer table that can uniquely identify a row in the table.

  • customerid, phone
  • customerid, email
  • phone, email

Q4: What is a primary key?

A primary key is one of the candidate key that is selected to uniquely identify rows of a table.

There can be more than one number of candidate keys for a given table and it is upto the architect to choose any one of the candidate key and make it the primary key.

We have selected customerid as the primary key for the customer table as it can uniquely identify a row in the table.

Q5: What is an alternate key?

All candidate keys that are not the primary key are called the alternate keys.

Q6: What is a foreign key?

A foreign key is an attribute of a table that will take only those values that are present in an attribute of other table.

Following is the customer_order table.

orderidcustomeridamountmodified_atcreated_at
o1c1100.702018-01-01 10:20:012018-01-01 10:20:01
o2c399.102018-01-01 10:31:102018-01-01 10:31:10
o3c219.992018-01-01 10:52:002018-01-01 10:52:00
o4c57.992018-02-04 11:02:102018-02-04 11:02:10
o5c5299.992018-05-01 14:01:502018-05-01 14:01:50

In the above table the customerid attribute is the foreign key in the customer_order table.

The customerid column of the customer_order table will take only those values that are present in the customerid column of the customer table.

Q7: Can a primary key column of a table have more than one row sharing the same value?

No.

Primary key column of a table is supposed to have only unique values.

Q8: Can a foreign key column of a table have more than one row sharing the same value?

Yes.

Foreign key column of a table points at the primary key column of some other table. So, it is possible to have more than one row having the same value.

In the above customer_order table the foreign key column customerid has same value c5 appearing twice.

customerid
c1
c3
c2
c5
c5

Q9: What is the difference between Primary key and Unique constraint?

For an table there can only be ONE Primary key but the table can have multiple unique constraint.

Primary key can't have NULL value whereas, unique constraint can have NULL value.

Primary key is a unique contraint of a table.

Q10: What is SQL?

SQL or Structured Query Language is a standardised query language that allows us to access and manage databases.

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT