• Home
  • Project
    Introduction
    • Introduction
    • Background and Motivation
    • What is a Good Timetable?
    • Project Aims and Scope
  • Graph Data
    Model
    • Graph vs Relational Data Models
    • Graph Data Model for Timetabling
    • Early Insights
    • Model Expansion
    • Graphing Time
  • Data
    Pipeline
    • ETL Overview
    • Approach
    • Configuration and Logging
    • Extract
    • Transform
    • Google Drive Load
    • Neo4j Load
    • Reflection
  • Timetable
    Metrics
    • Timetable Metrics
    • Metric Aggregations
    • Implementing Metrics
    • TQI Summary
  • Final
    Thoughts
  • Appendices
    & Extras
    • Appendix Table of Contents
    • References
    • Acknowledgements
  • Word
  1. Appendices
  2. Neo4j & Cypher Code
  3. Deleting Nodes and Relationships
  • Home
  • Project Introduction
    • Introduction
    • Background and Motivation
    • What is a Good Timetable?
    • Project Aims and Scope
  • Graph Data Model
    • Graph vs Relational Data Models
    • Graph Data Model for Timetabling
    • Early Insights
    • Model Expansion
    • Graphing Time
  • Data Pipeline
    • ETL Overview
    • Approach
    • Configuration and Logging
    • Extract
    • Transform
    • Google Drive Load
    • Neo4j Load
    • Reflection
  • Timetable Metrics
    • Timetable Metrics
    • Metric Aggregations
    • Implementing Metrics
    • TQI Summary
  • Final Thoughts
  • Appendices
    • Random Graph Generator
    • Technology Stack
    • Configuration
    • Anonymisation
    • ETL Summary and Code
      • ETL Summary
      • ETL Code
      • Config and Misc
      • Extract-SQL
      • Extract
      • Google Drive Load
      • Transform
      • Neo4j Load
    • Neo4j & Cypher Code
      • Cypher Queries
      • Creating Nodes and Relationships
      • Deleting Nodes and Relationships
      • General Queries
      • Count Queries
      • Hard (timetabling) Constraints
      • Student Clashes
      • Soft Constraints
      • Rooms and Spaces
      • Perspectives
      • Blue Skies Opportunities
  • Supervision
    • Supervision
    • Notes Example 1
    • Notes Example 2
    • Notes Example 3
  • References
  • Acknowledgements

On this page

  • Deleting Nodes
    • Example: Deleting a Student Node
  • Deleting Relationships
    • Example: Deleting a Relationship Between a Student and an Activity
  1. Appendices
  2. Neo4j & Cypher Code
  3. Deleting Nodes and Relationships

O: Deleting Nodes and Relationships


Deleting nodes and relationships, using the DELETE clause in Cypher, is an important operation in managing the graph database.

Deleting Nodes

The general syntax for deleting a node is:

MATCH (n:NodeLabel {propertyName: propertyValue})
DELETE n

Where:

  • n is the node variable
  • NodeLabel is the label assigned to the node
  • propertyName is the property name
  • propertyValue is the value assigned to the property
  • DELETE is used to delete the node
  • MATCH is used to find the node to delete
  • ... represents additional properties

Example: Deleting a Student Node

MATCH (s:Student {studentID: '123456'})
DELETE s

Deleting Relationships

The general syntax for deleting a relationship is:

MATCH (n1:NodeLabel1)-[r:RELATIONSHIP_TYPE]->(n2:NodeLabel2)
DELETE r

Where:

  • n1 and n2 are the node variables
  • NodeLabel1 and NodeLabel2 are the labels assigned to the nodes
  • r is the relationship variable
  • RELATIONSHIP_TYPE is the type of relationship
  • DELETE is used to delete the relationship
  • MATCH is used to find the relationship to delete
  • ... represents additional properties

Example: Deleting a Relationship Between a Student and an Activity

MATCH (s:Student {studentID: '123456'})-[r:ATTENDS]->(a:Activity {activityID: '789'})
DELETE r
Creating Nodes and Relationships
General Queries

Copyright 2024, Petter Lövehagen

 

Built with Quarto