- Can a field reference to 2 different FKs or any better option for this case?
- CREATE TABLE `settings` (
- `setting_id` int(6) NOT NULL,
- `description` varchar(32) NOT NULL,
- `code` int(6) DEFAULT NULL,
- `created` datetime NOT NULL,
- `updated` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- PRIMARY KEY (`setting_id`),
- KEY `code` (`code`),
- CONSTRAINT `settings_ibfk_1` FOREIGN KEY (`code`) REFERENCES `field_values` (`fv_id`) ON UPDATE CASCADE
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
- create table Setting (
- SettingID integer not null
- , SettingType char(1) not null
- , SettingName varchar(32) not null
- , Description varchar(32) not null
- , Created timestamp default CURRENT_TIMESTAMP
- -- other common-to-all-setups columns here
- );
- alter table Setting add constraint pk_setting primary key (SettingID);
- create table LanguageSetting (
- SettingID integer not null
- , Updated timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
- -- other columns specific to this setup-type here
- );
- alter table LanguageSetting
- add constraint pk_langset primary key (SettingID)
- , add constraint fk1_langset foreign key (SettingID) references Setting(SettingID);
- create table AgeFilterSetting (
- SettingID integer not null
- , Updated timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
- -- other columns specific to this setup-type here
- );
- alter table AgeFilterSetting
- add constraint pk_ageflt primary key (SettingID)
- , add constraint fk1_ageflt foreign key (SettingID) references Setting(SettingID);
- create table OtherSetting (
- SettingID integer not null
- , Updated timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
- -- other columns specific to this setup-type here
- );
- alter table OtherSetting
- add constraint pk_othset primary key (SettingID)
- , add constraint fk1_othset foreign key (SettingID) references Setting(SettingID);
- CREATE TABLE [Child1](
- [ParentId] int NOT NULL,
- CONSTRAINT [PK2] PRIMARY KEY CLUSTERED ([ParentId])
- )
- CREATE TABLE [Child2](
- [ParentId] int NOT NULL,
- CONSTRAINT [PK3] PRIMARY KEY CLUSTERED ([ParentId])
- )
- CREATE TABLE [Parent](
- [ParentId] int NOT NULL,
- CONSTRAINT [PK1] PRIMARY KEY CLUSTERED ([ParentId])
- )
- ALTER TABLE [Child1] ADD CONSTRAINT [RefParent1]
- FOREIGN KEY ([ParentId])
- REFERENCES [Parent]([ParentId])
- ALTER TABLE [Child2] ADD CONSTRAINT [RefParent3]
- FOREIGN KEY ([ParentId])
- REFERENCES [Parent]([ParentId])