我需要截断一个表来刷新数据,但是这个表的索引视图取决于它。我试图删除索引,然后截断表,然后重新创建索引。我收到一个错误,即非聚集索引不存在或者我没有权限删除它们...代码存在于下面显示的存储过程中。我假设它与存储过程中的执行顺序有关,因为手动执行代码(drop / truncate / create)。
DROP INDEX [IDX_VDetailEmergency] ON [dbo].[vFactEmergencySummary] WITH ( ONLINE = OFF )
DROP INDEX [IDX_VDetailEmergency_facility_refno] ON [dbo].[vFactEmergencySummary] WITH ( ONLINE = OFF )
DROP INDEX [IDX_VDetailEmergency_mode_of_separation_refno] ON [dbo].[vFactEmergencySummary] WITH ( ONLINE = OFF )
DROP INDEX [IDX_VDetailEmergency_period_refno] ON [dbo].[vFactEmergencySummary] WITH ( ONLINE = OFF )
truncate table DetailEmergency
CREATE UNIQUE CLUSTERED INDEX [IDX_VDetailEmergency] ON [dbo].[vFactEmergencySummary]
(
[facility_refno] ASC,
[period_refno] ASC,
[mode_of_separation_refno] ASC,
[ed_visit_type_refno] ASC,
[triage_category] ASC,
[UDG_refno] ASC,
[URG_refno] ASC,
[URG_MDB_refno] ASC
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [IDX_VDetailEmergency_facility_refno] ON [dbo].[vFactEmergencySummary]
(
[facility_refno] ASC
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [IDX_VDetailEmergency_mode_of_separation_refno] ON [dbo].[vFactEmergencySummary]
(
mode_of_separation_refno ASC
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [IDX_VDetailEmergency_period_refno] ON [dbo].[vFactEmergencySummary]
(
period_refno ASC
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
答案 0 :(得分:0)
如果您可以删除并重新创建表格,则可以使用SQL Server Management Studio执行以下步骤:
快乐管理!