Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_dzienna_15_09
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
java_dzienna_15_09
Commits
bc4acf0a
Commit
bc4acf0a
authored
Sep 28, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kody SQL tworzące bazę sklep
parent
a88a22d7
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
0 deletions
+55
-0
create.sql
PC26-SklepWeb/sql/create.sql
+45
-0
drop.sql
PC26-SklepWeb/sql/drop.sql
+4
-0
insert.sql
PC26-SklepWeb/sql/insert.sql
+6
-0
No files found.
PC26-SklepWeb/sql/create.sql
0 → 100644
View file @
bc4acf0a
CREATE
TABLE
products
(
product_id
SERIAL
PRIMARY
KEY
,
product_name
VARCHAR
(
100
)
NOT
NULL
,
-- tekst o dł maksymalnie 100 znaków
price
NUMERIC
(
10
,
2
)
NOT
NULL
,
-- max 10 cyfr, z czego 2 to cyfry po przecinku
vat
NUMERIC
(
2
,
2
),
-- wartości do 0.99
description
TEXT
-- w PostgreSQL TEXT, a w Oracle CLOB to są "duże fragmenty tekstu"
);
-- W celach dydaktycznych: kluczem nie musi być liczba, może być tekst
CREATE
TABLE
customers
(
customer_email
VARCHAR
(
100
)
PRIMARY
KEY
,
customer_name
VARCHAR
(
100
)
NOT
NULL
,
phone_number
VARCHAR
(
20
),
address
VARCHAR
(
200
),
postal_code
CHAR
(
6
),
city
VARCHAR
(
100
)
);
-- REFERENCES oznacza "klucz obcy", za pomocą tej wartości wskazujemy klienta, który złożył zamówienie
-- technicznie: do pola orders.customer_email można wpisać tylko taką wartość, która wystepuje gdzieś w customers.customer_email
CREATE
TABLE
orders
(
order_id
SERIAL
PRIMARY
KEY
,
customer_email
VARCHAR
(
100
)
NOT
NULL
REFERENCES
customers
(
customer_email
),
status
VARCHAR
(
10
)
NOT
NULL
,
order_date
TIMESTAMP
NOT
NULL
,
delivery_date
DATE
);
-- Tabela łączy zamówienia z produktami.
-- Jeśli w tej tabeli istnieje wpis z order_id=X i product_id=Y,
-- to znaczy, że w zamówieniu X wystepuje produkt Y
-- Dodatkowo zaposujemy informację o liczbie sztuk i cenie, po której towar był kupowany.
-- W tej tabeli mamy też dwukolumnowy klucz główny - unikalna jest para order_id×product_id
CREATE
TABLE
order_products
(
order_id
INTEGER
NOT
NULL
REFERENCES
orders
(
order_id
),
product_id
INTEGER
NOT
NULL
REFERENCES
products
(
product_id
),
quantity
SMALLINT
NOT
NULL
,
actual_price
NUMERIC
(
10
,
2
)
NOT
NULL
,
PRIMARY
KEY
(
order_id
,
product_id
)
);
PC26-SklepWeb/sql/drop.sql
0 → 100644
View file @
bc4acf0a
DROP
TABLE
order_products
;
DROP
TABLE
orders
;
DROP
TABLE
customers
;
DROP
TABLE
products
;
PC26-SklepWeb/sql/insert.sql
0 → 100644
View file @
bc4acf0a
INSERT
INTO
products
(
product_name
,
price
,
vat
,
description
)
VALUES
(
'pralka'
,
2300
,
0
.
23
,
'Pralka oszczędna i szybka.'
);
INSERT
INTO
products
(
product_name
,
price
,
vat
)
VALUES
(
'odkurzacz'
,
333
.
33
,
0
.
23
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment