Unit 5 - Practice Quiz

INT222 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What type of database model does PostgreSQL primarily use?

Introduction to PostgreSQL database Easy
A. Key-Value Store
B. Document-Oriented
C. Object-Relational
D. Graph-Based

2 The acronym ACID describes properties that guarantee transaction reliability. What does the 'C' in ACID stand for?

Introduction to PostgreSQL database Easy
A. Capacity
B. Consistency
C. Commit
D. Concurrency

3 Which of the following best describes PostgreSQL?

Introduction to PostgreSQL database Easy
A. A proprietary database owned by Microsoft
B. An in-memory-only database
C. An open-source database system
D. A NoSQL database

4 The name "PostgreSQL" is a successor to which earlier database project?

Introduction to PostgreSQL database Easy
A. DB2
B. Oracle
C. MySQL
D. Ingres

5 What is the default network port number that PostgreSQL listens on for client connections?

PostgreSQL installation Easy
A. 27017
B. 5432
C. 1433
D. 3306

6 During a standard installation of PostgreSQL, what is the default superuser account name that is created?

PostgreSQL installation Easy
A. root
B. admin
C. sysadmin
D. postgres

7 Which command-line tool is the native, interactive terminal for working with PostgreSQL?

PostgreSQL installation Easy
A. mongo-shell
B. psql
C. sqlcmd
D. mysql-cli

8 On a Debian/Ubuntu system, which apt command is used to install the PostgreSQL server package?

PostgreSQL installation Easy
A. sudo apt install postgresql
B. sudo apt-add postgresql
C. sudo apt-get configure postgresql
D. sudo apt-get start postgresql

9 Which SQL keyword is used to retrieve data from a database table?

Basic SQL commands Easy
A. GET
B. RETRIEVE
C. FETCH
D. SELECT

10 What is the purpose of the CREATE TABLE statement in SQL?

Basic SQL commands Easy
A. To define a new table and its columns
B. To add a new row of data to a table
C. To create a new database
D. To retrieve data from a table

11 In a SELECT statement, which clause is used to filter the results based on a specific condition?

Basic SQL commands Easy
A. FILTER
B. HAVING
C. CONDITION
D. WHERE

12 What character is used to terminate most SQL statements in tools like psql?

Basic SQL commands Easy
A. Period (.)
B. Semicolon (;)
C. Colon (:)
D. Comma (,)

13 Which SQL command corresponds to the 'Create' operation in CRUD?

CRUD operations Easy
A. ADD
B. INSERT
C. CREATE
D. NEW

14 Which SQL command corresponds to the 'Read' operation in CRUD?

CRUD operations Easy
A. READ
B. SHOW
C. FETCH
D. SELECT

15 Which SQL command corresponds to the 'Update' operation in CRUD?

CRUD operations Easy
A. CHANGE
B. ALTER
C. MODIFY
D. UPDATE

16 Which SQL command corresponds to the 'Delete' operation in CRUD?

CRUD operations Easy
A. REMOVE
B. DELETE
C. DROP
D. ERASE

17 What is the primary role of Prisma in a Node.js application?

PostgreSQL modeling with Prisma ORM Easy
A. To act as a web server
B. To be a type-safe database client (ORM)
C. To bundle JavaScript files
D. To manage front-end state

18 In a Prisma project, what is the standard name of the file where you define your database schema models?

PostgreSQL modeling with Prisma ORM Easy
A. database.yml
B. prisma.config
C. models.js
D. schema.prisma

19 Which Prisma CLI command is used to apply pending schema changes to the database by creating a new migration?

PostgreSQL modeling with Prisma ORM Easy
A. prisma init
B. prisma migrate dev
C. prisma generate
D. prisma db seed

20 After changing your schema.prisma file, what command must you run to update the type-safe Prisma Client?

PostgreSQL modeling with Prisma ORM Easy
A. prisma deploy
B. prisma format
C. prisma refresh
D. prisma generate

21 In the context of PostgreSQL's concurrency control, what is a primary advantage of using Multi-Version Concurrency Control (MVCC) over traditional read/write locking mechanisms?

