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. Object-Relational
B. Graph-Based
C. Document-Oriented
D. Key-Value Store

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

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

3 Which of the following best describes PostgreSQL?

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

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

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

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

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

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

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

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

PostgreSQL installation Easy
A. sqlcmd
B. mongo-shell
C. psql
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-get start postgresql
B. sudo apt install postgresql
C. sudo apt-add postgresql
D. sudo apt-get configure postgresql

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

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

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

Basic SQL commands Easy
A. To retrieve data from a table
B. To define a new table and its columns
C. To create a new database
D. To add a new row of data to 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. CONDITION
B. HAVING
C. FILTER
D. WHERE

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

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

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

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

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

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

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

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

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

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

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 manage front-end state
D. To bundle JavaScript files

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. schema.prisma
B. models.js
C. database.yml
D. prisma.config

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 db seed
B. prisma init
C. prisma migrate dev
D. prisma generate

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 generate
B. prisma format
C. prisma deploy
D. prisma refresh

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. It completely eliminates the possibility of deadlocks.
B. It simplifies the transaction isolation levels, offering only one strict level.
C. Writers do not block readers, and readers do not block writers.
D. It uses less disk space because only one version of a row is ever stored.

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. Using a separate database for each tenant on the same server instance.
B. Using different tablespaces for each tenant.
C. Creating a separate schema 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. pg_ident.conf by mapping the remote user to a local user.
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. environment file by setting the PGHOST variable.

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 install the PostgreSQL software binaries on the operating system.
C. To start the main PostgreSQL server process (the postmaster).
D. To create a new database cluster, including system catalogs and default databases.

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 window function like RANK() or ROW_NUMBER() partitioned by department.
B. A GROUP BY clause with a MAX() aggregate function on the salary.
C. An ORDER BY clause on salary with a LIMIT 1 clause.
D. A subquery in the WHERE clause to find the global maximum 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 can be used with a WHERE clause for selective deletion.
B. DELETE is always faster as it logs less information to the WAL.
C. TRUNCATE is non-transactional and cannot be rolled back, while DELETE can.
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 HAVING clause to perform the second-step calculation.
B. Using a WITH clause to define a Common Table Expression (CTE).
C. Using nested subqueries in the FROM clause.
D. Creating a permanent VIEW for the daily sales.

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
INSERT INTO users (email) VALUES ('test@example.com') ON DUPLICATE KEY IGNORE;
C. sql
IF NOT EXISTS (SELECT 1 FROM users WHERE email = 'test@example.com') THEN
INSERT INTO users (email) VALUES ('test@example.com');
END IF;
D. sql
INSERT INTO users (email) VALUES ('test@example.com') ON CONFLICT (email) DO NOTHING;

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;
SELECT name, price FROM products WHERE id = 42;
B. sql
BEGIN;
UPDATE products SET price = 150.00 WHERE id = 42;
SELECT name, price FROM products WHERE id = 42;
COMMIT;
C. sql
UPDATE products SET price = 150.00 WHERE id = 42 OUTPUT updated.name, updated.price;
D. sql
UPDATE products SET price = 150.00 WHERE id = 42 RETURNING name, price;

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 product is deleted, and all corresponding orders are also deleted.
B. The product is deleted, and the product_id in the orders table is set to NULL.
C. The delete operation is blocked, and a foreign key violation error is returned.
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 priority, creation_date
B. sql
ORDER BY creation_date DESC, priority ASC
C. sql
ORDER BY
CASE priority
WHEN 'High' THEN 1
WHEN 'Medium' THEN 2
WHEN 'Low' THEN 3
END,
creation_date DESC
D. sql
ORDER BY FIELD(priority, 'High', 'Medium', 'Low'), 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 @relation(fields: [authorId], references: [id]) and authorId Int to the Post model.
B. By creating an explicit join table model called UserPosts with relations to both User and Post.
C. By adding userId Int to the User model and posts Post[] @relation(fields: [userId], references: [id]).
D. By adding posts Post[] to the User model and author User to the Post model, letting Prisma handle the foreign key implicitly.

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 create a new SQL migration file based on schema changes and apply it to the database.
B. To seed the database with initial test data.
C. To re-generate the Prisma Client to reflect the new schema types.
D. To push the schema changes directly to the database without creating a migration file.

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 },
select: {
posts: { take: 10, sort: 'createdAt' }
}
});
B. typescript
await prisma.user.findMany({
where: { email },
include: { posts: { limit: 10 } }
});
C. typescript
await prisma.user.findUnique({
where: { email },
include: { posts: true }
});
D. typescript
await prisma.user.findUnique({
where: { email },
include: {
posts: {
orderBy: { createdAt: 'desc' },
take: 10
}
}
});

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

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

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. Executing two await calls sequentially for user.create and profile.create.
B. The prisma.$queryRaw() method.
C. A nested write operation within a single create call.
D. The prisma.$executeRaw() method with transaction control statements.

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->>'electronics' IS NOT NULL;
B. sql
SELECT * FROM products WHERE tags @> '"electronics"';
C. sql
SELECT * FROM products WHERE tags LIKE '%electronics%';
D. sql
SELECT * FROM products WHERE 'electronics' IN tags;

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 a backup database that is restored automatically in case of a crash.
B. It is a system database that stores all global configuration settings and user roles.
C. It is the primary database used for storing application data by default.
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. createdb
C. pg_ctl
D. pg_dump

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
B. ORDER BY last_updated DESC NULLS LAST
C. ORDER BY last_updated DESC NULLS FIRST
D. ORDER BY last_updated ASC 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 count will be the same as the first read, but a warning will be issued indicating that the underlying data has changed.
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 transaction T1 will be aborted with a serialization failure error when it tries to re-run the query.
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. The query planner will generate increasingly inefficient plans due to stale statistics.
B. Query performance will degrade due to excessive table and index bloat from dead tuples.
C. The Write-Ahead Log (WAL) will grow indefinitely, consuming all available disk space.
D. The database will stop accepting WRITE operations due to the risk of transaction ID (XID) wraparound failure.

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. A checkpoint exclusively removes old WAL files that are no longer needed for recovery, which is its primary method for managing disk space.
B. A checkpoint flushes the WAL buffers to disk, ensuring that all subsequent COMMIT operations are durable.
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. 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.

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. Faster connection startup time at the cost of reduced security, as all connections share the same memory space.
B. Higher stability and fault isolation at the cost of higher memory consumption per connection and potentially slower connection startup.
C. Better scalability on multi-core CPUs because of OS-level process scheduling, but with more complex code for inter-process communication.
D. 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.

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 maintenance_work_mem
B. shared_buffers and effective_cache_size
C. max_connections and wal_buffers
D. work_mem and shared_buffers

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 fail with an error because of a configuration conflict.
C. The connection will succeed because the more specific IP address rule (/32) always takes precedence over a less specific CIDR range (/24).
D. The connection will succeed using scram-sha-256 authentication.

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 reduces the amount of data written during a checkpoint by 90%, delaying the rest of the writes until the next checkpoint.
B. 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.
C. It has no effect on time-based checkpoints (checkpoint_timeout) and only applies to checkpoints triggered by max_wal_size.
D. 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).

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. local
C. host with address ::1/128
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. A LATERAL JOIN to find the previous page view for each row.
B. The LAG() window function to get the timestamp of the previous view, followed by aggregation on the calculated time difference.
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
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;
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
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;
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 assigns unique numbers, RANK leaves gaps after ties, DENSE_RANK does not leave gaps after ties.
C. ROW_NUMBER and DENSE_RANK are identical, but RANK leaves gaps for 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 WHERE tag = 'new'
INTERSECT
SELECT product_id FROM product_tags WHERE tag = 'sale'
EXCEPT
SELECT product_id FROM product_tags WHERE tag = '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
GROUP BY product_id
HAVING ARRAY_AGG(tag) @> ARRAY['new', 'sale']
AND NOT (ARRAY_AGG(tag) && ARRAY['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
INSERT INTO counters (name, value) VALUES ('page_views', 1)
ON CONFLICT (name) DO UPDATE SET value = counters.value + EXCLUDED.value;
B. sql
INSERT INTO counters (name, value) VALUES ('page_views', 1)
ON CONFLICT (name) DO UPDATE SET value = value + 1;
C. 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;
D. sql
INSERT INTO counters (name, value) VALUES ('page_views', 1)
ON CONFLICT (name) DO UPDATE SET value = counters.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
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;
B. sql
UPDATE products SET deleted_at = NOW() WHERE id = 123;
SELECT id FROM products WHERE id = 123 AND deleted_at IS NOT NULL;
C. sql
UPDATE products SET deleted_at = NOW()
WHERE id = 123 AND deleted_at IS NULL
RETURNING id;
D. 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;

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 special type of trigger that modifies data in a temporary table before committing to the main table, primarily used for logging.
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 feature that allows SELECT statements to modify data in memory without writing to disk, improving performance for read-heavy workloads.

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 deletes all rows from employees_production that have a matching employee_id in employees_staging.
B. It deletes all rows from employees_staging that have a matching employee_id in employees_production.
C. It deletes rows from both employees_staging and employees_production where the employee_id matches.
D. It attempts to delete from employees_staging, but will fail because the alias es is not referenced in the WHERE clause.

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: {
AND: [
{ tags: { some: { tag: { name: { startsWith: 'tech' } } } } },
{ author: { email: { contains: '@example.com' } } }
]
}
});
B. javascript
prisma.post.findMany({
where: {
tags: { every: { 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([ ... ]) with an array of Prisma client operations.
B. Using prisma.$executeRawUnsafe() to manually write a PL/pgSQL function that encapsulates the logic.
C. Using prisma.$transaction(async (tx) => { ... }) with an interactive transaction callback.
D. Executing the operations sequentially with await, relying on the database's default transaction handling.

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 cache query results from the development database to speed up repeated queries during the development process.
B. To serve as a hot backup of the development database that can be restored instantly.
C. To store the schema.prisma file's state, allowing for version control of the schema.
D. 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.

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. Omitting the field prevents you from creating Post records associated with a User.
D. There is no functional difference; the posts Post[] field is purely for documentation and is ignored by the Prisma Client.