DROP USER sena CASCADE;
CREATE USER sena IDENTIFIED BY A; alter user sena default tablespace adsi; grant connect to sena; connect sena/a;
--********************************************* CONNECT SYSTEM/A; grant dba to sena; --******************************************** PROMPT "creando tabla A" CREATE TABLE sena.A ( idA number (2), X1 number (2), X2 number (2), X3 number (2) );
PROMPT "creando tabla B" CREATE TABLE sena.B ( idB number (3), Y1 number (3), Y2 VARCHAR2 (3), Y3 number (3), idA number (2) ); --***************************************************** PROMPT "creando de pk"
PROMPT "creando pk para A" ALTER table sena.A ADD CONSTRAINT pkA primary KEY(idA); PROMPT "creando pk para B" ALTER table sena.B ADD CONSTRAINT pkB primary KEY(idB); --***************************************************** PROMPT "crando fk para B" ALTER TABLE sena.B ADD CONSTRAINT fkB FOREIGN KEY(idA) REFERENCES sena.A(idA); --************************************************** PROMPT"creando unique para A" alter table sena.A ADD CONSTRAINT UKX1 UNIQUE(X1); PROMPT"creando unique para A" alter table sena.A ADD CONSTRAINT UKA UNIQUE(X2,X3); PROMPT "creacion CK para B" alter table sena.B ADD CONSTRAINT CKB CHECK(Y2 IN(Y1,Y3,idA));
--*********************************************************** PROMPT "insertando informacion para A" INSERT INTO sena.A(idA,X1,X2,X3)VALUES(1,1,2,3); INSERT INTO sena.A(idA,X1,X2,X3)VALUES(2,4,5,6);
PROMPT "insertando informacion para B" INSERT INTO sena.B(idB,Y1,Y3,idA)VALUES(1,3,9,5); INSERT INTO sena.B(idB,Y1,Y3,idA)VALUES(2,6,8,4); INSERT INTO sena.B(idB,Y1,Y3,idA)VALUES(2,6,8,4);