Introduction to PostgreSQL database Medium
A. Writers do not block readers, and readers do not block writers.
B. It uses less disk space because only one version of a row is ever stored.
C. It simplifies the transaction isolation levels, offering only one strict level.
D. It completely eliminates the possibility of deadlocks.

22 You are designing a multi-tenant application where each tenant's data must be logically separated but reside within the same PostgreSQL database. What is the most appropriate PostgreSQL feature to achieve this namespace-level separation?

Introduction to PostgreSQL database Medium
A. Creating a separate schema for each tenant.
B. Using a separate database for each tenant on the same server instance.
C. Using different tablespaces for each tenant.
D. Using partitioned tables with a tenant_id column.

23 After installing PostgreSQL, you are unable to connect to the database server from a remote machine. Which configuration file is most likely responsible for controlling which hosts are allowed to connect, and what parameter needs to be adjusted?

PostgreSQL installation Medium
A. environment file by setting the PGHOST variable.
B. postgresql.conf by setting the allow_remote_connections parameter.
C. pg_hba.conf by adding a rule for the remote host's IP address.
D. pg_ident.conf by mapping the remote user to a local user.

24 What is the primary responsibility of the initdb command in the PostgreSQL setup process?

PostgreSQL installation Medium
A. To create the initial superuser and set its password interactively.
B. To start the main PostgreSQL server process (the postmaster).
C. To create a new database cluster, including system catalogs and default databases.
D. To install the PostgreSQL software binaries on the operating system.

25 You need to find the employee with the highest salary in each department from an employees table. Which query structure is most appropriate for this task?

Basic SQL commands Medium
A. A subquery in the WHERE clause to find the global maximum salary.
B. A window function like RANK() or ROW_NUMBER() partitioned by department.
C. An ORDER BY clause on salary with a LIMIT 1 clause.
D. A GROUP BY clause with a MAX() aggregate function on the salary.

26 What is a key difference in behavior between TRUNCATE TABLE users; and DELETE FROM users; in PostgreSQL?

Basic SQL commands Medium
A. TRUNCATE is non-transactional and cannot be rolled back, while DELETE can.
B. TRUNCATE can be used with a WHERE clause for selective deletion.
C. DELETE is always faster as it logs less information to the WAL.
D. TRUNCATE does not fire ON DELETE triggers, while DELETE does.

27 You need to perform a multi-step query: first, aggregate daily sales, and then, using that result, calculate the 7-day moving average. Which SQL feature is best suited for structuring such a query for readability and performance?

Basic SQL commands Medium
A. Using a WITH clause to define a Common Table Expression (CTE).
B. Using nested subqueries in the FROM clause.
C. Creating a permanent VIEW for the daily sales.
D. Using a HAVING clause to perform the second-step calculation.

28 You want to insert a new user with email = 'test@example.com', but if a user with that email already exists, you want to do nothing and avoid an error. Which PostgreSQL-specific query achieves this?

CRUD operations Medium
A. sql
INSERT INTO users (email) VALUES ('test@example.com') WHERE email != 'test@example.com';
B. sql
IF NOT EXISTS (SELECT 1 FROM users WHERE email = 'test@example.com') THEN
INSERT INTO users (email) VALUES ('test@example.com');
END IF;
C. sql
INSERT INTO users (email) VALUES ('test@example.com') ON CONFLICT (email) DO NOTHING;
D. sql
INSERT INTO users (email) VALUES ('test@example.com') ON DUPLICATE KEY IGNORE;

29 Which SQL statement correctly updates the price of a product and returns its new price and name in a single, atomic operation in PostgreSQL?

CRUD operations Medium
A. sql
UPDATE products SET price = 150.00 WHERE id = 42 RETURNING name, price;
B. sql
UPDATE products SET price = 150.00 WHERE id = 42 OUTPUT updated.name, updated.price;
C. sql
UPDATE products SET price = 150.00 WHERE id = 42;
SELECT name, price FROM products WHERE id = 42;
D. sql
BEGIN;
UPDATE products SET price = 150.00 WHERE id = 42;
SELECT name, price FROM products WHERE id = 42;
COMMIT;

