Forum Replies Created

Viewing post 1 (of 1 total)

  • RE: Trigger to add user to db_owner role after db restore

    You could try:

    CREATE TRIGGER [dbo].[PostDBRestore]

    ON [msdb].[dbo].[restorehistory]

    FOR INSERT

    AS

    SET NOCOUNT ON

    DECLARE @DBName AS VARCHAR(256)

    DECLARE @User AS VARCHAR(256)

    SELECT @DBName = destination_database_name

    , @User = user_name

    FROM INSERTED

    IF @DBName = 'YourDB' ....

    SET NOCOUNT OFF

Viewing post 1 (of 1 total)