复合主键或超出整数(数字)主键

时间:2015-03-10 14:04:13

标签: sql oracle datatable

我需要在表格创建方面提出建议。哪个最好?如果你能解释原因,那将是非常感激的。

CREATE TABLE TRANSLATION (
       LANGUAGE_CODE CHAR(2) NOT NULL,
       TRANSLATION VARCHAR2(30) NOT NULL,
       OBJECT_ID NUMBER NOT NULL,
       OBJECT_TYPE VARCHAR(10) NOT NULL,
       CONSTRAINT P$TR#PRIMARY PRIMARY KEY (LANGUAGE_CODE, OBJECT_ID, OBJECT_TYPE)
)

CREATE TABLE TRANSLATION (
       ID NUMBER NOT NULL,
       LANGUAGE_CODE CHAR(2) NOT NULL,
       TRANSLATION VARCHAR2(30) NOT NULL,
       OBJECT_ID NUMBER NOT NULL,
       OBJECT_TYPE VARCHAR(10) NOT NULL,
       CONSTRAINT P$TR#PRIMARY PRIMARY KEY (ID),
       CONSTRAINT P$TR#PRIMARY UNIQUE (LANGUAGE_CODE, OBJECT_ID, OBJECT_TYPE)
)

正如您在第二个示例中仅在现有主键中看到的那样。我将永远不必通过id找到这样的行,因为没有其他表引用它。 我使用Oracle db

0 个答案:

没有答案