I want to make an electronic journal for maintaining a list of equipment, with the ability to create parameters in the client part, i.e. A new position appeared with its own unique set of characteristics, the user added equipment, created the necessary parameters and added them.
For these purposes, I made the following tables in the database:
Handbook of equipment parameters
CREATE TABLE dbo.ParametersOfEquipments ( Id INT IDENTITY, TypeId INT NOT NULL, Name NVARCHAR(50) COLLATE Cyrillic_General_CI_AS NOT NULL, Created DATETIME NOT NULL, AuthorId INT NOT NULL, Deleted TINYINT NOT NULL DEFAULT (0), CONSTRAINT [PK_dbo.ParametersOfEquipments] PRIMARY KEY CLUSTERED (Id), CONSTRAINT [FK_dbo.ParametersOfEquipments_dbo.Users_AuthorId] FOREIGN KEY (AuthorId) REFERENCES dbo.Users (Id) ) ON [PRIMARY] GO Table equipment
CREATE TABLE dbo.Equipments ( Id INT IDENTITY, TypeId INT NOT NULL, Name NVARCHAR(MAX) COLLATE Cyrillic_General_CI_AS NULL, Model NVARCHAR(MAX) COLLATE Cyrillic_General_CI_AS NULL, AssetNumber NVARCHAR(15) COLLATE Cyrillic_General_CI_AS NOT NULL, UnitId INT NOT NULL, Created DATETIME NOT NULL, AuthorId INT NOT NULL, Deleted TINYINT NOT NULL DEFAULT (0), CONSTRAINT [PK_dbo.Equipments] PRIMARY KEY CLUSTERED (Id), CONSTRAINT [FK_dbo.Equipments_dbo.EquipmentTypes_TypeId] FOREIGN KEY (TypeId) REFERENCES dbo.EquipmentTypes (Id) ON DELETE CASCADE, CONSTRAINT [FK_dbo.Equipments_dbo.Units_UnitId] FOREIGN KEY (UnitId) REFERENCES dbo.Units (Id) ON DELETE CASCADE, CONSTRAINT [FK_dbo.Equipments_dbo.Users_AuthorId] FOREIGN KEY (AuthorId) REFERENCES dbo.Users (Id) ON DELETE CASCADE ) ON [PRIMARY] GO History of equipment parameters
CREATE TABLE dbo.HistoryParametersOfEquipments ( Id INT IDENTITY, EquipmentId INT NOT NULL, ParameterId INT NOT NULL, Value NVARCHAR(MAX) COLLATE Cyrillic_General_CI_AS NULL, ValidFrom DATETIME NOT NULL, ValidTo DATETIME NOT NULL, Created DATETIME NOT NULL, AuthorId INT NOT NULL, CONSTRAINT [PK_dbo.HistoryParametersOfEquipments] PRIMARY KEY CLUSTERED (Id), CONSTRAINT [FK_dbo.HistoryParametersOfEquipments_dbo.Equipments_EquipmentId] FOREIGN KEY (EquipmentId) REFERENCES dbo.Equipments (Id) ON DELETE CASCADE, CONSTRAINT [FK_dbo.HistoryParametersOfEquipments_dbo.ParametersOfEquipments_ParameterId] FOREIGN KEY (ParameterId) REFERENCES dbo.ParametersOfEquipments (Id) ON DELETE CASCADE, CONSTRAINT [FK_dbo.HistoryParametersOfEquipments_dbo.Users_AuthorId] FOREIGN KEY (AuthorId) REFERENCES dbo.Users (Id) ) ON [PRIMARY] GO In the ParametersOfEquipments table there is a TypeId field TypeId suppose to create a directory of parameter types, i.e. something like: string , int , DateTime , bool .
But some parameters should be selected from the directory: for example, the Unit parameter ( UnitId field in Equipments ), or the Equipment state should be selected from the directory of possible states, etc.
Please tell me how it is necessary to change / modify the above scheme to implement the selection of the values of some parameters from the tables of directories in the database.