-- phpMyAdmin SQL Dump
-- version 4.1.14
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Aug 22, 2016 at 07:24 PM
-- Server version: 5.6.17
-- PHP Version: 5.5.12

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 utf8 */;

--
-- Database: `e_prodavnica2016`
--
CREATE DATABASE IF NOT EXISTS `e_prodavnica2016` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `e_prodavnica2016`;

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

--
-- Table structure for table `artikal`
--

DROP TABLE IF EXISTS `artikal`;
CREATE TABLE IF NOT EXISTS `artikal` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `naziv` varchar(150) NOT NULL,
  `cena` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `naziv` (`naziv`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

--
-- Dumping data for table `artikal`
--

INSERT INTO `artikal` (`id`, `naziv`, `cena`) VALUES
(1, 'Polo majica', 1500),
(2, 'Duskerica', 2000),
(3, 'Hemijska olovka', 25),
(4, 'Milka cokolada - bela', 100),
(5, 'Milka cokolada sa celim lesnicima', 110);

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

--
-- Table structure for table `artikal_extra`
--

DROP TABLE IF EXISTS `artikal_extra`;
CREATE TABLE IF NOT EXISTS `artikal_extra` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `boja` varchar(32) DEFAULT NULL,
  `kolicina` int(10) unsigned NOT NULL,
  `artikal_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `artikal_id` (`artikal_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;

--
-- Dumping data for table `artikal_extra`
--

INSERT INTO `artikal_extra` (`id`, `boja`, `kolicina`, `artikal_id`) VALUES
(1, 'bela', 10, 1),
(2, 'crna', 5, 1),
(3, 'crvena', 7, 2),
(4, 'teget', 1, 2),
(5, 'plava', 50, 3),
(6, 'crvena', 50, 3),
(7, 'crna', 30, 3),
(8, NULL, 6, 4),
(9, NULL, 0, 5);

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

--
-- Table structure for table `korisnik`
--

DROP TABLE IF EXISTS `korisnik`;
CREATE TABLE IF NOT EXISTS `korisnik` (
  `korisnicko_ime` varchar(100) NOT NULL,
  `lozinka` varchar(100) NOT NULL,
  `ime` varchar(50) NOT NULL,
  `prezime` varchar(100) NOT NULL,
  `tip` tinyint(3) unsigned NOT NULL,
  PRIMARY KEY (`korisnicko_ime`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `korisnik`
--

INSERT INTO `korisnik` (`korisnicko_ime`, `lozinka`, `ime`, `prezime`, `tip`) VALUES
('bosko', 'sifra123', 'Bosko', 'Nikolic', 2),
('drasko', 'sifra123', 'Drazen', 'Draskovic', 1),
('korisnik', 'sifra123', 'Petar', 'Markovic', 1),
('sanja', 'sifra123', 'Sanja', 'Delcev', 1);

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

--
-- Table structure for table `kupovina`
--

DROP TABLE IF EXISTS `kupovina`;
CREATE TABLE IF NOT EXISTS `kupovina` (
  `korisnik_id` varchar(100) NOT NULL,
  `artikal_extra_id` int(10) unsigned NOT NULL,
  `broj_kupljenih` int(10) unsigned NOT NULL,
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`),
  KEY `korisnik_id` (`korisnik_id`,`artikal_extra_id`),
  KEY `artikal_extra_id` (`artikal_extra_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

--
-- Dumping data for table `kupovina`
--

INSERT INTO `kupovina` (`korisnik_id`, `artikal_extra_id`, `broj_kupljenih`, `id`) VALUES
('sanja', 9, 3, 1),
('drasko', 9, 5, 2),
('sanja', 1, 1, 3),
('sanja', 2, 1, 4),
('korisnik', 4, 1, 5);

--
-- Constraints for dumped tables
--

--
-- Constraints for table `artikal_extra`
--
ALTER TABLE `artikal_extra`
  ADD CONSTRAINT `FK_artikal` FOREIGN KEY (`artikal_id`) REFERENCES `artikal` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Constraints for table `kupovina`
--
ALTER TABLE `kupovina`
  ADD CONSTRAINT `FK_artikal_extra` FOREIGN KEY (`artikal_extra_id`) REFERENCES `artikal_extra` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_korisnik` FOREIGN KEY (`korisnik_id`) REFERENCES `korisnik` (`korisnicko_ime`) ON DELETE CASCADE ON UPDATE CASCADE;

/*!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 */;
