在ABP项目开发系列中,使用Poem作为例子,相关数据库表的Sql语句如下:
Poet:
CREATE TABLE [dbo].[Poet](
[PoetID] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](200) NULL,
[Description] [varchar](4000) NULL,
CONSTRAINT [PK_PEOT] PRIMARY KEY NONCLUSTERED
(
[PoetID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
Poem:
CREATE TABLE [dbo].[Poem](
[PoemId] [int] IDENTITY(1,1) NOT NULL,
[PoetID] [int] NULL,
[Title] [nvarchar](1024) NULL,
[Content] [ntext] NULL,
[Comments] [ntext] NULL,
[Volumn] [nvarchar](20) NULL,
[Num] [nvarchar](20) NULL,
CONSTRAINT [PK_PEOM] PRIMARY KEY NONCLUSTERED
(
[PoemId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[Poem] WITH CHECK ADD CONSTRAINT [FK_Peom_Peot] FOREIGN KEY([PoetID])
REFERENCES [dbo].[Poet] ([PoetID])
GO
ALTER TABLE [dbo].[Poem] CHECK CONSTRAINT [FK_Peom_Peot]
GO
Category:
CREATE TABLE [dbo].[Category](
[CategoryName] [nvarchar](150) NULL,
[CategoryId] [int] IDENTITY(1,1) NOT NULL,
CONSTRAINT [PK_Category] PRIMARY KEY CLUSTERED
(
[CategoryId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CategoryPoem:
CREATE TABLE [dbo].[CategoryPoem](
[CategoryPoemId] [int] IDENTITY(1,1) NOT NULL,
[CategoryId] [int] NOT NULL,
[PoemId] [int] NOT NULL,
CONSTRAINT [PK_CategoryPeom] PRIMARY KEY CLUSTERED
(
[CategoryPoemId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[CategoryPoem] WITH CHECK ADD CONSTRAINT [FK_CategoryPeom_Category] FOREIGN KEY([CategoryId])
REFERENCES [dbo].[Category] ([CategoryId])
GO
ALTER TABLE [dbo].[CategoryPoem] CHECK CONSTRAINT [FK_CategoryPeom_Category]
GO
ALTER TABLE [dbo].[CategoryPoem] WITH CHECK ADD CONSTRAINT [FK_CategoryPeom_Peom] FOREIGN KEY([PoemId])
REFERENCES [dbo].[Poem] ([PoemId])
GO
ALTER TABLE [dbo].[CategoryPoem] CHECK CONSTRAINT [FK_CategoryPeom_Peom]
GO
PoemLine:
CREATE TABLE [dbo].[PoemLine](
[PoemLineId] [int] IDENTITY(1,1) NOT NULL,
[PoemId] [int] NOT NULL,
[LineContent] [nvarchar](4000) NULL,
[Order] [int] NULL,
CONSTRAINT [PK_PEOMLINE] PRIMARY KEY NONCLUSTERED
(
[PoemLineId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[PoemLine] WITH CHECK ADD CONSTRAINT [FK_PeomLine_Peom] FOREIGN KEY([PoemId])
REFERENCES [dbo].[Poem] ([PoemId])
GO
ALTER TABLE [dbo].[PoemLine] CHECK CONSTRAINT [FK_PeomLine_Peom]
GO