create a Rigger to allow you to lend a book only to students who have 'MT' status

Asked

Viewed 36 times

1

the teacher asked to make a Rigger in postgresql, only that can not do no if someone can help me, create Function emprestimo_book() Returns Trigger language plpgsql as $$ Begin if( Insert Loan Bookbook

Return new; end; $$ data set, create schema provaII set schema 'probable';

CREATE TABLE STUDENT ( CDALUNO INTEGER NOT NULL, NAME VARCHAR(40) , NMATRICULA VARCHAR(15), STATUS CHAR(2) );

Insert into Aluno values (1, 'Antonio Bandeiras', '00010-2018','MT'), (2, 'Bill Gates', '00002-2018', 'RP') , (3, 'Steve Snick', '00003-2018', 'AP') , (4, 'Linus Torvals', '00404-2018','AM')

CREATE TABLE COURSE ( CDCURSO INTEGER NOT NULL, NAME VARCHAR(20), NUMERIC VALUE(7,2));

Insert into curso values(10, 'ADS', 800.00), (11, 'Quimica',900.00), (12, 'Agronomy', 1000.00), (13, 'Agroindustria', 1100.00)

CREATE TABLE PROFESSOR ( CDPROFESSOR INTEGER NOT NULL, NAME VARCHAR(40));

Insert into professor values (20, 'MAXUEEL SANTOS'), (21, 'ANTOIN LIMA') (22, 'GEORGINA COTRIM') , (23, 'PAULITA FERREIRA')

CREATE TABLE DISCIPLINE ( CDDISCIPLINA INTEGER NOT NULL, NOMEDISCIPLINA varchar(40), CDPROFESSOR INTEGER, NUMERIC VALUE(7,2));

Insert into DISCIPLINA values(30, 'ALGORITHM',20,500.00), (31, 'DATABASE',21, 600.00), (32, 'TABD',21, 600.00)

CREATE TABLE SEMESTER ( CDSEMESTRE INTEGER NOT NULL, VARCHAR YEAR(15));

INSERT INTO SEMESTER VALUES(50,'2017.1'), (51,'2017.2') , (52,'2018.1') , (53,'2018.2')

CREATE TABLE TURMA ( CDTURMA INTEGER NOT NULL, CLASS VARCHAR(20)) ;

INSERT INTO CLASS VALUES(60, 'PROGRAMMERS'), (61,'ANALYSTS')

CREATE TABLE MATRICULA ( CDMATRICULA INTEGER NOT NULL, CDCURSO INTEGER, STUDENT OFFICER INTEGER, CDSEMESTRE INTEGER, NUMERIC VALUE(7,2), CDTURMA INTEGER);

INSERT INTO matricula values( 100, 10, 1, 50,300.00,60), ( 101, 10, 2, 50,400.00,60), ( 102, 12, 3, 50,500.00,61), ( 103, 13, 4, 50,500.00,61),

                        ( 104, 10, 1, 51, 300.00, 60),
                        ( 105, 10, 2, 51, 400.00, 60),
                        ( 106, 12, 3, 51, 500.00, 61),                         
                        ( 107, 13, 4, 51, 500.00, 61),

                        ( 108, 10, 1, 52, 300.00, 60),
                        ( 109, 10, 2, 52, 400.00, 60),
                        ( 110, 12, 3, 53, 500.00, 61),                         
                        ( 111, 13, 4, 53, 500.00, 61)

CREATE TABLE MATDISCIPLINA ( CDMATDISCIPLINA INTEGER NOT NULL, CDMATRICULA INTEGER, CDDISCIPLINA INTEGER MEDIA NUMERIC(7,2), STATUS CHAR(2), CDPROFESSOR INTEGER, NUMERIC VALUE(7,2));

insert into matdisciplina(cdmatdisciplina,cdmatricula,cddisciplina, status,valor) 
       values( 1,100,30,'AP', 500.00),
             ( 2,100,31,'AP', 600.00),
             ( 3,100,32,'AP', 600.00),
             ( 4,100,33,'AP', 500.00),

             ( 5,101,30,'RP', 500.00),
             ( 6,101,33,'RP', 350.00),
             ( 7,101,34,'RE', 400.00),

             ( 8,102,30,'MT', 350.00),
             ( 9,102,31,'MT', 300.00),

             (10,103,30,'MT', 660.00),
             (11,103,32,'MT', 760.00)

CREATE TABLE NOTE ( CDNOTA INTEGER NOT NULL, CDMATDISCIPLINA INTEGER, NUMERIC NOTE(7,2), REFERENCE VARCHAR(20), STATUS CHAR(2));

Insert into note values (1, 1, 8.00, 'Av I', 'AP') , (2, 1, 4.00, 'AV II', 'RP') , (3, 1, 3.00, 'AV III', 'RP'), (4, 2, 6.00, 'Av I', 'RP') , (5, 2, 4.00, 'AV II', 'RP') , (7, 3, 4.00, 'Av I', 'RP') , (8, 3, 4.00, 'AV II', 'RP') , (9, 4, 8.00, 'Av I', 'AP') , (10, 4, 4.00, 'AV II', 'RP')

create table book ( Cdlivro INTEGER NOT NULL, nomelivro varchar(40));

Insert into book values (1, 'TABD'), (2, 'SO') and (3, 'BD') , (4, 'BOLSONARO'')

create table emprestimolivro ( Cdemplivro INTEGER NOT NULL, Cdmattricula INTEGER, cdinteger book, Statusemp CHAR(2));

Insert into Businessbook values (1, 100,1,'EM'), (2, 100,2,'DE'), (3, 100,3,'EM') and (4, 101,4,'DE')

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.