经过昨天的帖,让我掌握了寻找缺失索引的一般性方法。
现在再请教另外的问题:(假设业务数据的数量级在千万以上,基础数据的数量级在几千到几万条记录之间)
1、针对大数据量的索引,是不是要按单个字段来建立?
现象:整理昨天的索引的时候,其中有个外键涉及到的表其实是没有数据的,如下面脚本中的TableD的逻辑关系,我要删除的表类似TableE,其实tableD中并没有我要删除的E中所关联的数据,因为D中的数据已经用其它SQL语句删掉了。D的索引有建立,也包含了TE这个字段,只是混合在接近10个字段共同组合的索引之中,删除速度很慢,我用了【执行计划】查看,发现是这个表花费了很长时间,试着把索引拆开,速度就很快了。
2、级联删除是否能够提升涉及外键的删除速度?
假如TableD中的TE不建立索引,使用级联删除能提升速度不?
3、针对下面的脚本中的表结构,我要删除TableE的数据,如何使用级联删除?
Visio图在后面。
CREATE TABLE [dbo].[TableA](
[TA] [int] NOT NULL,
[TAName] [varchar](10) NULL,
CONSTRAINT [TableA_PK] PRIMARY KEY CLUSTERED
(
[TA] 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
CREATE TABLE [dbo].[TableB](
[TB] [int] NOT NULL,
[TBName] [varchar](10) NULL,
CONSTRAINT [TableB_PK] PRIMARY KEY CLUSTERED
(
[TB] 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
CREATE TABLE [dbo].[TableC](
[TC] [int] NOT NULL,
[TCName] [varchar](10) NULL,
CONSTRAINT [TableC_PK] PRIMARY KEY CLUSTERED
(
[TC] 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
CREATE TABLE [dbo].[TableD](
[TD] [int] NOT NULL,
[TDName] [varchar](10) NULL,
[TC] [int] NULL,
[TA] [int] NULL,
[TE] [int] NULL,
CONSTRAINT [TableD_PK] PRIMARY KEY CLUSTERED
(
[TD] 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
CREATE TABLE [dbo].[TableE](
[TE] [int] NOT NULL,
[TEName] [varchar](10) NULL,
[TA] [int] NULL,
[TB] [int] NULL,
[TC] [int] NULL,
CONSTRAINT [TableE_PK] PRIMARY KEY CLUSTERED
(
[TE] 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
CREATE TABLE [dbo].[TableF](
[TF] [int] NOT NULL,
[TFName] [varchar](10) NULL,
[TD] [int] NULL,
[TE] [int] NULL,
[TC] [int] NULL,
[TB] [int] NULL,
[TA] [int] NULL,
CONSTRAINT [TableF_PK] PRIMARY KEY CLUSTERED
(
[TF] 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].[TableD] WITH CHECK ADD CONSTRAINT [TableA_TableD_FK1] FOREIGN KEY([TA])