Sql Server change fill factor value for all indexes by tsql

danielUrrero picture danielUrrero · May 14, 2013 · Viewed 15.8k times · Source

I have to expoet my DB into a bacpac file to import it into Azure. When I try to export I get an error because any indexes have a fillFactor value.

I've found how to set a fillFactor value for all indexes but I can't specify 0, the value have to be between 1 an 100. If I change the value in the management studio I can set it to 0.

The problem is that I have got lots of indexes to change and I would like to change the fillFactor value to all of them trough tsql.

Any ideas?.

Thanks.

Answer

Nick Kavadias picture Nick Kavadias · Apr 28, 2017

something simpler for all tables in a single database:

   select 'ALTER INDEX ALL ON ['
   + s.name+ '].['+ o.name+'] REBUILD WITH (FILLFACTOR = 99)' 
   from sys.objects o
   inner join sys.schemas s on o.schema_id = s.schema_id
   where type='u' and is_ms_shipped=0

generates statements you can then copy & execute.