30 An orders table has a product_id foreign key referencing the products table with the ON DELETE RESTRICT action. What is the outcome if you attempt to delete a product that is referenced by at least one order?

CRUD operations Medium
A. The delete operation is blocked, and a foreign key violation error is returned.
B. The product is deleted, and the product_id in the orders table is set to NULL.
C. The product is deleted, and all corresponding orders are also deleted.
D. The product is deleted, and the product_id in orders is set to its default value.

31 How would you write a query to select all tasks and order them by their priority (High, Medium, Low) and then by their creation_date in descending order?

CRUD operations Medium
A. sql
ORDER BY FIELD(priority, 'High', 'Medium', 'Low'), creation_date DESC
B. sql
ORDER BY priority, creation_date
C. sql
ORDER BY creation_date DESC, priority ASC
D. sql
ORDER BY
CASE priority
WHEN 'High' THEN 1
WHEN 'Medium' THEN 2
WHEN 'Low' THEN 3
END,
creation_date DESC

32 In a Prisma schema, how do you define a one-to-many relationship where a User can have multiple Post records?

PostgreSQL modeling with Prisma ORM Medium
A. By adding posts Post[] to the User model and author User to the Post model, letting Prisma handle the foreign key implicitly.
B. By creating an explicit join table model called UserPosts with relations to both User and Post.
C. By adding posts Post[] to the User model and author User @relation(fields: [authorId], references: [id]) and authorId Int to the Post model.
D. By adding userId Int to the User model and posts Post[] @relation(fields: [userId], references: [id]).

33 You have updated your schema.prisma file. What is the primary purpose of running the prisma migrate dev command?

PostgreSQL modeling with Prisma ORM Medium
A. To re-generate the Prisma Client to reflect the new schema types.
B. To push the schema changes directly to the database without creating a migration file.
C. To seed the database with initial test data.
D. To create a new SQL migration file based on schema changes and apply it to the database.

34 Using the Prisma Client in a TypeScript application, which query finds a unique user by their email and includes their 10 most recent posts, sorted by creation date?

PostgreSQL modeling with Prisma ORM Medium
A. typescript
await prisma.user.findUnique({
where: { email },
include: {
posts: {
orderBy: { createdAt: 'desc' },
take: 10
}
}
});
B. typescript
await prisma.user.findUnique({
where: { email },
select: {
posts: { take: 10, sort: 'createdAt' }
}
});
C. typescript
await prisma.user.findMany({
where: { email },
include: { posts: { limit: 10 } }
});
D. typescript
await prisma.user.findUnique({
where: { email },
include: { posts: true }
});

35 What is the purpose of the prisma db pull command in a Prisma workflow?

PostgreSQL modeling with Prisma ORM Medium
A. It applies pending migration files to the database schema.
B. It introspects the existing database and updates the schema.prisma file to match.
C. It pulls the latest version of the Prisma CLI from the internet.
D. It seeds the database by pulling data from a remote source.

36 You need to create a new user and a new profile for that user in a single, atomic database transaction. Which Prisma Client feature is designed for this purpose?

PostgreSQL modeling with Prisma ORM Medium
A. The prisma.$queryRaw() method.
B. A nested write operation within a single create call.
C. The prisma.$executeRaw() method with transaction control statements.
D. Executing two await calls sequentially for user.create and profile.create.

37 You have a products table with a tags column of type jsonb. The tags are stored as an array of strings, e.g., ["electronics", "mobile"]. Which query correctly finds all products that have the tag 'electronics'?

Basic SQL commands Medium
A. sql
SELECT * FROM products WHERE tags LIKE '%electronics%';
B. sql
SELECT * FROM products WHERE tags->>'electronics' IS NOT NULL;
C. sql
SELECT * FROM products WHERE 'electronics' IN tags;
D. sql
SELECT * FROM products WHERE tags @> '"electronics"';

38 Which of the following statements best describes the purpose of the template1 database in a PostgreSQL cluster?

