我试图在SAP HANA中创建2个(多个)顶点,如 -
为顶点创建两个表 ITEM 和 DATASET
CREATE COLUMN TABLE "GREEK_MYTHOLOGY"."ITEM" (
"ITEM_ID" VARCHAR(100) PRIMARY KEY,
"ITEM_NAME" VARCHAR(100)
);
CREATE COLUMN TABLE "GREEK_MYTHOLOGY"."DATASET" (
"DATASET_ID" VARCHAR(100) PRIMARY KEY,
"DATASET_NAME" VARCHAR(100)
);
创建优势 REFERENCES
CREATE COLUMN TABLE "GREEK_MYTHOLOGY"."REFERENCES" (
"REF_ID" INT UNIQUE NOT NULL,
"SOURCE" VARCHAR(100) NOT NULL
REFERENCES "GREEK_MYTHOLOGY"."ITEM" ("ITEM_ID")
ON UPDATE CASCADE ON DELETE CASCADE,
"TARGET" VARCHAR(100) NOT NULL
REFERENCES "GREEK_MYTHOLOGY"."DATASET" ("DATASET_ID")
ON UPDATE CASCADE ON DELETE CASCADE,
"TYPE" VARCHAR(100)
);
现在我想将两个顶点( ITEM 和 DATASET )连接到边缘参考,如下所示
CREATE GRAPH WORKSPACE "GREEK_MYTHOLOGY"."GRAPH"
EDGE TABLE "GREEK_MYTHOLOGY"."DATASET"
SOURCE COLUMN "SOURCE"
TARGET COLUMN "TARGET"
VERTEX TABLE "GREEK_MYTHOLOGY"."ITEM" KEY COLUMN "ITEM_ID"
VERTEX TABLE "GREEK_MYTHOLOGY"."DATASET"KEY COLUMN "DATASET_ID"
KEY COLUMN "REF_ID";
但是它会在行
处抛出异常VERTEX TABLE" GREEK_MYTHOLOGY"。" DATASET" KEY COLUMN" DATASET_ID"
sql syntax error: incorrect syntax near "VERTEX": line 6 col 1 (at pos 200)
是否可以在SAP HANA图中创建多个顶点?如果是,那么正确的方法是什么。
答案 0 :(得分:1)
这里存在误解。 REFERENCES
语句中的CREATE TABLE
子句与您要表示的图结构无关。
相反,它在两个表之间定义了外键约束。
CREATE GRAPH WORKSPACE
命令只接受一个EDGE TABLE
和一个VERTEX TABLE
作为参数。
不过,您也可以在此处传递同义词或观看次数。
这样,您可以像这样创建一个视图"ALL_ITEMS"
:
CREATE VIEW "GREEK_MYTHOLOGY"."ALL_ITEMS" as
SELECT "ITEM_ID" as "ID", "ITEM_NAME" as "NAME" FROM "GREEK_MYTHOLOGY"."ITEM"
UNION
SELECT "DATASET_ID" as "ID", "DATASET_NAME" as "NAME" FROM "GREEK_MYTHOLOGY"."DATASET";
然后引用此视图:
CREATE GRAPH WORKSPACE "GREEK_MYTHOLOGY"."GRAPH"
EDGE TABLE "GREEK_MYTHOLOGY"."DATASET"
SOURCE COLUMN "SOURCE"
TARGET COLUMN "TARGET"
VERTEX TABLE "GREEK_MYTHOLOGY"."ALL_ITEMS"
KEY COLUMN "NAME";
使用此方法是可行的,但您现在必须确保"NAME"
值在两个表中都是唯一的而不是NULL
。