我有一个不寻常的情况在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。
显然我的google-fu今晚很弱,任何链接/提示非常感谢!
备用标题:如何模拟SQL SERVER中的'overlay'字段?
MS SQL SERVER 2005或更高版本假设/首选。
感谢(a)唯一的答案和(b)替代方案。我不认为UDT会起作用,但不能通过谷歌搜索来证明消极;-)。计算列也是PK,但根据http://www.devx.com/tips/Tip/15397这是可行的。 – 2008-12-17 00:45:48