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

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;

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 all of the nodes and relationships from the Memgraph database?

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;

How to delete rows from H2 table with commited changes after each Junit test

I am using H2 in-memory DB for unit testing interaction with a database.
I need to clean commited changes in #After so that tables stay but all rows get wiped away (thus I cannot just drop tables). My database also has many foreign keys which makes even wiping objects one by one cumbersome as I have to do it in certain order.
Is there any way to clean rows in a database without dropping tables and preferably without deleting objects one by one?
To clean the rows, you can use the H2 TRUNCATE TABLE data definition command.
You can temporarily disable checking foreign key constraints by using H2's SET REFERENTIAL_INTEGRITY.

LINQ to SQL doesn't call DELETE

I am deleting a bunch of records from different tables that are linked with foreign keys. When I call 'SubmitChanges' the following error is received:
The DELETE statement conflicted with the REFERENCE constraint
FK_PTXProductMap_CustomerProduct". The conflict occurred in database "SOTI", table
"dbo.PTXProductMap", column 'InstanceId'.
The statement has been terminated.
I looked with profiler what queries are executed when SubmitChanges tries to save changes and DELETE SQL operation is not called for 2 records. I 100% sure that linq2sql-'DELETE' operation is called for them (I put a break point to the line:
IEnumerable<CustomerProduct> products = DbContext.CustomerProducts
.Where(cp => cp.InstanceId == transition.InstanceId
|| cp.InstanceId == transition.PreInstanceId);
foreach (CustomerProduct cp in products)
{
DbContext.CustomerProducts.DeleteOnSubmit(cp);
}
and checked if it was called for required cp object. DELETE is called for 2 another record from the same table... but not for all required
Do you have any ideas why this happened? And how to resolve that?
Any ideas are welcome.
P.S. I am working with VS2008 SP1, MS SQL 2005 under 64bit Windows 7
P.P.S. I've detected few records in another table that were linked to the deleted scope... including their deletion resolved current error, but it is still unclear why 'DELETE' operation was not generated for ALL records to be deleted.
P.P.P.S. Pretty similar situation for another pair of table: table A contains 1 record, table B - 3 records that refer to the A.1 They are unable to be deleted in one transaction, but if I delete them manually (through the Management Studio) I am able to delete 3 records from B and then record from A... WHY?
This article about DeleteOnSubmit contains a note dealing with cascade deletes. We recommend you to delete the child rows first, then there should be no problems with deleting parent entities.

SchemaExport, NHibernate and deleting foreign keys

I am building my mapping and then using schema export to update my DB. However, if I delete an association in my mapping, since it's no longer in the mapping, when I run SchemaExport, it will not delete the foreign key for the deleted association. This means that it then fails to drop the table associated with that foreign key. Which further means that it can't recreate the table and I get a "There is already an object named Foo in the database" exception. Is there any way to brute delete the table via Schema Export?
The cleanest way is to do SchemaExport.Drop with the old nhibernate configuration, then create with the new one.
Alternatively you could drop and recreate the database itself, here's an example which does this at file level for SQL Server Express: http://nicholas.piasecki.name/blog/2010/01/integration-testing-with-sql-server-express-2008-nhibernate-and-mstest/