Introduction to PostgreSQL database Medium
A. It is the primary database used for storing application data by default.
B. It is a system database that stores all global configuration settings and user roles.
C. It is a backup database that is restored automatically in case of a crash.
D. It is a template that is copied to create new user databases.

39 From the command line on a Linux server, which utility is most commonly used to connect to a PostgreSQL database, execute SQL queries interactively, and view the results?

PostgreSQL installation Medium
A. psql
B. pg_ctl
C. pg_dump
D. createdb

40 You need to sort a list of products by their last_updated timestamp in descending order, but products that have never been updated (NULL timestamp) should appear at the very beginning of the list. Which ORDER BY clause accomplishes this?

CRUD operations Medium
A. ORDER BY last_updated DESC NULLS LAST
B. ORDER BY last_updated ASC NULLS FIRST
C. ORDER BY last_updated DESC
D. ORDER BY last_updated DESC NULLS FIRST

41 A transaction T1 is running at the REPEATABLE READ isolation level. It executes SELECT COUNT(*) FROM products WHERE category = 'electronics'. Before T1 commits, another transaction T2 commits after successfully inserting a new product with category = 'electronics'. If T1 re-runs the same SELECT query, what will be the result, and why?

Introduction to PostgreSQL database Hard
A. The transaction T1 will be aborted with a serialization failure error when it tries to re-run the query.
B. The count will be the same as the first read, because REPEATABLE READ in PostgreSQL uses an MVCC snapshot taken at the start of the transaction, which prevents phantom reads.
C. The count will be the same as the first read, but a warning will be issued indicating that the underlying data has changed.
D. The count will be higher, because REPEATABLE READ as defined by the SQL standard does not prevent phantom reads.

42 In a high-traffic PostgreSQL database with frequent UPDATE and DELETE operations, what is the most critical, system-halting consequence of autovacuum failing to run or being unable to keep up with the rate of change for an extended period?

Introduction to PostgreSQL database Hard
A. Query performance will degrade due to excessive table and index bloat from dead tuples.
B. The Write-Ahead Log (WAL) will grow indefinitely, consuming all available disk space.
C. The database will stop accepting WRITE operations due to the risk of transaction ID (XID) wraparound failure.
D. The query planner will generate increasingly inefficient plans due to stale statistics.

43 Which statement most accurately describes the relationship between a Checkpoint and the Write-Ahead Log (WAL) in PostgreSQL's recovery mechanism?

Introduction to PostgreSQL database Hard
A. During a checkpoint, the database pauses all write operations to create a consistent snapshot of the data files, which is then recorded in the WAL.
B. A checkpoint exclusively removes old WAL files that are no longer needed for recovery, which is its primary method for managing disk space.
C. A checkpoint is a point in the WAL sequence such that all data file modifications due to transactions committed before this point are guaranteed to be written to disk, allowing recovery to start from this point instead of the beginning of the logs.
D. A checkpoint flushes the WAL buffers to disk, ensuring that all subsequent COMMIT operations are durable.

44 PostgreSQL uses a multi-process architecture where the main 'postmaster' process forks a new backend process for each client connection. In contrast, many other databases use a multi-threaded model. What is a key architectural trade-off of PostgreSQL's approach?

Introduction to PostgreSQL database Hard
A. Lower memory usage per connection because processes share memory more efficiently than threads, but with a higher risk of a single connection crash bringing down the server.
B. Faster connection startup time at the cost of reduced security, as all connections share the same memory space.
C. Better scalability on multi-core CPUs because of OS-level process scheduling, but with more complex code for inter-process communication.
D. Higher stability and fault isolation at the cost of higher memory consumption per connection and potentially slower connection startup.

45 You are tuning a PostgreSQL server for a data warehouse workload characterized by a few, very large, complex queries running concurrently. These queries perform large joins, aggregations, and sorting. You observe significant temporary file I/O. Which two parameters in postgresql.conf are most crucial to adjust to optimize for this specific workload?

PostgreSQL installation Hard
A. work_mem and shared_buffers
B. work_mem and maintenance_work_mem
C. max_connections and wal_buffers
D. shared_buffers and effective_cache_size

