create a trigger to allow book borrowing only for students who have 'MT'

1

The teacher asked me to do a trigger in postgresql, but I can not do it if someone can help me, create a trigger to allow a book loan only for students who have 'MT' status, create function language plpgsql at $$ begin     if     insert businessbook

return new; end; $$ bunch of data, create schema provaII set schema 'proof';

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

insert into Student values (1, 'Antonio Flags', '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 course values (10, 'ADS', 800.00),                         (11, 'Chemistry', 900.00),                         (12, 'Agronomy', 1000.00),                         (13, 'Agribusiness', 1100.00)

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

insert into teacher 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 DISCIPLINE values (30, 'ALGORITHM', 20,500.00),                              (31, 'DATA BANK', 21, 600.00),                              (32, 'TABD', 21, 600.00)

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

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

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

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

CREATE TABLE ENROLLMENT (     CDMATRICULA INTEGER NOT NULL,     CDCURSO INTEGER,     CDALUNO 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, 60, 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,     NOTE NUMERIC (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 (     CD INTEGER NOT NULL,     varchar (40));

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

create table (     INTEGER NOT NULL,     CDMATtricula INTEGER,     cdlivro integer,     STATUSemp CHAR (2));

Insert into emprtimolivro values    (1, 100.1, 'MS'),    (2, 100.2, 'DE'),    (3, 100.3, 'EM'),    (4, 101.4, 'DE')

    
asked by anonymous 06.12.2018 / 22:16

0 answers