我正在LucidChart上建立一个啤酒厂的图表,该啤酒厂在1个地点销售和制造啤酒。我观看了一些有关如何设计ER模型的视频。想知道这是正确的还是我犯了任何错误。在讨论ER模型时,“映射”到底是什么?
答案 0 :(得分:0)
在谈论ER模型时到底是什么“映射”?
在数据模型的上下文中,术语“映射”是将数据模型转换为SQL DDL的过程的名称,然后该SQL DDL可用于在数据库管理系统(例如MySQL)中创建数据库架构, SQL Server,Oracle等。
据我所知,您无法使用Visio和LucidChart之类的工具进行“映射”,因为这些工具不是为数据建模而设计的。它们旨在使绘图过程机械化。 (正确的数据模型包含的内容不止图片)
作为示例,我使用您的ER图使用免费的NORMA工具设计对象角色模型。下图显示:
对象角色模型
逻辑模型(从对象角色模型生成逻辑模型花费了几毫秒的时间。)
我从对象角色模型“映射”的SQL DDL(将对象角色模型映射到SQL DDL花费了几秒钟。)
我使用SQL Server Management Studio,因此可以将DDL的T-SQL版本复制并粘贴到“新建查询”窗口中,并在几秒钟内生成数据库表。
这是逻辑模型(自动生成)。请注意,与模型不同,逻辑模型中只有一个“地址”表。
这是MySQL Server的SQL DDL(自动生成)
CREATE TABLE Brewery
(
breweryNr INT NOT NULL,
addressNr INT NOT NULL,
breweryName CHAR(63) NOT NULL,
CONSTRAINT Brewery_PK PRIMARY KEY(breweryNr)
);
CREATE TABLE Address
(
addressNr INT NOT NULL,
country CHAR(63) NOT NULL,
street CHAR(63) NOT NULL,
town CHAR(63) NOT NULL,
zipCode CHAR(63) NOT NULL,
CONSTRAINT Address_PK PRIMARY KEY(addressNr)
);
CREATE TABLE Beer
(
beerType CHAR(63) NOT NULL,
alcoholPercent INT NOT NULL,
beerAmountLitres CHAR(63) NOT NULL,
beerID CHAR(63) NOT NULL,
beerPrice CHAR(63) NOT NULL,
kegNr INT NOT NULL,
CONSTRAINT Beer_PK PRIMARY KEY(beerType)
);
CREATE TABLE BreweryMakesBeer
(
beerType CHAR(63) NOT NULL,
breweryNr INT NOT NULL,
CONSTRAINT BreweryMakesBeer_PK PRIMARY KEY(breweryNr, beerType)
);
CREATE TABLE Keg
(
kegNr INT NOT NULL,
kegState CHAR(63) NOT NULL,
CONSTRAINT Keg_PK PRIMARY KEY(kegNr)
);
CREATE TABLE Employee
(
employeeNr INT NOT NULL,
addressNr INT NOT NULL,
birthDate INT NOT NULL,
breweryNr INT NOT NULL,
firstName CHAR(63) NOT NULL,
lastName CHAR(63) NOT NULL,
salary DECIMAL(6,4) NOT NULL,
SSN CHAR(63) NOT NULL,
middleInt CHAR(63),
CONSTRAINT Employee_PK PRIMARY KEY(employeeNr)
);
CREATE TABLE Distributor
(
distributorNr INT NOT NULL,
brewingIngredientNr INT NOT NULL,
CONSTRAINT Distributor_PK PRIMARY KEY(distributorNr)
);
CREATE TABLE BrewingIngredient
(
brewingIngredientNr INT NOT NULL,
ingredientName CHAR(63) NOT NULL,
CONSTRAINT BrewingIngredient_PK PRIMARY KEY(brewingIngredientNr)
);
CREATE TABLE IngredientSupplier
(
ingredientSupplierNr INT NOT NULL,
addressNr INT NOT NULL,
CONSTRAINT IngredientSupplier_PK PRIMARY KEY(ingredientSupplierNr)
);
CREATE TABLE IngredientSupply
(
brewingIngredientNr INT NOT NULL,
ingredientSupplierNr INT NOT NULL,
CONSTRAINT IngredientSupply_PK PRIMARY KEY(brewingIngredientNr, ingredientSupplierNr)
);
ALTER TABLE Brewery ADD CONSTRAINT Brewery_FK FOREIGN KEY (addressNr) REFERENCES Address (addressNr) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE Beer ADD CONSTRAINT Beer_FK FOREIGN KEY (kegNr) REFERENCES Keg (kegNr) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE BreweryMakesBeer ADD CONSTRAINT BreweryMakesBeer_FK1 FOREIGN KEY (breweryNr) REFERENCES Brewery (breweryNr) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE BreweryMakesBeer ADD CONSTRAINT BreweryMakesBeer_FK2 FOREIGN KEY (beerType) REFERENCES Beer (beerType) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE Employee ADD CONSTRAINT Employee_FK1 FOREIGN KEY (breweryNr) REFERENCES Brewery (breweryNr) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE Employee ADD CONSTRAINT Employee_FK2 FOREIGN KEY (addressNr) REFERENCES Address (addressNr) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE Distributor ADD CONSTRAINT Distributor_FK FOREIGN KEY (brewingIngredientNr) REFERENCES BrewingIngredient (brewingIngredientNr) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE IngredientSupplier ADD CONSTRAINT IngredientSupplier_FK FOREIGN KEY (addressNr) REFERENCES Address (addressNr) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE IngredientSupply ADD CONSTRAINT IngredientSupply_FK1 FOREIGN KEY (brewingIngredientNr) REFERENCES BrewingIngredient (brewingIngredientNr) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE IngredientSupply ADD CONSTRAINT IngredientSupply_FK2 FOREIGN KEY (ingredientSupplierNr) REFERENCES IngredientSupplier (ingredientSupplierNr) ON DELETE RESTRICT ON UPDATE RESTRICT;