Created
August 1, 2018 05:22
-
-
Save jibinpb/5cfccc374b4693e7d0b21c8668f8e361 to your computer and use it in GitHub Desktop.
SQL Server GDB - Insert Data to Node and Edge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @ParentNodeId nvarchar(1000), @ChildNodeId nvarchar(1000) | |
DECLARE @EntityNodeDetails table(NodeId nvarchar(1000)); | |
-- Insert the Facebook as parent organization | |
INSERT dbo.Entity ([Name], [Code], [Type]) | |
OUTPUT INSERTED.$node_id | |
INTO @EntityNodeDetails | |
VALUES ('Facebook, Inc.', 'FB', 'Public') | |
-- Get inserted nodeId to variable | |
SELECT TOP 1 @ParentNodeId=NodeId FROM @EntityNodeDetails | |
-- Insert WhatsApp | |
DELETE FROM @EntityNodeDetails | |
INSERT dbo.Entity ([Name], [Code], [Type]) | |
OUTPUT INSERTED.$node_id | |
INTO @EntityNodeDetails | |
VALUES ('WhatsApp Inc.', 'WhatsApp', 'Private') | |
SELECT TOP 1 @ChildNodeId=NodeId FROM @EntityNodeDetails | |
-- Make WhatsApp as a Subsidiary of Facebook | |
INSERT INTO dbo.Subsidiaries VALUES (@ParentNodeId, @ChildNodeId, 100.00, '2014-02-19'); | |
-- Insert Instagram | |
DELETE FROM @EntityNodeDetails | |
INSERT dbo.Entity ([Name], [Code], [Type]) | |
OUTPUT INSERTED.$node_id | |
INTO @EntityNodeDetails | |
VALUES ('Instagram, Inc.', 'Instagram', 'Private') | |
SELECT TOP 1 @ChildNodeId=NodeId FROM @EntityNodeDetails | |
-- Make Instagram as a Subsidiary of Facebook | |
INSERT INTO dbo.Subsidiaries VALUES (@ParentNodeId, @ChildNodeId, 100.00, '2012-09-06'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment