create ms sql server job schedule from datetime database - sql

I'm using microsoft SQL server management studio 2005
I'm trying to run a job at a specific time and that time is stored in a database.
I can't insert the schedule manually because it is up to the user to decide what date and time the job(s) has to be done. php collects the time and date and sends it to a database.
I thought about runing a job every min and in my execution I have an if statement that only activates when the datetime stored in the database is one minute greater or lower than the current datetime. but doing it like this would be inaccurate and very inefficient. would it be possible to create a schedule directly from a query or job?

You can create and modify both jobs and schedules programmatically using SMO or TSQL. That means you can use an external application, a stored procedure or a trigger to create or update a job schedule based on the table data. SMO is probably the best way to go if you want to build an application to manage jobs, but on the other hand it's .NET only.

Related

Last run date of a view and triggers

Is it possible to find the run date of view and triggers in SQL Server? We have a script for procedures but not views and triggers. We need this to create a report of the last run date of the objects in the production.
This can also be achieved by using a server side trace
https://www.sqlservercentral.com/blogs/setting-up-a-server-side-trace

How to calculate the next run date for a SQL Server agent job

I am developing a custom system for scheduling task & I am following Microsoft SQL Server Agent approach to schedule task.
I have replicated sysschedules table for capturing users scheduling occurrences and timings.
Now I need to know how SQL Server get the Next_run_date and time from this table.
I have found a solution on the internet which are using sysjobhistory table to get the next run date, but in my case, I have an only sysschedules table. So, what is the formula to calculate the next_run_date and time for any job?
Note: I am looking for entire code, concept/algorithm will work for me.

View the waiting/suspended queries between a time period in the past

I am trying to optimize an SQL process using the dmv ([sys].[dm_os_wait_stats]).
Is there any way that we can see the waiting/suspended queries between a time period in the past?. Like want to have records only from 3pm today.
Currently I clean the instance every time before running the process using
DBCC SQLPERF ('sys.dm_os_wait_stats', CLEAR);
GO
I suggest that using monitoring tools such as Idera or Redgate monitor in order to monitor sql server waiting. You can also copy ([sys].[dm_os_wait_stats]) data in other table periodically.

MS sql command automatically run when server activity

I have a MS SQL database storing information of members. I wish every day automatic test data today is the birthday of members, then sends congratulatory letter.
So I will use what command? Store Procedure or triger or something else ...? And how to use?
You can you the SQL Server Agent service to schedule a job that executes a procedure that finds the correct members and Database Mail to send the mail. The links provided should have the information you need.

Delete column in SQL Server after a period from creation

I am working with sensitive/private files stored in SQL Server as VarBinary(MAX). Is there a way to tell the database or nHibernate to nullify the column after a period of time after its creation.
Make sure to put a timestamp column on the table, then set up a SQL Scheduled Job with a query to delete those rows periodically based on that time.
Absolutely not
Imagine the fun when SQL Server decides to change data apparently on it's own because the code monkey fluffed setting up whatever mechanism would be used...
You could (off top of my head):
Encrypt the columns
Schedule a clean up (SQL Agent job, a config table)
Don't use SQL Server for the files themselves, just store paths/links