我在MS SQL Server数据库中建模了一个不寻常的情况:表的主键是一个由5个外键(固定大小)组成的多段“自然”键。
我希望能够定义一个用户定义的数据类型,以实现基于CHAR(8)原语的数据结构,使元素可以作为单独的字段进行寻址。
例如(在错误的伪代码中):
UDT seggy
(
seg1 char(2),
seg2 char(1),
seg3 char(1),
seg4 char(2),
seg5 char(2)
)
create table yotable
(
pkfield seggy NOT NULL,
etc varchar(14), --whatever etc.
)
with pkfield as the primary key,
and also with seg1 as a foreign key to tableseg1,
and also with seg2 as a foreign key to tableseg2,
and so on
然后能够做这样的事情:
insert into yotable (pkfield, etc) values ('abcdefgh','whatever')
select * from yotable where seg2 = 'c'
insert into yotable (seg1,seg2,seg3,seg4,seg5,etc)
values ('ab','c','d','ef','gh', 'whatever')
到目前为止,我只找到了这个
CodeProject article
这还不够深入,也没有提供更多信息的链接,而这个基础
MSDN link
.
显然,我的谷歌傅今晚很弱,非常感谢任何链接/提示!
替代标题:如何在SQL SERVER中模拟“覆盖”字段?
假设/首选MS SQL SERVER 2005或更高版本。