46 A pg_hba.conf file contains the following entries in this specific order:


# TYPE DATABASE USER ADDRESS METHOD
host all all 192.168.1.0/24 scram-sha-256
host all admin 192.168.1.50/32 reject


A user 'admin' attempts to connect from the IP address 192.168.1.50 to the sales database. What will be the outcome of the connection attempt?

PostgreSQL installation Hard
A. The connection will be rejected.
B. The connection will succeed using scram-sha-256 authentication.
C. The connection will fail with an error because of a configuration conflict.
D. The connection will succeed because the more specific IP address rule (/32) always takes precedence over a less specific CIDR range (/24).

47 To mitigate I/O spikes during checkpoints, a DBA sets checkpoint_completion_target = 0.9. How does this setting interact with checkpoint_timeout and max_wal_size?

PostgreSQL installation Hard
A. It instructs PostgreSQL to try and spread the checkpoint's write activity over 90% of the duration between checkpoints, whether the checkpoint was triggered by time (checkpoint_timeout) or WAL size (max_wal_size).
B. It has no effect on time-based checkpoints (checkpoint_timeout) and only applies to checkpoints triggered by max_wal_size.
C. It forces the checkpoint to finish within the first 90% of the checkpoint_timeout interval, leaving the last 10% of the time as an I/O-free buffer.
D. It reduces the amount of data written during a checkpoint by 90%, delaying the rest of the writes until the next checkpoint.

48 You are configuring a PostgreSQL server that will be accessed by an application running inside a Docker container on the same host machine. For maximum performance and security, what is the recommended host type to use in pg_hba.conf for this connection?

PostgreSQL installation Hard
A. host with the Docker bridge network's CIDR address (e.g., 172.17.0.0/16)
B. host with address ::1/128
C. local
D. host with address 127.0.0.1/32

49 Given a table page_views with user_id and view_timestamp, you want to calculate the average time between consecutive page views for each user. A single SELECT statement is required. Which combination of SQL features is best suited for this?

Basic SQL commands Hard
A. The LAG() window function to get the timestamp of the previous view, followed by aggregation on the calculated time difference.
B. A LATERAL JOIN to find the previous page view for each row.
C. A self-join on page_views with the condition t1.view_timestamp > t2.view_timestamp and GROUP BY t1.user_id.
D. A recursive CTE to iterate through each user's page views.

50 You have a table employees (id, name, department, salary). You need to write a query that returns each employee's name, department, and their salary's rank within their department, but also their salary's rank across the entire company, both in separate columns. Which query correctly achieves this?

Basic SQL commands Hard
A. sql
WITH dept_rank AS (
SELECT id, RANK() OVER (PARTITION BY department ORDER BY salary DESC) r FROM employees
), overall_rank AS (
SELECT id, RANK() OVER (ORDER BY salary DESC) r FROM employees
)
SELECT e.name, e.department, dr.r, or.r
FROM employees e JOIN dept_rank dr ON e.id = dr.id JOIN overall_rank or ON e.id = or.id;
B. sql
SELECT name, department,
RANK() OVER (PARTITION BY department ORDER BY salary DESC) as dept_rank,
RANK() OVER (ORDER BY salary DESC) as overall_rank
FROM employees;
C. sql
SELECT name, department,
(SELECT COUNT() + 1 FROM employees e2 WHERE e2.department = e1.department AND e2.salary > e1.salary) as dept_rank,
(SELECT COUNT(
) + 1 FROM employees e2 WHERE e2.salary > e1.salary) as overall_rank
FROM employees e1;
D. sql
SELECT name, department,
RANK() OVER (ORDER BY department, salary DESC) as dept_rank,
RANK() OVER (ORDER BY salary DESC) as overall_rank
FROM employees;

51 What is the primary difference in behavior between ROW_NUMBER(), RANK(), and DENSE_RANK() when used as window functions on a set of rows with duplicate values in the ORDER BY clause?

