Free MTA Database Questions and Answers — Questions and Answers
Question 1: What is the primary key in a database table?
- A field that can be left empty
- A field that uniquely identifies each record in a table (Correct answer)
- A field that refers to data in another table
- A field that contains duplicate values
Correct answer: A field that uniquely identifies each record in a table
A primary key in a database table is a special field or a combination of fields that uniquely identifies each individual record (row) within that table. It must contain unique values for every record and cannot be null. The primary key is crucial for maintaining data integrity and for establishing relationships between different tables in a relational database.
Question 2: Which SQL statement is used to retrieve data from a database?
- SELECT (Correct answer)
- INSERT
- UPDATE
- DELETE
Correct answer: SELECT
The `SELECT` statement is the fundamental SQL command used to retrieve data from one or more tables in a database. It allows users to specify which columns they want to view, which tables to query, and to apply various conditions for filtering and sorting the results. Commands like `INSERT`, `UPDATE`, and `DELETE` are used for modifying data, not for retrieving it.
Question 3: Which of the following is a characteristic of a relational database?
- Tables that store unstructured data
- Data is organized into tables with rows and columns (Correct answer)
- Hierarchical relationships between data elements
- Data stored in flat files
Correct answer: Data is organized into tables with rows and columns
A relational database is characterized by its structured organization, where data is arranged into two-dimensional tables consisting of rows and columns. Each row represents a unique record, and each column represents an attribute or field. Relationships between these tables are established through common fields, known as foreign keys, adhering to the principles of the relational model for efficient data management.
Question 4: In SQL, what does the JOIN clause do?
- Combines columns from different tables (Correct answer)
- Removes duplicates from a result set
- Adds a new row to a table
- Deletes rows from a table
Correct answer: Combines columns from different tables
In SQL, the `JOIN` clause is used to combine rows from two or more tables based on a related column between them. This allows you to retrieve a unified result set that includes columns from all joined tables, effectively linking data that is spread across different parts of the database. Various types of joins, such as INNER JOIN or LEFT JOIN, dictate how rows are matched and included in the output.
Question 5: Which of the following SQL keywords is used to add a new row to a table?
- INSERT (Correct answer)
- UPDATE
- SELECT
- ALTER
Correct answer: INSERT
The `INSERT` SQL keyword is specifically used to add new rows, also known as records, into an existing table within a database. This command allows you to specify the table name and provide the values for the columns of the new row. Other keywords like `UPDATE` modify existing rows, `SELECT` retrieves data, and `ALTER` modifies the table's structure.
What is the primary key in a database table?