How to execute some script when database starts up
[Updated]


Create SQL Agent job for what you need. 
Use Server-scoped DDL trigger for that


Approximately like this:

Create TRIGGER ddl_trig_AlterDatabes
ON ALL SERVER 
FOR ALTER_DATABASE 
AS 
    -- your code here
    -- use EventData() to check database name if needed.. or other info..
    Exec msdb..sp_start_job @job_name = 'job_name'