Sql-server – How to check which users have been created by specific stored procedure in sql server

sql server

I have created a stored procedure, which creates different username and password.But i have condition that for next time when stored procedure is called, it should delete previous user created by same stored procedure.And we are not supposed to store user details in table.
So could anyone can suggest me how to know those users which are created by only this stored procedure?
Thanks.

Best Answer

You can't without storing something uniquely identifying, particularly if (when) users/logins are dropped and recreated by other processes than the stored procedure.

Perhaps you could store just the principal_id and create_date from sys.server_principals, and the same from sys.database_principals; nothing identifying in particular, but the pair together should be a good indication that these are the right rows.