How can I delete all of the nodes and relationships from the Memgraph database? - cypher

I want to delete all of the nodes and relationships from the Memgraph database. I know that could create a whole instance, but I don't want to do that.
Which Cypher query can I use to delete the content of the Memgraph database?

To delete all nodes and relationships from your Memgraph database use the following Cypher query:
MATCH (n)
DETACH DELETE n;

Related

How to delete records of multiple tables in one go? Sqlite

For a project i need to to delete all data from all tables in a database,
I tried
DELETE FROM table1,table2,table3,...;
But it doesnt work. Any advice ? Thank
I would like to refer You to this related post
How do I use cascade delete with SQL Server?
as You will find there several possible solutions.
When using SQL it means that Your data is relations, which means most of the records are somehow related in the different tables and this relation is expressed with foreign keys. However when attempting to delete data which is id is related with data in another table a cascade deletion should be implemented, the other way around it is add additional boolean column named isDeleted(as example ofcourse) and just alter specific rows to true in this specific column and then filter by preferences. Hopefully I have managed somehow to provide with alternative and/or possible solution to Your problem.
Leaving also this link which gives some examples on cascade deletion and guide on how to implement it. ->
https://www.sqlshack.com/delete-cascade-and-update-cascade-in-sql-server-foreign-key/
P.S. also if You want just to DELETE all the data You can either use TRUNCATE TABLE or DROP DATABASE query. With the latest option You will have to recreate the database once more.
Because you want to delete all databases from all tables, you are essentially deleting the database.
The sqlite way of doing this is to just delete the database file.
In contrast to postgres or mongodb or most databases, sqlite doesn't have a server so no need to call DROP DATABASE.
As soon as the file is gone and you open the database from your application you will be in a blank state again.

How can I delete relationships belonging to a node using Cypher in Memgraph?

I have a node, and I want to delete all of the relationships for that node. I've tried to use MATCH (node) DELETE node; but I get an error. What am I doing wrong?
Cypher prevents accidental deletion of relationships. You need to use the DETACH keyword, which will remove relationships from a node you are deleting. The following should work and delete everything in the database:
MATCH (node) DETACH DELETE node;

How to delete items with a many-to-many relationship with 'WHERE' clause in a stored procedure?

In my MSSQL database I have the following three tables:
Tasks
Files
TaskFile
As one can imagine, TaskFile simply maps IDs of the Tasks table to the IDs of the Files table having foreign key constraints to them. I do most of my database operations using stored procedures. Deleting a single file by ID is then easy, I simply have to delete the entries in TaskFile first:
CREATE PROCEDURE [dbo].[spFile_Delete]
#ID INT = 0
AS
BEGIN
DELETE
FROM dbo.[TaskFile]
WHERE FileID = #ID;
DELETE
FROM dbo.[File]
WHERE ID = #ID;
END
However, I'm wondering what the recommended way is to delete multiple files. For example, file entries belong to a dataset and therefore hold a reference to a DatasetID. I have the following procedure to delete by DatasetID however this needs to be adapted to work with the foreign key constraint:
CREATE PROCEDURE [dbo].[spFile_DeleteByDataset]
#DatasetID NVARCHAR(128)
AS
BEGIN
DELETE
FROM dbo.[File]
WHERE DatasetID = #DatasetID;
END
The most straight forward way I can think of, is to first query all the FileIDs with the given DatasetID and then use them to delete all entries in TaskFile first. This should work, but doesn't seem like the best solution, especially if I want to go further and have for example have a stored procedure to delete datasets. Now I would have to:
Find all the files belonging to the dataset
Find all the references in TaskFile and delete dem
Delete all File entries
Delete the dataset entry
and for each relationship this would go further and further and get more and more complicated.
Basically I'm asking for some best practices in such cases. I'm fairly new when it comes to database management and these convolution seem like a good source for errors. Should each stored procedure only handle it's specific table and I have to manage the correct order of entries/updates/deletions in the data access layer code? Is there a way to automate changes with foreign relationships? Or should you simply never delete anything from the database and only have a flag 'deleted' in a separate column?
Oh I believe you are talking about DELETE/UPDATE CASCADE. It's usually not advised because in general you don't want to delete more than you are targeting in the moment. But depending on the scenario it can be used. For example in your case i believe it's ok: if FileTask has ON DELETE CASCADE in the reference to File, when you delete straight the table File, all FileTask related to this file would be deleted together and you wouldn't need to worry about deleting FileTask before. In your case when you want to delete a file, you also want to delete related FileTasks.

Query to delete single row in Impala

I would like to delete on record from impala table. Below I have used to delete the record from the table.
This is My Query :
DELETE FROM sample.employee_details WHERE sno=5 AND name='XYZ'AND age=26;
suggest the best way to remove a record from the table.
This is fine assuming your where conditions uniquely identify the row. See the documentation:
https://www.cloudera.com/documentation/enterprise/5-10-x/topics/impala_delete.html
Impala delete command works only for Kudu storage type. Any storage formats other than kudu are not designed for online transactions and does not offer any real-time queries and row level updates and deletes.

How to delete all the entities in Azure table?

I've been working on deleting all the rows in Azure table in java. Can I do it without querying it?
Thanks in advance
If I retrieve all the data, can I perform delete query on that?
If you just want to delete data, you just need to retrieve PKs and RKs. After retrieved all the data of PKs and RKs, you could perform the delete query for the entities one by one.
For complex delete query, for example, below query is not supported currently.
delete from tablename where PK = ''
I suggest you submit your idea on Azure feedback site which is used for features request.
https://feedback.azure.com/forums/217298-storage
If you don't want to query the table, what you can do is to delete the table and recreate it.