January 2, 2019 at 2:44 pm
Hello,
I am trying to make change in the existing SQL auditing for all user databases.
How can I loop through each DB to run this script?
Begin
EXEC sp_MSforeachdb 'USE ?
IF EXISTS (SELECT * FROM sys.database_audit_specifications WHERE name = N''DatabaseAuditSpecification'')
BEGIN
ALTER DATABASE AUDIT SPECIFICATION DatabaseAuditSpecification WITH (STATE = OFF)
DROP DATABASE AUDIT SPECIFICATION DatabaseAuditSpecification
END
CREATE DATABASE AUDIT SPECIFICATION [DatabaseAuditSpecification]
FOR SERVER AUDIT [Audit]
ADD (DATABASE_CHANGE_GROUP),
ADD (EXECUTE ON DATABASE::DBName BY [public])
WITH (STATE = ON)'
END
Thank you.
January 2, 2019 at 4:47 pm
Use another question mark?
As a bit of an important sidebar, there's no way on this good Green Earth that I'd ever grant EXECUTE for an entire database to the PUBLIC role regardless of intended use.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 4, 2019 at 10:02 pm
This was removed by the editor as SPAM
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply