1
I have a question, when I create a CONSTRAINT
UNIQUE
, she measures all the columns together?
For example, I want a country not to have names or acronyms equal, in which case I must create CONSTRAINT
different?
For I did in only one, she lets me enter countries since name and acronym are not equal, however, I want to block even in case only one of these columns are equal.
I did so:
CREATE TABLE PAIS
(
IdPais INTEGER NOT NULL,
NomePais VARCHAR(60) NOT NULL,
SiglaPais VARCHAR(3) NOT NULL,
StatusPais CHAR(1) NOT NULL,
CONSTRAINT PAIS PRIMARY KEY (IdPais),
CONSTRAINT PAIS_UNIQUE UNIQUE (NomePais, SiglaPais)
);
/
CREATE SEQUENCE SEQ_ID_PAIS
MINVALUE 1
MAXVALUE 9999999999
START WITH 1
INCREMENT BY 1
NOCACHE
CYCLE;
/
CREATE OR REPLACE TRIGGER TRG_ID_PAIS BEFORE INSERT ON PAIS FOR EACH ROW BEGIN <<COLUMN_SEQUENCES>> BEGIN IF :NEW.IDPAIS IS NULL THEN SELECT SEQ_ID_PAIS.NEXTVAL INTO :NEW.IDPAIS FROM DUAL; END IF; END COLUMN_SEQUENCES; END;
/
then, when I want separate, I must make a Constraint for each column, correct ?
– AlunoOracle
yes, if the given column cannot repeat the value in any condition, the Constraint is individual
– Rovann Linhalis
Siglapais could be the PK then.
– Motta
depending on the case, yes, but you can’t know the specification of the colleague’s software, so I didn’t even get into this question.
– Rovann Linhalis