/*******************************************************************************************************************
-- Title : [SQL2017] Graph Table 컨셉 및 Create and Insert Graph Table
-- Reference : docs.microsoft.com
-- Key word : graph table 그래프 테이블 그래프테이블 node table edge table 노드 엣지 graph database
그래프 데이터베이스
*******************************************************************************************************************/



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
USE tempdb;
go
-- 테이블 초기화
drop table person, friend, likes;
-- Create node table
CREATE TABLE Person
( ID INTEGER PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
age int
) AS NODE;
-- Insert into node table
INSERT INTO dbo.Person VALUES (1, 'John', 'aaa@a.co.kr', 30);
INSERT INTO dbo.Person VALUES (2, 'Mary', 'bbb@a.co.kr', 28);
INSERT INTO dbo.Person VALUES (3, 'Alice', 'ccc@a.co.kr', 25);
-- Select node table
select * from person;
-- Create edge table
CREATE TABLE friend
( id integer PRIMARY KEY,
start_date date
) AS EDGE;
-- Insert into edge table
INSERT INTO dbo.friend
VALUES ( (SELECT $node_id FROM dbo.Person WHERE name = 'John')
, (SELECT $node_id FROM dbo.Person WHERE name = 'Mary')
, 11
, '01/01/2013');
INSERT INTO dbo.friend
VALUES ( (SELECT $node_id FROM dbo.Person WHERE name = 'Mary')
, (SELECT $node_id FROM dbo.Person WHERE name = 'Alice')
, 22
, '05/05/2010');
INSERT INTO dbo.friend
VALUES ( (SELECT $node_id FROM dbo.Person WHERE name = 'Alice')
, (SELECT $node_id FROM dbo.Person WHERE name = 'John')
, 33
, '09/09/2016');
-- Select edge table
select * from friend;
-- Create a likes edge table, this table does not have any user defined attributes
CREATE TABLE likes AS EDGE;
-- 테이블 확인
select * from person;
select * from friend;
select * from likes;
|
cs |