Originally posted by SimonMac
View Post
- Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
- Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Reply to: Paging All SQL Monkeys!
Collapse
You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:
- You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
- You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
- If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.
Logging in...
Previously on "Paging All SQL Monkeys!"
Collapse
-
Originally posted by BigRed View PostSorry, you've completely lost me there
If you are talking about one SQL Instance (and it's DR solution) it really can be worth getting a proper production DBA in to give the system a full healthcheck, set up maintenance, report on deviations from best practices, lock down the security etc. It can be done in a couple of days and save a lot of grief. Development DBAs can not be relied on for this, it isn't what they do. Now where would you find an experienced production DBA
Leave a comment:
-
Originally posted by eek View PostIf we could do the indexes without taking the server down we could justify spending weeks on it.
If you are talking about one SQL Instance (and it's DR solution) it really can be worth getting a proper production DBA in to give the system a full healthcheck, set up maintenance, report on deviations from best practices, lock down the security etc. It can be done in a couple of days and save a lot of grief. Development DBAs can not be relied on for this, it isn't what they do. Now where would you find an experienced production DBA
Leave a comment:
-
Originally posted by BigRed View PostYes, Ola's solution is what we use at my current site as a full ongoing maintenance solution, it even builds the jobs for you. Bit OTP for the OP though.
Leave a comment:
-
Originally posted by SimonMac View PostAnyone got a quick and dirty script they rely on to rebuild all the indexes in a database for SQL 2008 R2?
There is a few in google but would prefer one that comes for someone here
SQL Server Index and Statistics Maintenance
Leave a comment:
-
Originally posted by d000hg View PostIf you don't trust random scripts on Google, ask on StackOverflow and rely on the peer view system to spot obvious problems.Originally posted by eek View PostNot quite:
Add question to stackoverflow
Get mate to write your solution down as the solution to the problem.
Then if no one else comments you have both fixed the problem and set up your solution as best practice...
Ironically at previous clientco we discovered that a previous contractor had done exactly that.
Leave a comment:
-
If you don't trust random scripts on Google, ask on StackOverflow and rely on the peer view system to spot obvious problems.
Leave a comment:
-
If you really want to rebuild them all, use a maintenance plan, for something doing only those that need it and switching between reorg/rebuild with logic for which edition and online or not use Michelle Uffords (SQLFool) script Index Defrag Script, v4.1 SQL Fool
or one for 2005 but I've lost the acknowlegement:
-- define index defrag rate for this run
DECLARE @fragrate float;
SET @fragrate = 30.0; -- set to do something if defrag rate HIGH
DECLARE @rbrirate float;
SET @rbrirate = 50.0; -- set to rebuild if defrag rate EXTREME
-- define table holding index information
DECLARE @indexinfo TABLE(objectid int, indexid int, partitionnum bigint, frag float)
DECLARE @objectid int;
DECLARE @indexid int;
DECLARE @partitioncount bigint;
DECLARE @schemaname nvarchar(130);
DECLARE @objectname nvarchar(130);
DECLARE @indexname nvarchar(130);
DECLARE @partitionnum bigint;
DECLARE @partitions bigint;
DECLARE @frag float;
DECLARE @command nvarchar(4000);
DECLARE @DBID int;
set @DBID = (select db_id())
-- Conditionally select tables and indexes from the sys.dm_db_index_physical_stats function
INSERT INTO @indexinfo
SELECT
object_id AS objectid,
index_id AS indexid,
partition_number AS partitionnum,
avg_fragmentation_in_percent AS frag
FROM sys.dm_db_index_physical_stats (@DBID, NULL, NULL , NULL, 'LIMITED')
WHERE avg_fragmentation_in_percent > @fragrate
AND index_id > 0 AND page_count > 50 AND alloc_unit_type_desc = 'IN_ROW_DATA'; --
-- Declare the cursor for the list of partitions to be processed.
DECLARE partitions CURSOR FOR SELECT * FROM @indexinfo;
OPEN partitions;
-- Loop through the partitions.
FETCH NEXT FROM partitions
INTO @objectid, @indexid, @partitionnum, @frag;
WHILE (@@fetch_status <> -1)
BEGIN;
IF (@@fetch_status <> -2)
BEGIN
SELECT @objectname = QUOTENAME(o.name), @schemaname = QUOTENAME(s.name)
FROM sys.objects AS o
JOIN sys.schemas as s ON s.schema_id = o.schema_id
WHERE o.object_id = @objectid;
SELECT @indexname = QUOTENAME(name)
FROM sys.indexes
WHERE object_id = @objectid AND index_id = @indexid;
SELECT @partitioncount = count (*)
FROM sys.partitions
WHERE object_id = @objectid AND index_id = @indexid;
-- 30 is an arbitrary decision point at which to switch between reorganizing and rebuilding.
IF @frag < @rbrirate
SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N' REORGANIZE';
IF @frag >= @rbrirate
SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N' REBUILD';
IF @partitioncount > 1
SET @command = @command + N' PARTITION=' + CAST(@partitionnum AS nvarchar(10));
------------------- EXEC (@command);
PRINT N'Executed (Defrag ' + CAST(@frag AS varchar(12)) + '): ' + @command;
END;
-- Get the next record to process
FETCH NEXT FROM partitions
INTO @objectid, @indexid, @partitionnum, @frag;
END;
-- Close and deallocate the cursor.
CLOSE partitions;
DEALLOCATE partitions;
Leave a comment:
-
Originally posted by SimonMac View PostAnyone got a quick and dirty script they rely on to rebuild all the indexes in a database for SQL 2008 R2?
There is a few in google but would prefer one that comes for someone here
You are a braver man than me....
Leave a comment:
-
Paging All SQL Monkeys!
Anyone got a quick and dirty script they rely on to rebuild all the indexes in a database for SQL 2008 R2?
There is a few in google but would prefer one that comes for someone hereTags: None
- Home
- News & Features
- First Timers
- IR35 / S660 / BN66
- Employee Benefit Trusts
- Agency Workers Regulations
- MSC Legislation
- Limited Companies
- Dividends
- Umbrella Company
- VAT / Flat Rate VAT
- Job News & Guides
- Money News & Guides
- Guide to Contracts
- Successful Contracting
- Contracting Overseas
- Contractor Calculators
- MVL
- Contractor Expenses
Advertisers
Contractor Services
CUK News
- Reports of umbrella companies’ death are greatly exaggerated Nov 28 10:11
- A new hiring fraud hinges on a limited company, a passport and ‘Ade’ Nov 27 09:21
- Is an unpaid umbrella company required to pay contractors? Nov 26 09:28
- The truth of umbrella company regulation is being misconstrued Nov 25 09:23
- Labour’s plan to regulate umbrella companies: a closer look Nov 21 09:24
- When HMRC misses an FTT deadline but still wins another CJRS case Nov 20 09:20
- How 15% employer NICs will sting the umbrella company market Nov 19 09:16
- Contracting Awards 2024 hails 19 firms as best of the best Nov 18 09:13
- How to answer at interview, ‘What’s your greatest weakness?’ Nov 14 09:59
- Business Asset Disposal Relief changes in April 2025: Q&A Nov 13 09:37
Leave a comment: