BIBAH BLOG "SQL I"
SQL
Kasus :
Sebuah perguruan tinggi akan menyelanggarakan Kuliah Kerja Nyata (KKN). KKN kali ini berada di 5 kecamatan, Setiap kecamatan memiliki 4 sampai 6 desa. Setiap desa dapat berisi 15-17 mahasiswa dari berbagai program studi. Namun setelah memilih desa mahasiswa TIDAK DAPAT merubah desa yang telah di pilih. sistem juga harus mencatan nilai dari setiap mahasiswa di akhir pelaksanaan KKN. (ERD yang sudah di normalisasi)
-- phpMyAdmin SQL Dump
-- version 5.2.0
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Nov 06, 2022 at 06:48 AM
-- Server version: 10.4.25-MariaDB
-- PHP Version: 8.1.10
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
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: `kkn`
--
-- --------------------------------------------------------
--
-- Table structure for table `alamat_kkn`
--
CREATE TABLE `alamat_kkn` (
`id_alamat` int(11) NOT NULL,
`nama_desa` varchar(50) NOT NULL,
`nama_kecamatan` varchar(50) NOT NULL,
`nama_jalan` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `desa`
--
CREATE TABLE `desa` (
`id_desa` int(11) NOT NULL,
`nama_desa` varchar(50) NOT NULL,
`nama_kecamatan` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `desa2`
--
CREATE TABLE `desa2` (
`id_desa` int(11) NOT NULL,
`nama_desa` varchar(50) NOT NULL,
`nim` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `kecamatan`
--
CREATE TABLE `kecamatan` (
`id_kecamatan` int(11) NOT NULL,
`nama_kecamatan` varchar(50) NOT NULL,
`jumlah_desa` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `mahasiswa`
--
CREATE TABLE `mahasiswa` (
`id_mahasiswa` int(11) NOT NULL,
`nim` int(11) NOT NULL,
`nama` varchar(50) NOT NULL,
`id_prodi` int(11) NOT NULL,
`nama_prodi` varchar(50) NOT NULL,
`kelompok` varchar(50) NOT NULL,
`nilai` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `mahasiswa2`
--
CREATE TABLE `mahasiswa2` (
`id_mahasiswa` int(11) NOT NULL,
`nim` int(11) NOT NULL,
`nilai` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `prodi`
--
CREATE TABLE `prodi` (
`id_prodi` int(11) NOT NULL,
`nama_fakultas` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `prodi2`
--
CREATE TABLE `prodi2` (
`id_prodi` int(11) NOT NULL,
`nama_prodi` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `alamat_kkn`
--
ALTER TABLE `alamat_kkn`
ADD PRIMARY KEY (`id_alamat`);
--
-- Indexes for table `desa`
--
ALTER TABLE `desa`
ADD PRIMARY KEY (`id_desa`);
--
-- Indexes for table `desa2`
--
ALTER TABLE `desa2`
ADD PRIMARY KEY (`id_desa`);
--
-- Indexes for table `kecamatan`
--
ALTER TABLE `kecamatan`
ADD PRIMARY KEY (`id_kecamatan`);
--
-- Indexes for table `mahasiswa`
--
ALTER TABLE `mahasiswa`
ADD PRIMARY KEY (`id_mahasiswa`),
ADD UNIQUE KEY `nama` (`nama`),
ADD UNIQUE KEY `nama_prodi` (`nama_prodi`),
ADD UNIQUE KEY `nim` (`nim`),
ADD KEY `id_prodi` (`id_prodi`);
--
-- Indexes for table `mahasiswa2`
--
ALTER TABLE `mahasiswa2`
ADD PRIMARY KEY (`id_mahasiswa`);
--
-- Indexes for table `prodi`
--
ALTER TABLE `prodi`
ADD PRIMARY KEY (`id_prodi`);
--
-- Indexes for table `prodi2`
--
ALTER TABLE `prodi2`
ADD PRIMARY KEY (`id_prodi`),
ADD KEY `nama_prodi` (`nama_prodi`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `alamat_kkn`
--
ALTER TABLE `alamat_kkn`
MODIFY `id_alamat` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `desa`
--
ALTER TABLE `desa`
MODIFY `id_desa` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `desa2`
--
ALTER TABLE `desa2`
MODIFY `id_desa` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `kecamatan`
--
ALTER TABLE `kecamatan`
MODIFY `id_kecamatan` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `mahasiswa`
--
ALTER TABLE `mahasiswa`
MODIFY `id_mahasiswa` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `mahasiswa2`
--
ALTER TABLE `mahasiswa2`
MODIFY `id_mahasiswa` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `prodi`
--
ALTER TABLE `prodi`
MODIFY `id_prodi` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `prodi2`
--
ALTER TABLE `prodi2`
MODIFY `id_prodi` int(11) NOT NULL AUTO_INCREMENT;
--
-- Constraints for dumped tables
--
--
-- Constraints for table `alamat_kkn`
--
ALTER TABLE `alamat_kkn`
ADD CONSTRAINT `alamat_kkn_ibfk_1` FOREIGN KEY (`id_alamat`) REFERENCES `mahasiswa` (`id_mahasiswa`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints for table `desa`
--
ALTER TABLE `desa`
ADD CONSTRAINT `desa_ibfk_1` FOREIGN KEY (`id_desa`) REFERENCES `mahasiswa` (`id_mahasiswa`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints for table `kecamatan`
--
ALTER TABLE `kecamatan`
ADD CONSTRAINT `kecamatan_ibfk_1` FOREIGN KEY (`id_kecamatan`) REFERENCES `desa` (`id_desa`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints for table `mahasiswa`
--
ALTER TABLE `mahasiswa`
ADD CONSTRAINT `mahasiswa_ibfk_2` FOREIGN KEY (`id_mahasiswa`) REFERENCES `mahasiswa2` (`id_mahasiswa`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `mahasiswa_ibfk_3` FOREIGN KEY (`nim`) REFERENCES `desa2` (`id_desa`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `mahasiswa_ibfk_4` FOREIGN KEY (`id_prodi`) REFERENCES `prodi` (`id_prodi`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints for table `prodi2`
--
ALTER TABLE `prodi2`
ADD CONSTRAINT `prodi2_ibfk_1` FOREIGN KEY (`nama_prodi`) REFERENCES `mahasiswa` (`nama_prodi`) ON DELETE CASCADE ON UPDATE CASCADE;
COMMIT;
/*!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 */;
Komentar
Posting Komentar