Home » RDBMS Server » Server Administration » Constraint trouble
Constraint trouble [message #372459] Wed, 14 February 2001 04:51 Go to next message
Jonas Blomqvist
Messages: 3
Registered: February 2001
Junior Member
Hello,

I'm quite new to SQL and haven't figured out how to set up a CONSTRAINT.

Here's the scenario with SQL:

CREATE TABLE FB_S_1 (
S_1 NUMBER NOT NULL,
S_2 NUMBER NOT NULL,
S_3 NUMBER,
S_4 NUMBER,
S_5 NUMBER,
S_6 NUMBER,
S_7 NUMBER,
S_8 NUMBER,
S_9 NUMBER,
PRIMARY KEY ( S_1, S_2 )
);

COMMENT ON COLUMN FB_S_1.S_2 IS 'The comment';

/* Create table */
CREATE TABLE FB_U_1 (
U_1 NUMBER NOT NULL,
U_2 VARCHAR2(32) NOT NULL,
U_3 VARCHAR2(32),
U_4 VARCHAR2(32),
U_5 VARCHAR2(64),
/* Set primary keys */
PRIMARY KEY ( U_1, U_2 )
);

/* Unique key */
CREATE UNIQUE INDEX U_2_PK ON
FB_U_1(U_2);

/* Sequence to update ID for new field with */
CREATE SEQUENCE U_1_SEQ START WITH 1;

/* Create trigger to launche when inserting new record */
CREATE OR REPLACE TRIGGER U_1_TRG
BEFORE INSERT ON FB_U_1
FOR EACH ROW
BEGIN
SELECT U_1_SEQ.NEXTVAL INTO :NEW.U_1
FROM DUAL;
END;

/* Here is the problem ! */
ALTER TABLE FB_S_1 ADD CONSTRAINT FB_S_1_FK1
FOREIGN KEY (S_1)
REFERENCES FB_U_1 (U_1);

It's this last clause I cant get to work. I'll get the error: "ORA-02270: no matching unique or primary key for this column-list"

Please, any help appriciated !

Regards, Jonas
Re: Constraint trouble [message #372588 is a reply to message #372459] Mon, 26 February 2001 10:16 Go to previous message
Bobby
Messages: 32
Registered: August 2000
Member
Hi

Hey You created a composite primary key and you are trying to create a foreign key with just one coluumn name, so u need to add the second column name in ur last script also.
Previous Topic: How much characters in varchar2 length 4000?
Next Topic: HELP HELP PLS
Goto Forum:
  


Current Time: Sun Jun 30 20:57:01 CDT 2024