SSMS => Right click destination database => Tasks => Take Offline
Find the location of database backup and latest full backup (BAK)
SSMS => New Query => Do restore with following script (notice: this example restore is done from prod to test)
RESTORE DATABASE SomecityTest FROM DISK='I:\SQLBackup\SomecityProd\SomecityProd_backup_2021_08_09_190001_2760309.bak'
WITH
MOVE 'SomecityProd' TO 'F:\SQLData\SomecityTest.mdf',
MOVE 'SomecityProd_log' TO 'G:\SQLData\SomecityTest_log.ldf',
REPLACE
SSMS => Right click destination database => Tasks => Take Online
indeksien fragmentaatiokysely
SELECT
OBJECT_NAME(ips.object_id) AS TableName,
i.name AS IndexName,
ips.index_id,
ips.index_type_desc,
ips.avg_fragmentation_in_percent,
ips.fragment_count,
ips.page_count
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, 'limited') ips
INNER JOIN sys.indexes i ON ips.object_id = i.object_id AND ips.index_id = i.index_id
WHERE ips.page_count > 2000 -- Filter out small indexes
ORDER BY ips.avg_fragmentation_in_percent DESC;
näyttää nätin tuloksen monta prosenttia on fragmentoitunut