diff --git a/MySQLStoredProcedureStudent/DatabaseExports/student2018_2019-04-11.sql b/MySQLStoredProcedureStudent/DatabaseExports/student2018_2019-04-11.sql new file mode 100644 index 0000000..d0c0e01 --- /dev/null +++ b/MySQLStoredProcedureStudent/DatabaseExports/student2018_2019-04-11.sql @@ -0,0 +1,291 @@ +-- MySQL dump 10.13 Distrib 5.7.25, for Linux (x86_64) +-- +-- Host: 127.0.0.1 Database: student2018 +-- ------------------------------------------------------ +-- Server version 5.7.25-0ubuntu0.18.04.2 + +/*!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 utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `fylke` +-- + +DROP TABLE IF EXISTS `fylke`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `fylke` ( + `idFylke` int(11) NOT NULL AUTO_INCREMENT, + `FylkeNavn` varchar(45) NOT NULL, + PRIMARY KEY (`idFylke`), + UNIQUE KEY `idFylke_UNIQUE` (`idFylke`) +) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8 COMMENT=' '; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `fylke` +-- + +LOCK TABLES `fylke` WRITE; +/*!40000 ALTER TABLE `fylke` DISABLE KEYS */; +INSERT INTO `fylke` VALUES (1,'Hedmark'),(2,'Oppland'),(3,'Oslo'),(4,'Østfold'),(5,'Vestfold'),(6,'Akershus'),(7,'Buskerud'),(8,'Rogaland'),(9,'Hordaland'),(10,'Telemark'),(11,'Troms'),(12,'Finnmark'),(13,'Trøndelag'),(14,'Møre og Romsdal'),(15,'Vest-Agder'),(16,'Aust-Agder'),(17,'Nordland'),(18,'Sogn og Fjordane'); +/*!40000 ALTER TABLE `fylke` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `poststed` +-- + +DROP TABLE IF EXISTS `poststed`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `poststed` ( + `Postnummer` int(4) unsigned zerofill NOT NULL, + `Poststed` varchar(45) NOT NULL, + `Fylke` int(11) NOT NULL, + PRIMARY KEY (`Postnummer`,`Fylke`), + UNIQUE KEY `Postnummer_UNIQUE` (`Postnummer`), + KEY `fk_Poststed_Fylke1_idx` (`Fylke`), + CONSTRAINT `fk_Poststed_Fylke1` FOREIGN KEY (`Fylke`) REFERENCES `fylke` (`idFylke`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=' '; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `poststed` +-- + +LOCK TABLES `poststed` WRITE; +/*!40000 ALTER TABLE `poststed` DISABLE KEYS */; +INSERT INTO `poststed` VALUES (0191,'Oslo',3),(2315,'Hamar',1),(2320,'Furnes',1),(2382,'Brumunddal',1),(2383,'Brumunddal',1),(2815,'Gjøvik',2),(5010,'Bergen',9),(7010,'Trondheim',13); +/*!40000 ALTER TABLE `poststed` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `student` +-- + +DROP TABLE IF EXISTS `student`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `student` ( + `idStudent` int(11) NOT NULL AUTO_INCREMENT, + `Etternavn` varchar(50) NOT NULL, + `Fornavn` varchar(50) NOT NULL, + `Adresse` varchar(100) NOT NULL, + `Telefon` varchar(40) NOT NULL, + `Alder` int(3) DEFAULT NULL, + `Kjonn` varchar(1) DEFAULT NULL, + `Postnummer` int(4) unsigned zerofill NOT NULL, + PRIMARY KEY (`idStudent`,`Postnummer`), + KEY `StudentPostnummerID_idx` (`Postnummer`), + CONSTRAINT `StudentPostnummerID` FOREIGN KEY (`Postnummer`) REFERENCES `poststed` (`Postnummer`) +) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8 COMMENT=' '; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `student` +-- + +LOCK TABLES `student` WRITE; +/*!40000 ALTER TABLE `student` DISABLE KEYS */; +INSERT INTO `student` VALUES (1,'Thomassen','Alex','Skolevegen 6','47634677',21,'M',2383),(2,'Nordmann','Ola','Blankeveien 82','88228833',19,'M',0191),(3,'Schnøring','Hakke','Smockrettinnveien 99','22336622',20,'K',0191),(4,'Larsen','Stian','Bøttekottet 47','21345676',22,'M',2315),(6,'Finsrud','Øyvind','Hakkebakkeskogen 66','77554422',21,'M',2815),(8,'Stian','Blipp','Klovngata 51','99887766',44,'M',0191),(9,'Larsen','Stian','Aldershjemmet 55','45678982',25,'M',2383),(10,'Ås','Åsmund','Bruuuuuuumund 511','123123123',22,'M',2815),(11,'Thomassen','Karin','Rostadvegen 9','62342318',31,'K',2383),(12,'Anne Kari','Thomassen','Rælhaugen 22','22113322',25,'K',0191),(13,'Morken Haugen','Katrine','Lia 1','21356788',20,'K',2815),(14,'Kristiansen','Hanne','Borettslaget 44','77222772',21,'K',2383),(15,'Laubakken','Bjønn','OppiDerEnPlass 44','77228822',23,'M',2383),(16,'Snartenkt','Helge','Hoppihavet 19','56786578',22,'M',2383); +/*!40000 ALTER TABLE `student` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping routines for database 'student2018' +-- +/*!50003 DROP PROCEDURE IF EXISTS `FylkeViewAll` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `FylkeViewAll`() +BEGIN + SELECT * FROM fylke; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `PoststedAdd` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `PoststedAdd`( + _Postnummer INT, + _Poststed VARCHAR(45), + _FylkeId INT +) +BEGIN + INSERT INTO poststed(Postnummer, Poststed, Fylke) VALUES(_Postnummer, _Poststed, _FylkeId); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `PoststedViewAll` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `PoststedViewAll`() +BEGIN + SELECT * FROM poststed INNER JOIN fylke ON poststed.Fylke = fylke.idFylke; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `StudentAddOrEdit` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `StudentAddOrEdit`( + _Id INT(11), + _Fornavn VARCHAR(50), + _Etternavn VARCHAR(50), + _Adresse VARCHAR(100), + _Telefon VARCHAR(40), + _Alder INT(3), + _Kjonn VARCHAR(1), + _Postnummer INT(4) UNSIGNED ZEROFILL +) +BEGIN + if _Id = 0 then + INSERT INTO + student(Fornavn, Etternavn, Adresse, Telefon, Alder, Kjonn, Postnummer) + VALUES + (_Fornavn, _Etternavn, _Adresse, _Telefon, _Alder, _Kjonn, _Postnummer); + else + UPDATE student + SET + Fornavn = _Fornavn, + Etternavn = _Etternavn, + Adresse = _Adresse, + Telefon = _Telefon, + Alder = _Alder, + Kjonn = _Kjonn, + Postnummer = _Postnummer + WHERE + idStudent = _Id; + end if; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `StudentDeleteById` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `StudentDeleteById`( + _StudentId INT +) +BEGIN + DELETE FROM student WHERE idStudent = _StudentId; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `StudentSearchByText` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `StudentSearchByText`( + _SearchText VARCHAR(100) +) +BEGIN + SELECT * FROM student + WHERE + Etternavn LIKE CONCAT('%', _SearchText, '%') + OR + Fornavn LIKE CONCAT('%', _SearchText, '%') + OR + Adresse LIKE CONCAT('%', _SearchText, '%') + OR + Telefon LIKE CONCAT('%', _SearchText, '%'); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `StudentViewAll` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `StudentViewAll`() +BEGIN + SELECT * FROM student; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!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 */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2019-04-11 13:31:19