From the course: Master Next.js by Building Scalable Apps with Routing, Databases, and Performance

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

All possibilities of record deletion - delete() and deleteMany()

All possibilities of record deletion - delete() and deleteMany() - Next.js Tutorial

From the course: Master Next.js by Building Scalable Apps with Routing, Databases, and Performance

All possibilities of record deletion - delete() and deleteMany()

So, we have seen how insertion works. Now let's understand the ways and methods for deleting records. The Prisma Client object that is the DB offers the DELETE and DELETEMANY methods for deleting records from a table. Let's see the DELETE method first. The syntax is like this, where you call the method by DB.tableName.DELETE and then pass an object in it with the where property and assign an object with the field colon value that is field value pair. So for example, if I want to delete the record with id 5, then I will pass an object with the key value pair of id colon 5. Let's practically try it. Right now we have a duplicate product stored, so we will get rid of the later one that is ID number 5. We already have the action configured for deleting products and its code is in the product action.js file. Let me open it. I'll clear the query code and write await db.products.delete where ID is 5. Let's save this and check. I'll click on the delete button so that the action is called…

Contents