Answering your questions one by one:
- Since I'm running a single delete command is causing the tempdb growth?
Could be. As you are running a huge DML operation, some data from
buffer cache is moved to tempdb for carrying out the operation and it
is causing the tempdb growth.
- Will the space consumed in tempdb get automatically cleared when the connection is closed?
No. the tempdb will not automatically shrink. When the database
service is restarted, tempdb is created fresh and will reset to its
original size.
Is there any way we can avoid this situation?
- You can go for small batches for UPDATE operation.
DECLARE @rowCount INT
SET @rowCount = (SELECT COUNT(*) FROM TableName WHERE ColumnName = 'Somevalue')
WHILE @rowCount <> 0
BEGIN
BEGIN TRANSACTION
UPDATE TableName
SET ColumnName = 'Newvalue'
WHERE PrimaryKeyId IN (select top 10000 PrimaryKeyId FROM TableName WHERE ColumnName = 'Somevalue');
COMMIT TRANSACTION;
SET @rowCount = (SELECT COUNT(*) FROM TableName WHERE ColumnName = 'Somevalue');
END
- Try to go for SELECT * INTO to another table and then rename the newly created table to current tableName
SELECT col1, updatedCol2
INTO new_tableName
FROM tablename;
sp_rename tablename, old_tablename
sp_rename new_tablename, tablename
There are more suggestions available in the Stackoverflow post
Also, Microsoft has some guidelines on tempdb performance improvement