Basic SQL commands Hard
A. All three functions produce the same result unless a PARTITION BY clause is also used.
B. ROW_NUMBER and DENSE_RANK are identical, but RANK leaves gaps for ties.
C. ROW_NUMBER assigns unique numbers, RANK leaves gaps after ties, DENSE_RANK does not leave gaps after ties.
D. RANK and DENSE_RANK are identical, but ROW_NUMBER assigns a random number to break ties.

52 You have a products table and a product_tags table (product_id, tag). You need to find all products that have the tag 'new' AND the tag 'sale', but NOT the tag 'clearance'. Which query is the most efficient and accurate way to express this complex set-based condition?

Basic SQL commands Hard
A. sql
SELECT product_id FROM product_tags
GROUP BY product_id
HAVING ARRAY_AGG(tag) @> ARRAY['new', 'sale']
AND NOT (ARRAY_AGG(tag) && ARRAY['clearance']);
B. sql
SELECT p.* FROM products p WHERE
EXISTS (SELECT 1 FROM product_tags WHERE product_id = p.id AND tag = 'new') AND
EXISTS (SELECT 1 FROM product_tags WHERE product_id = p.id AND tag = 'sale') AND
NOT EXISTS (SELECT 1 FROM product_tags WHERE product_id = p.id AND tag = 'clearance');
C. sql
SELECT product_id FROM product_tags WHERE tag = 'new'
INTERSECT
SELECT product_id FROM product_tags WHERE tag = 'sale'
EXCEPT
SELECT product_id FROM product_tags WHERE tag = 'clearance';
D. sql
SELECT p.* FROM products p
JOIN product_tags t1 ON p.id = t1.product_id AND t1.tag = 'new'
JOIN product_tags t2 ON p.id = t2.product_id AND t2.tag = 'sale'
LEFT JOIN product_tags t3 ON p.id = t3.product_id AND t3.tag = 'clearance'
WHERE t3.product_id IS NULL;

53 You have a counters table with a name (unique) and value column. You need an atomic operation to increment a counter by 1. If the counter does not exist, it should be inserted with an initial value of 1. Which SQL statement correctly performs this "upsert-increment" operation?

CRUD operations Hard
A. sql
UPDATE counters SET value = value + 1 WHERE name = 'page_views';
IF NOT FOUND THEN
INSERT INTO counters (name, value) VALUES ('page_views', 1);
END IF;
B. sql
INSERT INTO counters (name, value) VALUES ('page_views', 1)
ON CONFLICT (name) DO UPDATE SET value = counters.value + 1;
C. sql
INSERT INTO counters (name, value) VALUES ('page_views', 1)
ON CONFLICT (name) DO UPDATE SET value = counters.value + EXCLUDED.value;
D. sql
INSERT INTO counters (name, value) VALUES ('page_views', 1)
ON CONFLICT (name) DO UPDATE SET value = value + 1;

54 You are implementing a 'soft delete' pattern by updating a deleted_at timestamp on a table. To prevent race conditions where two processes try to soft-delete the same record, you want to ensure the UPDATE only affects the row if it hasn't been deleted already. You also need to get the id of the row that was successfully updated. Which query is the most robust?

CRUD operations Hard
A. sql
UPDATE products SET deleted_at = NOW()
WHERE id = 123 AND deleted_at IS NULL
RETURNING id;
B. sql
WITH updated AS (
UPDATE products SET deleted_at = NOW() WHERE id = 123
)
SELECT id FROM products WHERE id = 123 AND deleted_at IS NOT NULL;
C. sql
BEGIN;
SELECT id FROM products WHERE id = 123 AND deleted_at IS NULL FOR UPDATE;
-- (check in application logic if a row was returned)
UPDATE products SET deleted_at = NOW() WHERE id = 123;
COMMIT;
SELECT id FROM products WHERE id = 123;
D. sql
UPDATE products SET deleted_at = NOW() WHERE id = 123;
SELECT id FROM products WHERE id = 123 AND deleted_at IS NOT NULL;

55 What is a data-modifying Common Table Expression (CTE) in PostgreSQL, and what is a key advantage of using one for a task like moving rows from one table to another?

