Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-17-2020 10:44 AM
Hello guys!
I hope you guys are doing well today. I am new to NEO4j and need some suggestion/advice.
I successfully imported 3 different CSV files as A,B,C and now trying to create CONSTRAINT for all.
From my RDBMS, "reg_uid" (integer) is the primary key for all three tables (A,B,C).
If A,B,C has reg_uid on NEO4j, how do I make reg_uid as CONSTRAINT for A,B, and C?
Thank you so much.
06-17-2020 02:51 PM
Hello plee,
nice to meet you.
This is the reference you'll need, from the official docs: Neo4j's Cypher 4.0 Docs - Constraints
The correct syntax should be something like that, if I've understand well what you need:
CREATE CONSTRAINT ON (a:A) ASSERT a.reg_uid IS UNIQUE;
CREATE CONSTRAINT ON (b:B) ASSERT b.reg_uid IS UNIQUE;
CREATE CONSTRAINT ON (c:C) ASSERT c.reg_uid IS UNIQUE;
This create constraint without a name, but you can create named constraint
CREATE CONSTRAINT uniqueA ON (a:A) ASSERT a.reg_uid IS UNIQUE;
CREATE CONSTRAINT uniqueB ON (b:B) ASSERT b.reg_uid IS UNIQUE;
CREATE CONSTRAINT uniqueC ON (c:C) ASSERT c.reg_uid IS UNIQUE;
If you're using Enterprise Edition, maybe you want to make reg_uid a NODE KEY, so that a node of this type could not be created without it. This is the way for that:
CREATE CONSTRAINT nodeA ON (a:A) ASSERT a.reg_uid IS NODE KEY;
CREATE CONSTRAINT nodeB ON (b:B) ASSERT b.reg_uid IS NODE KEY;
CREATE CONSTRAINT nodeC ON (c:C) ASSERT c.reg_uid IS NODE KEY;
If you want to drop them, this is the way:
DROP CONSTRAINT uniqueA;
DROP CONSTRAINT uniqueB;
DROP CONSTRAINT uniqueC;
DROP CONSTRAINT nodeA;
DROP CONSTRAINT nodeB;
DROP CONSTRAINT nodeC;
Hope this will help you!
All the sessions of the conference are now available online