· 8 years ago · Apr 20, 2018, 08:18 AM
1drop database if exists czwartek;
2create database if not exists czwartek;
3use czwartek;
4create table pracownicy(
5id integer not null primary key,
6imie varchar(32) not null,
7nazwisko varchar(32) not null,
8pesel bigint not null,
9ktoDodalId integer not null,
10kiedyDodal datetime not null,
11ktoEdytowalId integer,
12kiedyEdytowal datetime,
13ktoUsunalId integer,
14kiedyUsunal datetime
15);
16create table pracownicylog(
17ktoLog integer not null,
18kiedyLog datetime not null,
19id integer not null primary key,
20imie varchar(32) not null,
21nazwisko varchar(32) not null,
22pesel bigint not null,
23ktoDodalId integer not null,
24kiedyDodal datetime not null,
25ktoEdytowalId integer,
26kiedyEdytowal datetime,
27ktoUsunalId integer,
28kiedyUsunal datetime
29);
30insert into pracownicy
31(id, imie, nazwisko, pesel, ktoDodalId, kiedyDodal)
32values (1, 'Jan', 'Kowalski', 0, 1, current_timestamp);
33
34select p.* from pracownicy as p order by p.id asc;
35
36insert into pracownicy log select 2, current_timestamp, p.* from pracownicy as p where p.id = 1;
37
38update pracownicy set
39imie = 'Janek',
40nazwisko = 'Kowalski',
41pesel = 0,
42ktoDodalId = 1,
43kiedyDodal = kiedyDodal,
44ktoEdytowalId = 2,
45kiedyedytowalId = current_timestamp
46where id = 1;