我有三个MS SQL Server(2008)表:
CREATE TABLE [dbo].[blog_BlogSet]
(
[BlogSetId] NVARCHAR(10) NOT NULL,
CONSTRAINT [PK_dbo.blog_BlogSet] PRIMARY KEY CLUSTERED ([BlogSetId] ASC)
);
CREATE TABLE [dbo].[blog_Persona]
(
[PersonaId] INT IDENTITY (1, 1) NOT NULL,
[BlogSetId] NVARCHAR(10) NOT NULL,
[Name] NVARCHAR(128) NOT NULL,
CONSTRAINT [PK_blog_Persona] PRIMARY KEY CLUSTERED ([PersonaId] ASC),
CONSTRAINT [FK_blog_Persona_blog_BlogSet] FOREIGN KEY ([BlogSetId]) REFERENCES [dbo].[blog_BlogSet] ([BlogSetId]) ON DELETE CASCADE
);
CREATE UNIQUE NONCLUSTERED INDEX [IX_blog_Persona_Name]
ON [dbo].[blog_Persona]([BlogSetId] ASC, [Name] ASC);
CREATE TABLE [dbo].[blog_Blog]
(
[BlogId] INT IDENTITY (1, 1) NOT NULL,
[PersonaId] INT NOT NULL,
[Title] NVARCHAR (128) NOT NULL,
CONSTRAINT [PK_blog_BlogId] PRIMARY KEY CLUSTERED ([BlogId] ASC),
CONSTRAINT [FK_blog_Blog_blog_Persona] FOREIGN KEY ([PersonaId]) REFERENCES [dbo].[blog_Persona] ([PersonaId]) ON DELETE CASCADE
);
因此,BlogSet包含多个BlogPersonas,每个BlogPersona可以包含多个博客。每个BlogPersona.Name在BlogSet中都是唯一的。
我现在想在BlogSet中使Blog.Title字段唯一。我可以看到我将如何在BlogPersona中执行此操作,但我要注意如何执行此操作并提升表格层次结构'。我考虑过的事情是:
有没有好办法呢?