In SQL Server, you can use the sysmail_delete_profile_sp
stored procedure to delete an existing Database Mail profile.
You can delete a profile by providing either its name or its ID (but you must provide either one or the other).
Example – Delete by Name
Here’s an example to demonstrate how to delete a profile by specifying its name.
EXECUTE msdb.dbo.sysmail_delete_profile_sp
@profile_name = 'DB Admin Profile';
Result:
Commands completed successfully.
This deleted the profile called “DB Admin Profile”.
The profile name is sysname with a default of NULL
.
Example – Delete by ID
As mentioned, you can alternatively provide the ID. To do this, change the @profile_name
argument to @profile_id
:
EXECUTE msdb.dbo.sysmail_delete_profile_sp
@profile_id = 1;
The profile ID is an int.
A Few Points
Deleting a profile does not delete the accounts used by the profile. You can delete accounts with the sysmail_delete_account_sp
stored procedure.
The sysmail_delete_profile_sp
procedure deletes the profile regardless of whether users have access to the profile.
Be careful when deleting default profiles. If there are no default profiles available when a user tries to send mail, the mail could fail (unless the user explicitly specifies a profile to use when sending the mail).
The sysmail_delete_account_sp
stored procedure is located in the msdb database and its owner is dbo. Therefore, you’ll need to provide three part naming if msdb isn’t the current database.