1

Using SQL Server, I want to know if it is possible to have a function I wrote run at a certain time every day. It will just perform a very small int insert into a table.

I'm not to sure how to go about this and I know how to use SQL Server generally.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

Yes it is possible with sql job please follow this documentation for more info https://learn.microsoft.com/en-us/sql/ssms/agent/create-a-transact-sql-job-step?view=sql-server-2017

-- creates a job step that uses Transact-SQL  
USE msdb;  
GO  
EXEC sp_add_jobstep  
    @job_name = N'Weekly Sales Data Backup',  
    @step_name = N'Set database to read only',  
    @subsystem = N'TSQL',  
    @command = N'ALTER DATABASE SALES SET READ_ONLY',   
    @retry_attempts = 5,  
    @retry_interval = 5 ;  
GO  
umesh99
  • 215
  • 1
  • 11
  • Thanks! this has a lot of good information but now I am having another issue, I do not see the Agent in my Object Explorer. –  Dec 23 '18 at 15:05
  • 1
    @OverFlowMars, it seems you are using SQL Express edition, which [doesn't include SQL Server Agent](https://learn.microsoft.com/en-us/sql/sql-server/editions-and-components-of-sql-server-2017). You could instead schedule a task via Windows Task scheduler that runs a T-SQL script using the SQLCMD command-line utility. – Dan Guzman Dec 23 '18 at 15:11
  • Ask them to add your login to msdb database 'sqlagentuserrole' . To add a user as a member of the 'sqlagentuserrole' , you can execute the following command: use msdb EXECUTE sp_addrolemember@rolename = 'sqlagentuserrole' ,@membername = 'username' – umesh99 Dec 23 '18 at 15:11