Assess your understanding of fundamental relational database concepts, normalization, and essential SQL queries in ASP.NET Core backend development. This quiz covers primary keys, data types, relationships, CRUD operations, and key SQL clauses to help reinforce your database design and querying skills.
Which statement best describes the purpose of a primary key in a relational database table used in an ASP.NET Core backend?
Explanation: The primary key is used to uniquely identify each record in a table, which is essential for data integrity and efficient queries. Creating references to other tables involves foreign keys, not primary keys. Large binary objects are stored in specific data types like BLOB or varbinary, not as primary keys. Grouping for faster retrieval typically involves indexes or the GROUP BY clause, not primary keys.
You need to store a user's email address in a database table. Which SQL data type is most suitable for this column in an ASP.NET Core project?
Explanation: VARCHAR is ideal for storing variable-length strings, such as email addresses, making it the correct data type. INT is meant for integer values and unsuitable for text data. DATE stores calendar dates, not text. BOOLEAN is used for true or false values, which do not accommodate text like email addresses.
Why is normalization important when designing relational databases for an ASP.NET Core backend?
Explanation: Normalization structures the database to minimize redundancy and maintain data integrity, preventing anomalies during data operations. Increasing the number of indexes is not the main purpose of normalization. Ensuring all columns are integers is not required and not related to normalization. Faster application startup time is not a typical outcome of normalization.
In a relational database for an ASP.NET Core backend, how do you create a direct relationship between an Orders table and a Customers table?
Explanation: A foreign key in the Orders table referencing the Customers table establishes a relational link, enforcing referential integrity. Sharing the same primary key across unrelated tables is incorrect and causes data issues. SELECT DISTINCT is for filtering query results, not defining relationships. Storing all order data in Customers causes redundancy and violates normalization.
Which SQL statement will retrieve all columns from the Products table in an ASP.NET Core backend database?
Explanation: SELECT * FROM Products; retrieves every column and row from the Products table. DELETE removes records, which is not desired here. UPDATE changes data but does not fetch records. INSERT adds records and does not retrieve existing rows.
You want to find all users older than 30 in the Users table. Which clause should you add to your SQL SELECT statement?
Explanation: The WHERE clause is used to filter rows based on specified conditions, so WHERE Age u003E 30 returns users older than 30. GROUP BY organizes results for aggregation, not filtering rows. ORDER BY sorts results but doesn't filter them. HAVING is used after GROUP BY for aggregated filtering, not single row conditions.
If you want to list all orders along with customer names, which SQL operation should you use between the Orders and Customers tables?
Explanation: INNER JOIN combines rows from both tables based on a related column, allowing you to view orders and corresponding customer names in a single result. UNION ALL merges rows from multiple SELECT queries, not joining tables on relationships. CREATE INDEX is for optimizing search performance, not combining data. ALTER TABLE modifies table structure, not fetching related records.
In the context of relational databases and ASP.NET Core, which SQL statement performs an update to existing records?
Explanation: The UPDATE statement is used to modify existing records in a table. DELETE removes records instead of updating them. SELECT retrieves records for reading, leaving them unchanged. DROP removes entire tables or database structures, not individual records or fields.
Which SQL keyword ensures that the values in a particular column are always unique in a table?
Explanation: The UNIQUE constraint enforces uniqueness for values in a column, ensuring that no duplicate values exist. DEFAULT sets a predefined value when none is provided, but does not guarantee uniqueness. FOREIGN is related to foreign keys, not value constraints. INDEX improves search speed but doesn't enforce unique values by itself.
How do you specify a default value for a column in an SQL table during its creation in a relational database?
Explanation: The DEFAULT keyword assigns a predefined value to a column when a new row is inserted without explicitly providing a value for the column. PRIMARY is used for primary keys, not default values. UNIQUE defines uniqueness constraints, not default assignments. FOREIGN refers to keys relating tables rather than default values.