CRUD operations Hard
A. It is a feature that allows SELECT statements to modify data in memory without writing to disk, improving performance for read-heavy workloads.
B. It is a CTE that contains an UPDATE, INSERT, or DELETE statement. Its key advantage is that the entire operation, including the data modification and any subsequent use of the modified data (e.g., in an INSERT), occurs within a single atomic statement.
C. It is a view that can be updated, allowing UPDATE statements to be run directly against the view definition.
D. It is a special type of trigger that modifies data in a temporary table before committing to the main table, primarily used for logging.

56 Consider a DELETE statement with a USING clause: DELETE FROM employees_staging es USING employees_production ep WHERE es.employee_id = ep.employee_id;. What does this statement do?

CRUD operations Hard
A. It attempts to delete from employees_staging, but will fail because the alias es is not referenced in the WHERE clause.
B. It deletes all rows from employees_production that have a matching employee_id in employees_staging.
C. It deletes all rows from employees_staging that have a matching employee_id in employees_production.
D. It deletes rows from both employees_staging and employees_production where the employee_id matches.

57 You have a Prisma schema with a many-to-many relationship between Post and Tag using an explicit join table. How do you write a Prisma Client query to find all Posts that have at least one Tag with a name starting with 'tech' and are also written by a User whose email contains '@example.com'?

PostgreSQL modeling with Prisma ORM Hard
A. javascript
prisma.post.findMany({
where: {
tags: { every: { tag: { name: { startsWith: 'tech' } } } },
author: { email: { contains: '@example.com' } }
}
});
B. javascript
prisma.post.findMany({
where: {
AND: [
{ tags: { some: { tag: { name: { startsWith: 'tech' } } } } },
{ author: { email: { contains: '@example.com' } } }
]
}
});
C. javascript
prisma.post.findMany({
include: { tags: true, author: true },
where: {
tags: { name: { startsWith: 'tech' } },
author: { email: { contains: '@example.com' } }
}
});
D. javascript
prisma.post.findMany({
where: {
tags: { some: { tag: { name: { startsWith: 'tech' } } } },
author: { email: { contains: '@example.com' } }
}
});

58 You need to perform a complex, multi-step operation: 1. Read a user's profile. 2. Based on their country, calculate a shipping cost. 3. Create a new order for that user with the calculated cost. 4. Decrement the stock of the ordered product. This entire sequence must be atomic. Which Prisma feature is specifically designed for such interdependent read-then-write operations within a single transaction?

PostgreSQL modeling with Prisma ORM Hard
A. Using prisma.$transaction(async (tx) => { ... }) with an interactive transaction callback.
B. Executing the operations sequentially with await, relying on the database's default transaction handling.
C. Using prisma.$transaction([ ... ]) with an array of Prisma client operations.
D. Using prisma.$executeRawUnsafe() to manually write a PL/pgSQL function that encapsulates the logic.

59 What is the primary purpose of the 'shadow database' used by Prisma Migrate during development (prisma migrate dev)?

PostgreSQL modeling with Prisma ORM Hard
A. To store the schema.prisma file's state, allowing for version control of the schema.
B. To test the application of new migrations in a clean, temporary environment before applying them to the main development database, ensuring migrations are repeatable and detecting drift.
C. To cache query results from the development database to speed up repeated queries during the development process.
D. To serve as a hot backup of the development database that can be restored instantly.

60 In a Prisma schema, you define a one-to-many relation between User and Post. What is the functional difference between defining the relation field on the User model as posts Post[] versus omitting it entirely?

PostgreSQL modeling with Prisma ORM Hard
A. Omitting the back-relation field (posts Post[]) makes the relation uni-directional from the Post's perspective. You can still query from Post to User, but you cannot easily query from User to their Posts via the Prisma Client's fluent API.
B. Omitting the field corrupts the foreign key constraint in the underlying database schema generated by Prisma Migrate.
C. There is no functional difference; the posts Post[] field is purely for documentation and is ignored by the Prisma Client.
D. Omitting the field prevents you from creating Post records associated with a User.