-- https://www.phpmyadmin.net/
--
-- Počítač: localhost
-- Vytvořeno: Pát 02. kvě 2025, 09:20
-- Verze serveru: 10.11.11-MariaDB-0+deb12u1
-- Verze PHP: 8.2.26

START TRANSACTION;

CREATE TABLE `MIxQIbind_bck` (
  `M_ID` int(10) NOT NULL,
  `Q_ID` int(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

DELIMITER $$
CREATE TRIGGER `test` BEFORE UPDATE ON `MIxQIbind_bck` FOR EACH ROW BEGIN END
$$
DELIMITER ;

ALTER TABLE `MIxQIbind_bck`
  ADD PRIMARY KEY (`M_ID`),
  ADD UNIQUE KEY `Q_ID` (`Q_ID`) USING BTREE;
COMMIT;

START TRANSACTION;

CREATE TABLE `MIxQItemp` (
  `M_ID` int(10) NOT NULL,
  `Q_ID` int(10) NOT NULL,
  `KOD_OP` decimal(6,0) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

INSERT INTO `MIxQItemp` (`M_ID`, `Q_ID`, `KOD_OP`) VALUES
(134, 167413215, 8457),
(312, 167269648, 27415);

ALTER TABLE `MIxQItemp`
  ADD KEY `M_ID` (`M_ID`) USING BTREE,
  ADD KEY `Q_ID` (`Q_ID`) USING BTREE;
COMMIT;

START TRANSACTION;
delete FROM `MIxQIbind_bck` where M_ID in (select M_ID from `MIxQItemp`);
INSERT into MIxQIbind_bck (M_ID,Q_ID) select M_ID,Q_ID from `MIxQItemp`; -- limit 1 is OK!!!
Rollback;