Below is the script to add free space in datafile or logfile. You just need to pass database name, datafile name, log file name, space to add, and total space.
------------------>>>>>>>>>>>>>>>>>>>>>>>>>>>>
declare @databaes varchar(100), @datafile varchar(250), @Current_size int, @SpaceBunch int, @sql varchar(500)
declare @TotalSpaceToAdd int
set @databaes='TESTDB' -->> Pass Database name here
set @datafile= 'TESTDB_Log_2' -->> Pass Logical Name of data/log file
set @SpaceBunch=20 -->> It will add THIS much of space of chunck
set @TotalSpaceToAdd=100 -->> It will add space till THIS much, and will starts from current size+@SpaceBunch
select @Current_size=size/128 from sys.master_files where db_name(database_id)=@databaes and name=@datafile
print 'Space Before Addition ' + convert(varchar,@Current_size/1024) -->> It will print current size in GB
while @Current_size/1024 <@TotalSpaceToAdd
begin
set @sql='ALTER DATABASE [' + @databaes + '] MODIFY FILE ( NAME = N''' + @datafile + ''''+ ', SIZE = ' + convert(varchar,@Current_size+ @SpaceBunch*1024) + 'MB )'
print @sql
exec(@sql)
select @Current_size=size/128 from sys.master_files where db_name(database_id)=@databaes and name=@datafile
print 'Space After Addition ' + convert(varchar,@Current_size/1024) -->> It will print new current size in GB after space addition
end
------------------>>>>>>>>>>>>>>>>>>>>>>>>>>>>