Documente Academic
Documente Profesional
Documente Cultură
Design Exterior
Giurgiuman Claudia-Teodora
IE, ID, an 2, Grupa 2
An Universitar 2021-2022
Scenariu:
La nivelul unei firme de design exterior, se dorește realizarea unei baze de date, pentru o mai
buna și eficientă gestiune a activității acesteia. Firma se ocupă de amenajarea exterioară atât a
spațiilor exterioare comune sau private (parcuri, grădini, terase etc.) cu mobilier, cât și a
clădirilor (locuințe, spații de birouri, sedii pentru firme etc.). Activitatea este extinsă la nivel
mondial iar vânzările pot fi efectuate atât către persoane juridice, cât și fizice.
Baza de date va cuprinde informații despre clienți (precum datele de identificare, comenzi,
adresele corespunzătoare), prețuri și costuri (acestea fiin calculate sezonier), furnizori (de ex. de
materii prime: lemn, fier etc.), locațiile proiectelor de design.
Diagrama ERD
Schema bazei de date:
Crearea Tabelelor
Tabel product
create table Product (Id int NOT NULL PRIMARY KEY, ProductName varchar(250),
CreatedAt varchar(250), Quantity int, UnitsInStock int, Discontinued boolean, DiscontinuedAt
varchar(250), CONSTRAINT MAX_UnitsInStock CHECK (UnitsInStock <= 30 and Quantity
<= 20));
Tabel season
create table Season (Id int NOT NULL PRIMARY KEY, Name varchar(250));
Tabel History
Create table History (Id int NOT NULL PRIMARY KEY, ProductId int NOT NULL, SeasonId
int NOT NULL, CreatedAt varchar(250), CompletedAt varchar(250), Price int, FOREIGN KEY
(ProductId) REFERENCES Product(Id), FOREIGN KEY (SeasonId) REFERENCES
Season(Id));
Tabel ProductType
create table ProductType (Id int NOT NULL PRIMARY KEY, ProductId int, Occurence
varchar(250), Description varchar(250), FOREIGN KEY (ProductId) REFERENCES
Product(Id));
Tabel BuyerType
create table BuyerType (Id int NOT NULL PRIMARY KEY, Type varchar(250));
Tabel Buyer
create table Buyer (Id int NOT NULL PRIMARY KEY, BuyerTypeId int NOT NULL, Name
varchar(250), SocialCapital int, AddedAt varchar(250), Discontinued boolean, DiscontinuedAt
varchar(250), FOREIGN KEY (BuyerTypeId) REFERENCES BuyerType(Id));
Tabel BuyerLocation
create table BuyerLocation (Id int NOT NULL PRIMARY KEY, BuyerId int NOT NULL, City
varchar(250), Region varchar(250), Country varchar(250), Street varchar(250), Number
varchar(250), FOREIGN KEY (BuyerId) REFERENCES Buyer(Id));
Tabel Sale
create table Sale (Id int NOT NULL PRIMARY KEY, ProductId int NOT NULL, BuyerId int
NOT NULL, CreatedAt varchar(250), Price decimal, FOREIGN KEY (ProductId)
REFERENCES Product(Id), FOREIGN KEY (BuyerId) REFERENCES Buyer(Id));
Tabel SupplierType
create table SupplierType (Id int NOT NULL PRIMARY KEY, Type varchar(250));
Tabel Supplier
create table Supplier (Id int NOT NULL PRIMARY KEY, SupplierTypeId int NOT NULL,
Name varchar(250), Location varchar(250), Price int, FOREIGN KEY (SupplierTypeId)
REFERENCES SupplierType(Id));
Tabel Supply
create table Supply (Id int NOT NULL PRIMARY KEY, ProductId int NOT NULL, SupplierId
int NOT NULL, CreatedAt varchar(250), Price decimal, FOREIGN KEY (ProductId)
REFERENCES Product(Id), FOREIGN KEY (SupplierId) REFERENCES
Buyer(Id),CONSTRAINT MIN_PriceTarget CHECK (Price >= 50));
Popularea datelor
Tabel Product
Tabel History
insert into History (Id, ProductId, SeasonId, CreatedAt, CompletedAt, Price) values (1, 1, 1,
'23.03.2022', '24.03.2022', 100);
insert into History (Id, ProductId, SeasonId, CreatedAt, CompletedAt, Price) values (2, 2, 1,
'23.03.2022', '24.03.2022', 20);
insert into History (Id, ProductId, SeasonId, CreatedAt, CompletedAt, Price) values (3, 3, 5,
'23.03.2022', '24.07.2022', 10);
insert into History (Id, ProductId, SeasonId, CreatedAt, CompletedAt, Price) values (4, 2, 5,
'21.04.2022', '24.07.2022', 15);
insert into History (Id, ProductId, SeasonId, CreatedAt, CompletedAt, Price) values (5, 6, 2,
'15.06.2022', '16.06.2022', 45);
insert into History (Id, ProductId, SeasonId, CreatedAt, CompletedAt, Price) values (6, 5, 2,
'10.06.2022', '24.06.2022', 214);
insert into ProductType (Id, ProductId, Occurence, Description) values (1, 1, '12x', 'Lorem
ipsum');
insert into ProductType (Id, ProductId, Occurence, Description) values (2, 2, '1x', 'Lorem ipsum
lorem');
insert into ProductType (Id, ProductId, Occurence, Description) values (3, 3, '2x', 'Lorem ipsum
lorem ipsum');
insert into ProductType (Id, ProductId, Occurence, Description) values (4, 3, '5x', 'Lorem ipsum
lorem ipsum lorem');
insert into ProductType (Id, ProductId, Occurence, Description) values (5, 4, '20x', 'Lorem ipsum
lorem ipsum lorem ipsum');
insert into ProductType (Id, ProductId, Occurence, Description) values (6, 6, '5x', 'Lorem ipsum
lorem ipsum lorem ipsum lorem');
Tabel Buyer
insert into BuyerLocation (Id, BuyerId, City, Region, Country, Street, Number) values (1, 1,
'Berlin', 'Bavaria', 'Germany', 'Vasentrop Street', '2');
insert into BuyerLocation (Id, BuyerId, City, Region, Country, Street, Number) values (2, 2,
'Washington', 'District of Columbia', 'USA', 'Independence Avenue', '2');
insert into BuyerLocation (Id, BuyerId, City, Region, Country, Street, Number) values (3, 3,
'New Orleans', 'Louisiana', 'USA', 'Loyola Avenue', '10');
insert into BuyerLocation (Id, BuyerId, City, Region, Country, Street, Number) values (4, 4,
'Cupertino', 'California', 'USA', 'Apple Park Way', '1');
insert into BuyerLocation (Id, BuyerId, City, Region, Country, Street, Number) values (5, 5,
'Osaka', 'Honshu', 'Japan', 'Sumiyoshi Ward', '9-12');
insert into BuyerLocation (Id, BuyerId, City, Region, Country, Street, Number) values (6, 6,
'Birmingham', 'West Midlands', 'UK', 'Henshaw Rd', '2-5');
Tabel Sale
insert into Sale (Id, ProductId, BuyerId, CreatedAt, Price) values (1, 1, 2, '12.02.2021', 234);
insert into Sale (Id, ProductId, BuyerId, CreatedAt, Price) values (2, 1, 3, '12.02.2021', 234);
insert into Sale (Id, ProductId, BuyerId, CreatedAt, Price) values (3, 3, 4, '12.02.2021', 234);
insert into Sale (Id, ProductId, BuyerId, CreatedAt, Price) values (4, 4, 5, '13.02.2021', 234);
insert into Sale (Id, ProductId, BuyerId, CreatedAt, Price) values (5, 5, 6, '13.02.2021', 234);
insert into Sale (Id, ProductId, BuyerId, CreatedAt, Price) values (6, 6, 1, '14.02.2021', 234);
Tabel Supplier
insert into Supplier (Id, SupplierTypeId, Name, Location, Price) values (1, 2, 'Fabrica de lemne',
'Brasov', 4563);
insert into Supplier (Id, SupplierTypeId, Name, Location, Price) values (2, 1, 'Apostol Ion',
'Craiova', 234);
insert into Supplier (Id, SupplierTypeId, Name, Location, Price) values (3, 2, 'Holver',
'Timisoara', 3453);
insert into Supplier (Id, SupplierTypeId, Name, Location, Price) values (4, 2, 'Mobirom', 'Iasi',
334);
insert into Supplier (Id, SupplierTypeId, Name, Location, Price) values (5, 2, 'Nord Arin',
'Milano', 452);
insert into Supplier (Id, SupplierTypeId, Name, Location, Price) values (6, 2, 'Staer', 'Galati',
768);
Tabel Supply
insert into Supply (Id, ProductId, SupplierId, CreatedAt, Price) values (1, 1, 1, '01.09.2015',
234.5);
insert into Supply (Id, ProductId, SupplierId, CreatedAt, Price) values (2, 2, 2, '01.09.2015',
3434.5);
insert into Supply (Id, ProductId, SupplierId, CreatedAt, Price) values (3, 3, 3, '01.09.2015',
436.78);
insert into Supply (Id, ProductId, SupplierId, CreatedAt, Price) values (4, 4, 4, '01.09.2015',
3267.3);
insert into Supply (Id, ProductId, SupplierId, CreatedAt, Price) values (5, 5, 5, '01.09.2015',
4364.5);
insert into Supply (Id, ProductId, SupplierId, CreatedAt, Price) values (6, 6, 6, '01.09.2015',
3552.5);
Modificări de structură
Modificări de conținut:
update BuyerLocation set City = 'New York', Region = 'New Jersey', Street = '3rd Street'
where Id = 2;
update Sale set Price = 340 where Id = 3;
update Supply set ProductId = 2 where Id = 1;
View-uri
from History h
from Sale s
group by s.ProductId
select sum(s.Price)
from Supply s
where sr.SupplierTypeId = 2;
from Supply s
Interogări
1. GetTotalCostPerSupplier
from Supplier sr
group by sr.Name;
2. GetTotalRevenuePerSeason
from Season s
inner join History h on h.SeasonId = s.Id
group by s.Name;
3. GetSupplierTypeThatSoldMoreThan3Times
from SupplierType st
4. GetProductWithPriceAboveAverageSupplierCosts
From Sale s
5. AppleTotalBuyValue
From Sale
where BuyerId = 4;
6. MostNeededProduct
from Supply s
group by s.ProductId
from Sale s
group by s.ProductId
8. GetClientTypeThatBoughtMoreThan2Times
from BuyerType bt
9. GetLocationThatBoughtMoreThanTwoTimes
from Buyer b
10. GetProductsPurchasedAbove30
from Product p
from Product p
12. GetProductsWithMoreThan2Sales
from Product p
13. FindAllDiscontinuedItemsWithUnitsInStock
from Product