我试图为下面的场景创建一个ERD,这就是我所拥有的......但我有一种感觉,我可能会错过一些东西,或者它可以吗? 顺便说一下,数据需要标准化为3NF。
情景 Samuels Property Development是一家总部位于英国曼彻斯特的建筑公司。公司希望您设计和实施满足其业务要求的数据库。这些要求在此业务情景中指定,并且公司保存的纸质文档示例如下所示。 Samuels Property Development专门代表客户管理高价值项目。客户可能有许多项目,但每个项目都分配给特定客户。项目按类型分类。每个项目可能有一个或多个工作人员,但个别工作人员只能在特定时间在一个项目上工作。项目由砖,木材和玻璃等材料制成。项目中可能有许多材料。材料从指定供应商处获得。
到目前为止,这是我的SQL查询:
-- STEP 1: Create lowry_property database
CREATE DATABASE lowry_property
GO
USE lowry_property;
-- STEP 2: Create ProjectType table
GO
CREATE TABLE ProjectType
(
ProjectTypeID int IDENTITY(1,1) PRIMARY KEY,
ProjectTypeName nvarchar(50) NOT NULL,
ProjectAddress nvarchar(255)
);
-- STEP 3: Create Supplier table
GO
CREATE TABLE Supplier
(
SupplierID int IDENTITY(1,1) PRIMARY KEY,
SupplierName nvarchar(50) NOT NULL,
SupplierCity nvarchar(50),
SupplierAddress nvarchar(255)
);
-- STEP 4: Create Material table
GO
CREATE TABLE Material
(
MaterialID int IDENTITY(1,1) PRIMARY KEY,
MaterialName nvarchar(50) NOT NULL,
SupplierID int NOT NULL
FOREIGN KEY REFERENCES Supplier (SupplierID)
);
-- STEP 5: Create StaffType table
GO
CREATE TABLE StaffType
(
StaffTypeID int IDENTITY(1,1) PRIMARY KEY,
StaffTypeName nvarchar(50) NOT NULL
);
-- STEP 7: Create Staff table
GO
CREATE TABLE Staff
(
StaffID int IDENTITY(1,1) PRIMARY KEY,
StaffFirstName nvarchar(50) NOT NULL,
StaffLastName nvarchar(50) NOT NULL,
StaffTypID int NOT NULL
FOREIGN KEY REFERENCES StaffType (StaffTypeID)
);
-- STEP 8: Create Project table
CREATE TABLE Project
(
ProjectID int IDENTITY(1,1) PRIMARY KEY,
ProjectName nvarchar(255),
ProjectTypeID int NOT NULL
FOREIGN KEY REFERENCES ProjectType (ProjectTypeID),
ProjectStartDate date,
ProjectEndDate date,
StaffID int NOT NULL
FOREIGN KEY REFERENCES Staff (StaffID),
MaterialID int NOT NULL
FOREIGN KEY REFERENCES Material (MaterialID)
);
-- STEP 9: Create County table
GO
CREATE TABLE County
(
CountyID int IDENTITY(1,1) PRIMARY KEY,
CountyName nvarchar(50) NOT NULL
);
-- STEP 10: Create City table
GO
CREATE TABLE City
(
CityID int IDENTITY(1,1) PRIMARY KEY,
City nvarchar(100) NOT NULL
);
-- STEP 11: Create Address table
GO
CREATE TABLE Address
(
AddressID int IDENTITY(1,1) PRIMARY KEY,
Street nvarchar(255) NOT NULL,
PostCode nvarchar(15) NOT NULL,
);
-- STEP 12: Create Client table
GO
CREATE TABLE Client
(
ClientID int IDENTITY(1,1) PRIMARY KEY,
ClientFirstName nvarchar(50) NOT NULL,
ClientLastName nvarchar(50) NOT NULL,
ClientAddress nvarchar(255),
CountyID int NOT NULL
FOREIGN KEY REFERENCES County (CountyID),
CityID int NOT NULL
FOREIGN KEY REFERENCES City (CityID),
AddressID int NOT NULL
FOREIGN KEY REFERENCES Address (AddressID),
ProjectID int NOT NULL
FOREIGN KEY REFERENCES Project (ProjectID)
);