Есть ли более хорошие варианты, чем
- Код: Выделить всё
create table [Type]
(
[Id] integer not null primary key,
[Text] nvarchar(32) not null unique
);
insert into [Type] ([Id], [Text]) values (1, 'Подтип 1');
insert into [Type] ([Id], [Text]) values (2, 'Подтип 2');
create table [Main]
(
[Id] integer not null primary key identity(1,1),
[TypeId] integer not null,
[Text] nvarchar(32) not null,
unique ([Id], [TypeId]),
foreign key ([TypeId]) references [Type] ([Id])
);
create table [Way1]
(
[Id] integer not null primary key,
[TypeId] integer check ([TypeId]=1) not null default 1,
[Field1] integer not null,
foreign key ([Id]) references [Main] ([Id]),
foreign key ([Id],[TypeId]) references [Main] ([Id],[TypeId])
);
create table [Way2]
(
[Id] integer not null primary key,
[TypeId] integer check ([TypeId]=2) not null default 2,
[Field2] nvarchar(16) not null,
foreign key ([Id]) references [Main] ([Id]),
foreign key ([Id],[TypeId]) references [Main] ([Id],[TypeId])
);
PS: База данных SQL Server, но хотелось бы, чтобы решение от этого не зависело.