-- --------------------------------------------------------
-- Server OS:                    Win64
-- HeidiSQL Version:             12.6.0.6765
-- --------------------------------------------------------


-- Dumping structure for table skirnes.rr_radibas_info
CREATE TABLE IF NOT EXISTS `rr_radibas_info` (
  `radiba_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `suga_id` int(10) unsigned NOT NULL,
  `skirne_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`radiba_id`) USING BTREE,
  KEY `FK_radibas_info_suga` (`skirne_id`) USING BTREE,
  KEY `FK_radibas_info_dzivnieks` (`suga_id`) USING BTREE,
  CONSTRAINT `FK_radibas_info_dzivnieks` FOREIGN KEY (`suga_id`) REFERENCES `rr_suga` (`suga_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `FK_radibas_info_suga` FOREIGN KEY (`skirne_id`) REFERENCES `rr_skirne` (`skirne_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- Data exporting was unselected.

-- Dumping structure for table skirnes.rr_saraksts
CREATE TABLE IF NOT EXISTS `rr_saraksts` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `radiba_id` int(10) unsigned NOT NULL,
  `valsts_id` int(10) unsigned NOT NULL,
  `gads` int(100) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `FK_saraksts_radibas_info` (`radiba_id`),
  KEY `FK_saraksts_valsts` (`valsts_id`),
  CONSTRAINT `FK_saraksts_radibas_info` FOREIGN KEY (`radiba_id`) REFERENCES `rr_radibas_info` (`radiba_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `FK_saraksts_valsts` FOREIGN KEY (`valsts_id`) REFERENCES `rr_valsts` (`valsts_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- Data exporting was unselected.

-- Dumping structure for view skirnes.rr_saraksts_view
-- Creating temporary table to overcome VIEW dependency errors
CREATE TABLE `rr_saraksts_view` (
	`id` INT(10) UNSIGNED NOT NULL,
	`radiba_id` INT(10) UNSIGNED NOT NULL,
	`skirne_nos` VARCHAR(100) NULL COLLATE 'utf8_unicode_ci',
	`suga_nos` VARCHAR(50) NULL COLLATE 'utf8_unicode_ci',
	`valsts_nos` VARCHAR(60) NULL COLLATE 'utf8_unicode_ci',
	`gads` INT(100) NULL,
	`bildite` LONGBLOB NULL
) ENGINE=MyISAM;

-- Dumping structure for table skirnes.rr_skirne
CREATE TABLE IF NOT EXISTS `rr_skirne` (
  `skirne_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `skirne_nos` varchar(100) NOT NULL,
  `bildite` longblob DEFAULT NULL,
  PRIMARY KEY (`skirne_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- Data exporting was unselected.

-- Dumping structure for table skirnes.rr_suga
CREATE TABLE IF NOT EXISTS `rr_suga` (
  `suga_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `suga_nos` varchar(50) NOT NULL DEFAULT '',
  PRIMARY KEY (`suga_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- Data exporting was unselected.

-- Dumping structure for table skirnes.rr_valsts
CREATE TABLE IF NOT EXISTS `rr_valsts` (
  `valsts_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `valsts_nos` varchar(60) DEFAULT NULL,
  PRIMARY KEY (`valsts_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=197 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- Data exporting was unselected.

-- Removing temporary table and create final VIEW structure
CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW `rr_saraksts_view` AS SELECT n.id,n.radiba_id, j.skirne_nos, b.suga_nos,u.valsts_nos,n.gads, j.bildite
FROM rr_saraksts AS n
LEFT JOIN rr_radibas_info AS p
ON p.radiba_id=n.radiba_id
LEFT JOIN rr_skirne j
ON j.skirne_id=p.skirne_id
LEFT JOIN rr_suga b
ON b.suga_id=p.suga_id
LEFT JOIN rr_valsts AS u
ON u.valsts_id=n.valsts_id ;

