Procedure Insert mysql

Asked

Viewed 4,282 times

0

Good afternoon guys I’m not managing to create this trial and I don’t understand why, if you can help me.

DELIMITER $$
CREATE PROCEDURE SP_INSERT_TB_ASS_TUR_AL(IN sp_id_disciplina INT, IN sp_id_aluno_prof INT, IN sp_id_turma INT, IN sp_id_aluno INT)
BEGIN
    INSERT INTO tb_assoc_turma_aluno (id_disciplina, id_aluno_prof, id_turma, id_aluno) VALUES (sp_id_disciplina, sp_id_aluno_prof, sp_id_turma, sp_id_aluno)
END $$
DELIMITER ;

Table creation script generated by mysql

-- phpMyAdmin SQL Dump
-- version 4.5.1
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: 03-Jun-2016 às 19:52
-- Versão do servidor: 10.1.13-MariaDB
-- PHP Version: 5.6.21

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `school_sys`
--

-- --------------------------------------------------------

--
-- Estrutura da tabela `tb_assoc_turma_aluno`
--

CREATE TABLE `tb_assoc_turma_aluno` (
  `id_disciplina` int(11) NOT NULL,
  `id_aluno_prof` int(11) NOT NULL,
  `id_turma` int(11) NOT NULL,
  `id_aluno` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Extraindo dados da tabela `tb_assoc_turma_aluno`
--

INSERT INTO `tb_assoc_turma_aluno` (`id_disciplina`, `id_aluno_prof`, `id_turma`, `id_aluno`) VALUES
(5, 17, 5, 12),
(5, 17, 5, 15),
(6, 16, 2, 1),
(6, 16, 2, 2),
(6, 16, 2, 3),
(6, 16, 2, 4);

--
-- Indexes for dumped tables
--

--
-- Indexes for table `tb_assoc_turma_aluno`
--
ALTER TABLE `tb_assoc_turma_aluno`
  ADD PRIMARY KEY (`id_disciplina`,`id_aluno_prof`,`id_turma`,`id_aluno`),
  ADD KEY `id_disciplina` (`id_disciplina`),
  ADD KEY `id_aluno_prof` (`id_aluno_prof`),
  ADD KEY `id_turma` (`id_turma`),
  ADD KEY `id_aluno` (`id_aluno`);

--
-- Constraints for dumped tables
--

--
-- Limitadores para a tabela `tb_assoc_turma_aluno`
--
ALTER TABLE `tb_assoc_turma_aluno`
  ADD CONSTRAINT `fk_assoc_turma_aluno_aluno` FOREIGN KEY (`id_aluno`) REFERENCES `tb_form_aluno` (`id_aluno`),
  ADD CONSTRAINT `fk_assoc_turma_aluno_disciplina` FOREIGN KEY (`id_disciplina`) REFERENCES `tb_form_disciplina` (`id_disciplina`),
  ADD CONSTRAINT `fk_assoc_turma_aluno_professor` FOREIGN KEY (`id_aluno_prof`) REFERENCES `tb_form_aluno` (`id_aluno`),
  ADD CONSTRAINT `fk_assoc_turma_aluno_turma` FOREIGN KEY (`id_turma`) REFERENCES `tb_form_turma` (`id_turma`);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Gives END error...

inserir a descrição da imagem aqui

  • What error? Can you edit your question and put the message please?

2 answers

2


Missing the ; at the end of the Insert.

DELIMITER $$
CREATE PROCEDURE SP_INSERT_TB_ASS_TUR_AL (IN sp_id_disciplina INT, IN sp_id_aluno_prof INT, IN sp_id_turma INT, IN sp_id_aluno INT)
BEGIN
    INSERT INTO tb_assoc_turma_aluno (id_disciplina, id_aluno_prof, id_turma, id_aluno) VALUES ( sp_id_disciplina, sp_id_aluno_prof, sp_id_turma, sp_id_aluno );
END $$
DELIMITER ;
  • I put and shows error in phpadmin

  • It worked, funny that in phpadmin he showed a red wrong but executed... thank you..

-1

I can’t say why, but another syntax that works to insert in Mariadb is using SET and runs in XAMPP with Mariadb 10. Try using it this way:

INSERT INTO 'tb_assoc_turma_aluno' SET id_disciplina = '5', id_aluno_prof 
= '17', id_turma = '5', id_aluno = '12';

Browser other questions tagged

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