drop database if exists sklep; create database sklep; use mysql; use sklep; create table kasjer (id varchar(16) not null unique, nr mediumint not null auto_increment primary key, czy_pracuje bool not null default 1, nr_karty int unique, imie char(20), nazwisko char(35), adres char(100), pesel_nip varchar(13), tel char(50), fax char(50), email char(50), www char(70), info text, punkty float not null default 0, nr_kasy smallint not null default 0, index nr_karty_ind (nr_karty), index id_ind (id), index nazwisko_ind (nazwisko), index nr_kasy_ind (nr_kasy)) type=innodb; create table klient (nr int not null auto_increment primary key, nr_karty int unique, imie varchar(20), nazwisko varchar(35), skrot_firmy varchar(35), nazwa_firmy varchar(100), adres varchar(100), pesel_nip char(13), tel varchar(50), fax varchar(50), email varchar(50), www varchar(70), info text, punkty float not null default 0, index nr_karty_ind (nr_karty), index nazwisko_ind (nazwisko), index skrot_firmy_ind (skrot_firmy), index pesel_nip_ind (pesel_nip)) type=innodb; create table dostawca (nr int not null auto_increment primary key, skrot_firmy varchar(35), nazwa_firmy varchar(100), adres varchar(100), nip char(13), tel varchar(50), fax varchar(50), email varchar(50), www varchar(70), info text, info_bank varchar(150), nr_konta varchar(50), index skrot_firmy_ind(skrot_firmy), index nip_ind (nip)) type=innodb; create table jednostka (nr smallint not null auto_increment primary key, nazwa varchar(4) not null) type=innodb; create table grupa_towarowa (nr smallint not null auto_increment primary key, nazwa varchar(19) not null) type=innodb; create table stawka_podatkowa (nr smallint not null auto_increment primary key, stawka float not null) type=innodb; create table towar (nr int not null auto_increment primary key, nazwa varchar(100), krotka_nazwa varchar(19), kod_kreskowy varchar(20) unique, producent varchar(50), sww varchar(14), pkwiu varchar(14), punkty float not null, stan_magazynowy float, vat_ref smallint, miara_ref smallint, grupa_towarowa_ref smallint, info text, dostawca_ref int, index nazwa_ind(nazwa), index kod_kreskowy_ind (kod_kreskowy), index producent_ind (producent), index vat_ind (vat_ref), index miara_ind (miara_ref), index grupa_ind (grupa_towarowa_ref), index dostawca_ind (dostawca_ref), foreign key (dostawca_ref) references dostawca(nr), foreign key (vat_ref) references stawka_podatkowa(nr), foreign key (miara_ref) references jednostka(nr), foreign key (grupa_towarowa_ref) references grupa_towarowa(nr)) type=innodb; create table faktura (nr int not null auto_increment primary key, typ char(1) not null, kupno_sprzedaz char(1) not null, czas timestamp, forma_zaplaty char(1) not null, termin_zaplaty timestamp, czy_zaplacona bool not null, klient_ref int, kasjer_ref mediumint, dostawca_ref int, index czas_ind (czas), index klient_ind (klient_ref), index kasjer_ind (kasjer_ref), index dostawca_ind (dostawca_ref), foreign key (klient_ref) references klient(nr), foreign key (kasjer_ref) references kasjer(nr), foreign key (dostawca_ref) references dostawca(nr)) type=innodb; create table faktura_poz (nr int not null auto_increment primary key, ilosc float not null, vat float not null, faktura_ref int not null, towar_ref int not null, index faktura_ind (faktura_ref), index towar_ind (towar_ref), foreign key (faktura_ref) references faktura(nr), foreign key (towar_ref) references towar(nr)) type=innodb; create table zmiana_ceny (nr int not null auto_increment primary key, cena_kupna float not null, cena_sprzedazy float not null, data_wpisu timestamp, towar_ref int not null, index data_wpisu_ind (data_wpisu), index towar_ind (towar_ref), foreign key (towar_ref) references towar(nr)) type=innodb; create table surowiec (nr int not null auto_increment primary key, produkt_ref int not null, surowiec_ref int not null, ilosc float not null, index produkt_ind (produkt_ref), index surowiec_ind (surowiec_ref), foreign key (produkt_ref) references towar(nr), foreign key (surowiec_ref) references towar(nr)) type=innodb; grant all privileges on *.* to 'szef'@'localhost' identified by 'szef'; grant grant option on *.* to 'szef'@'localhost';