Sie sind auf Seite 1von 3

xcreate or replace procedure t_pins(uid number,fn varchar,

ln varchar,emai varchar)is
begin
insert into users values(uid,fn,ln,emai);
commit;
end;

variable x number;
variable a varchar2(30);
variable y varchar2(30);
variable z varchar2(30);

exec t_pins(100,'mani','raj','mani_2@kgisliim.ac.in');

select * from users;

create or replace procedure t_pup(uid number)is


begin
update users set email='qwewerw' where user_id=uid;
commit;
end;

exec t_pup(100);

select * from users;

create or replace procedure t_pdel(uid number)is


begin
delete users where user_id=uid;
commit;
end;

exec t_pup(100);

select * from users;

-------------primary key

create or replace trigger tri_t_pk before insert on users1


for each row
declare
cnt number;
begin
select count(*) into cnt from users1 where user_id=:new.user_id;
if(cnt>=1 or :new.user_id is null)then
raise_application_error(-20003,'primary constraint violated');
end if;
end;
--insert into users1(user_id)values(100);

-------------unique key

create or replace trigger tri_t_uni before insert on users1


for each row
declare
cnt number;
begin
select count(*) into cnt from users1 where email=:new.email;
if(cnt>=1)then
raise_application_error(-20003,'unique constraint violated');
end if;
end;

--insert into users1(email)values('asdf');

-------------not null

create or replace trigger tri_t_nn before insert on users1


for each row
begin
if(:new.first_names is null)then
raise_application_error(-20003,'not null constraint violated');
end if;
end;

-- insert into users1 values(105,null,'dfds','dfggrg');

----------------check

create or replace trigger tri_t_chk before insert on users1


for each row
begin
if(:new.user_id<=10)then
raise_application_error(-20003,'check constraint violated');
end if;
end;

--insert into users1(user_id)values(5);

-----------foreign key

create table prik( n number)

create table fork( n number)

create or replace trigger tri_fk1 before insert on fork


for each row
declare
no number;
begin -- fork,prik
select count(*) into no from prik where n=:new.n;
if(no<1)then
raise_application_error(-20003,'foreign key constraint');
end if;
end;

-------------opposite foreign key

create or replace trigger tri_fk1 before insert on fork


for each row
declare
no number;
begin -- fork,prik
select count(*) into no from prik where n=:new.n;
if(no>0)then
raise_application_error(-20003,'foreign key constraint');
end if;
end;