English 中文(简体)
甲骨质外国关键关系
原标题:Oracle foreign key relation

我的<代码>表有一个综合的主要部分。

CREATE TABLE CANDIDATE(
CANDIDATE_ID VARCHAR(5),
NAME VARCHAR(30),
TELEPHONE NUMBER,
PRIMARY KEY(CANDIDATE_ID, NAME));

在我创建儿童桌子时,我发现了一个错误,即当我为加拿大发展协会(ID)创建外国钥匙时,参考栏数必须与参考栏相匹配。

CREATE TABLE JOB(
POSITION_ID VARCHAR(5) PRIMARY KEY,
CANDIDATE_ID VARCHAR(5),
DATE2 DATE,
FOREIGN KEY(CANDIDATE_ID) REFERENCES CANDIDATE); 
问题回答

表格只能有一个主要的钥匙,即有综合的主要钥匙。 如果你拥有一个综合的主要钥匙,你必须参考你儿童表的全部关键内容。 这就意味着儿童表必须有一个“条形”栏和“条形”栏。

CREATE TABLE job (
  position_id VARCHAR2(5) PRIMARY KEY,
  candidate_id VARCHAR2(5),
  name         VARCHAR2(30),
  date2        DATE,
  FOREIGN KEY( candidate_id, name ) REFERENCES candidate( candidate_id, name )
);

当然,你可能不想在两个表格中储存<条码>。 您可能希望<代码>candidate_id成为<代码>candidate的实用关键词,而且您可能希望对<代码><>> > /代码”形成单独的独特限制。

CREATE TABLE CANDIDATE(
  CANDIDATE_ID VARCHAR(5) primary key,
  NAME VARCHAR(30) unique,
  TELEPHONE NUMBER);

CREATE TABLE JOB(
  POSITION_ID VARCHAR(5) PRIMARY KEY,
  CANDIDATE_ID VARCHAR(5),
  DATE2 DATE,
  FOREIGN KEY(CANDIDATE_ID) REFERENCES CANDIDATE(candidate_id)); 

假设CANDIDATE_ID和NAME是独一无二的关键,那么你在你的参考资料表中必须提及不结盟运动国家一栏。

我怀疑,加拿大发展协会(CANDIDATE)足以在你的主要职位上独一无二地确定候选人。 如果是这样的话,它就应该是你的主要关键,你的关系将发挥作用。 如果你想要将非农产品市场准入指数单独列出,则将其排除在外。

最后一点是这样;

CCTRAINT FK_CANDIDATE_ID FOREIGN KEY (CANDIDATE_ID)REFERENCES CANDIDATE (CANDIDATE_ID);

CREATE TABLE dept
( did char(3) not null,
  dname varchar2(20) not null,
  CONSTRAINT dept_pk PRIMARY KEY (did)
);

<>载体>

 create table emp
 (
  eid char(3) unique,
  ename varchar2(10) not null,
  sal number check (sal between 20000 AND 50000),
  city varchar2(10) default  texus ,
  did char(3) not null,
  constraint fk_did_dept
  FOREIGN KEY (did) references
  dept(did)
 );




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

How to make a one to one left outer join?

I was wondering, is there a way to make a kind of one to one left outer join: I need a join that matches say table A with table B, for each record on table A it must search for its pair on table B, ...

Insert if not exists Oracle

I need to be able to run an Oracle query which goes to insert a number of rows, but it also checks to see if a primary key exists and if it does, then it skips that insert. Something like: INSERT ALL ...

How can I store NULLs in NOT NULL field?

I just came across NULL values in NOT-NULL fields in our test database. How could they get there? I know that NOT-NULL constraints can be altered with NOVALIDATE clause, but that would change table s ...

Type reference scope

I m studying databases and am currently working on a object-relational DB project and I ve encountered a small problem with the number of possible constraints in an object table. I m using "Database ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

热门标签