· 7 years ago · Oct 09, 2018, 12:22 PM
1drop database if exists ti_14092018;
2create database if not exists ti_14092018;
3use ti_14092018;
4
5create table pracownicy(
6 ID integer not null primary key,
7 imie varchar(16) not null,
8 nazwisko varchar(32) not null
9);
10
11alter table pracownicy add column login varchar(8);
12alter table pracownicy add column haslo varchar(8);
13alter table pracownicy add column pin char(4);
14
15create table wyroby(
16 ID integer not null primary key,
17 nazwa varchar(32) not null
18);
19
20create table magazyny(
21 ID smallint not null primary key,
22 nazwa varchar(16)
23);
24
25create table lokalizacjaWyrobow(
26 ID integer not null primary key,
27 wyrobyID integer not null,
28 magazynyID smallint not null,
29 ktoDodalID integer not null
30);
31
32
33insert into wyroby values(1, 'podkladka');
34insert into wyroby (id, nazwa) values (2, 'nakretka');
35insert into wyroby (nazwa, id) values ('nakretka', 3);
36
37delete from wyroby where id = 3;
38
39insert into magazyny values(1, 'magazyn A');
40
41insert into lokalizacjaWyrobow
42(id, wyrobyID, magazynyID, ktoDodalID) values
43(1, 1 , 1 , 1);
44
45select lw.id,
46lw.wyrobyID as kodWyrobu, w.nazwa as produkt,
47lw.magazynyID as 'Kod Magazynu', m.nazwa as magazyn,
48lw.ktoDodalID , p.nazwisko, p.imie
49from lokalizacjaWyrobow as lw
50inner join magazyny as m on m.id = lw.magazynyID
51inner join wyroby as w on w.id = lw.wyrobyID
52left outer join pracownicy as p on p.id = lw.ktoDodalID
53
54;