Quantcast
Channel: Forum SQL Server Database Engine
Viewing all articles
Browse latest Browse all 15889

How to drop non-clustered indexes from offline filegroup

$
0
0

Hi,

We are simulating a recovery test and splitting the data so that clustered indexes will be stored on primary filegroup and secondary indexes will be stored on secondary filegroup. So we used the following script:

create database TestDB on  PRIMARY ( name = 'TestDB', filename = 'C:\backups\TestDB.mdf'),  filegroup FG1 ( name = 'TestDB_File1', filename = 'C:\backups\TestDB_File1.ndf') log on ( name = 'TestDB_log', filename = 'C:\backups\TestDB_log.ldf')GOcreate table TestDB.dbo.a (id int NOT NULL PRIMARY key, id1 int) on [PRIMARY]CREATE NONCLUSTERED INDEX idx_a ON a (id1) on [FG1]insert into TestDB.dbo.a values(1,1)insert into TestDB.dbo.a values(2,2)select * from TestDB.dbo.agoHere we can detach database manually and remove the TestDB_File1.ndf and move other 2 files to some temporary location and remove from c:\backupsuse masterif db_id('TestDB') is not null	drop database TestDBgocreate database TestDB on  PRIMARY ( name = 'TestDB', filename = 'C:\backups\TestDB.mdf'),  filegroup FG1 ( name = 'TestDB_File1', filename = 'C:\backups\TestDB_File1.ndf') log on ( name = 'TestDB_log', filename = 'C:\backups\TestDB_log.ldf')GOalter database TestDB modify file(name = 'TestDB_File1', offline)goalter database TestDB set offline-- remove all database files-- copy TestDB.mdf and TestDB_log.ldf back to C:\backupgoalter database TestDB set ONLINENow when we do insert into table a: insert into TestDB.dbo.a values(3,3)then it fails with error "The table 'a' cannot be modified because one or more non-clustered indexes reside in a filegroup which is not online."if we try to drop INDEX : DROP INDEX a.idx_aERROR IS : "Cannot drop the index 'a.idx_a' because at least part of the table resides on an offline filegroup."We removed the FILE AND FILEGROUP:ALTER DATABASE TestDB REMOVE FILE TestDB_File1ALTER DATABASE TestDB REMOVE FILEGROUP FG1


Still we can't drop the index or do DML on table?

How to drop all non-clustered indexes on corrupted filegroup so we can recreate them on new filegroup?


Viewing all articles
Browse latest Browse all 15889

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>