ta aiCREATE TABLE Auditoria(
id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
data DATE NOT NULL,
tipo VARCHAR(100) NOT NULL,
tabela VARCHAR(100) NOT NULL,
antiga VARCHAR(700) NOT NULL,
nova VARCHAR(700) NOT NULL
);testei com a trigger do fornecedor, e n deu nenhum problem (ela n tem FK)[code]DROP TRIGGER IF EXISTS trigInsereFornecedor ||
CREATE TRIGGER trigInsereFornecedor AFTER INSERT ON Fornecedor
FOR EACH ROW BEGIN
DECLARE aux_endereco varchar(200);
DECLARE aux_status varchar(20);
IF (NEW.endereco IS NULL) THEN
SET aux_endereco = 'Não inserido';
ELSE
SET aux_endereco = NEW.endereco;
END IF;
IF (NEW.status = 1) THEN
SET aux_status = 'Ativo';
ELSE
SET aux_status = 'Inativo';
END IF;
INSERT INTO Auditoria (antiga, nova, tipo, tabela, data) VALUES (
'Não Possui',
concat('ID: ',NEW.id,' - Empresa: ',NEW.nome_empresa,' - CNPJ: ',NEW.cnpj,' - Fone: ',NEW.fone,' - Status: ',aux_status,' - Endereco: ',aux_endereco),
'INSERT',
'Fornecedor',
NOW()
);
END;
||
DELIMITER ;[/code]insere fornecedor:insert into Fornecedor (nome_empresa,cnpj,fone,status)values ('Nenhum','0','0',0);
insert into Fornecedor (nome_empresa,cnpj,fone,status)values ('Biolab','00.000.000/0000-00','(10)0000-0000',1);
insert into Fornecedor (nome_empresa,cnpj,fone,status)values ('Merck','00.000.000/0000-01','(10)5000-0001',1);
insert into Fornecedor (nome_empresa,cnpj,fone,status)values ('Stryker','00.000.000/0000-02','(10)4000-0002',1);
insert into Fornecedor (nome_empresa,cnpj,fone,status)values ('Alere','00.000.000/0000-03','(10)3000-0003',1);
insert into Fornecedor (nome_empresa,cnpj,fone,status)values ('White Martins','00.000.000/0000-04','(10)2000-0004',1);
insert into Fornecedor (nome_empresa,cnpj,fone,status)values ('Cristália','00.000.000/0000-05','(10)1000-0005',1);a auditoria ficou assim: select * from auditoria;
+----+------------+--------+------------+------------+--------------------------------------------------------------------------------------------------------------------------+
| id | data | tipo | tabela | antiga | nova
+----+------------+--------+------------+------------+--------------------------------------------------------------------------------------------------------------------------+
| 1 | 2011-12-01 | INSERT | Fornecedor | Não Possui | ID: 1 - Empresa: Nenhum - CNPJ: 0 - Fone: 0 - Status: Inativo - Endereco: Não inserido
| 2 | 2011-12-01 | INSERT | Fornecedor | Não Possui | ID: 2 - Empresa: Biolab - CNPJ: 00.000.000/0000-00 - Fone: (10)0000-0000 - Status: Ativo - Endereco: Não inserido
| 3 | 2011-12-01 | INSERT | Fornecedor | Não Possui | ID: 3 - Empresa: Merck - CNPJ: 00.000.000/0000-01 - Fone: (10)5000-0001 - Status: Ativo - Endereco: Não inserido
| 4 | 2011-12-01 | INSERT | Fornecedor | Não Possui | ID: 4 - Empresa: Stryker - CNPJ: 00.000.000/0000-02 - Fone: (10)4000-0002 - Status: Ativo - Endereco: Não inserido
| 5 | 2011-12-01 | INSERT | Fornecedor | Não Possui | ID: 5 - Empresa: Alere - CNPJ: 00.000.000/0000-03 - Fone: (10)3000-0003 - Status: Ativo - Endereco: Não inserido
| 6 | 2011-12-01 | INSERT | Fornecedor | Não Possui | ID: 6 - Empresa: White Martins - CNPJ: 00.000.000/0000-04 - Fone: (10)2000-0004 - Status: Ativo - Endereco: Não inserido
| 7 | 2011-12-01 | INSERT | Fornecedor | Não Possui | ID: 7 - Empresa: Cristália - CNPJ: 00.000.000/0000-05 - Fone: (10)1000-0005 - Status: Ativo - Endereco: Não inserido
+----+------------+--------+------------+------------+--------------------------------------------------------------------------------------------------------------------------+
7 rows in set (0.00 sec)