-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecondTask.sql
More file actions
54 lines (46 loc) · 1.26 KB
/
Copy pathSecondTask.sql
File metadata and controls
54 lines (46 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
create database SecondTask;
use SecondTask;
create schema Orders;
create table Orders.City
(
CityId INT IDENTITY PRIMARY KEY,
Name VARCHAR(100) NOT NULL
);
CREATE TABLE Orders.ShopDetails
(
ShopId INT IDENTITY PRIMARY KEY,
CityId INT NOT NULL,
Location VARCHAR(200) NOT NULL,
FOREIGN KEY (CityId) REFERENCES Orders.City(CityId)
);
CREATE TABLE Orders.Customers
(
CustomerId INT IDENTITY PRIMARY KEY,
FullName VARCHAR(200) NOT NULL,
Gender nchar(1) NOT NULL,
CONSTRAINT chk_gender CHECK (Gender IN ('M', 'F'))
);
CREATE TABLE Orders.Products
(
ProductId INT IDENTITY PRIMARY KEY,
ProductName VARCHAR(100) NOT NULL
);
CREATE TABLE Orders.OrderDetails
(
OrderId INT IDENTITY PRIMARY KEY,
ProductId INT NOT NULL,
ShopId INT NOT NULL,
Quantity INT NOT NULL,
Price MONEY NOT NULL,
FOREIGN KEY (ProductId) REFERENCES Orders.Products(ProductId),
FOREIGN KEY (ShopId) REFERENCES Orders.ShopDetails(ShopId),
);
CREATE TABLE Orders.CustomerPurchase
(
PurchaseId INT IDENTITY PRIMARY KEY,
CustomerId INT NOT NULL,
OrderId INT NOT NULL,
TotalSum MONEY NOT NULL,
FOREIGN KEY (CustomerId) REFERENCES Orders.Customers(CustomerId),
FOREIGN KEY (OrderId) REFERENCES Orders.OrderDetails(OrderId)
)