--generate disable deactivation SELECT 'exec msdb..sp_update_job @job_name = ''+NAME+'', @enabled = 0' FROM msdb..sysjobs --generate enable activation SELECT 'exec msdb..sp_update_job @job_name = ''+NAME+'', @enabled = 1'
Stopping Database Mail exec msdb.dbo.sysmail_stop_sp Cleaning the history of undelivered messages -- If the number of records in the msdb.sysmail_allitems table is very large, -- then use the @sent_before parameter to limit the deleted records exec msdb.dbo.sysmail_delete_mailitems_sp @sent_status =
Converting DATE or DATETIME to INT (format YYYYMMDD) declare @dt datetime set @dt = '\09-22-2007 15:07:38.850\' select cast(convert(char(8),@dt,112) as int) Converting INT (format YYYYMMDD) to DATE declare @dti int = 20071022; select cast(@dti as datetime)
Example of date trimming to minutes and hours: declare @dt datetime set @dt = '09-22-2007 15:07:38.850' select dateadd(mi, datediff(mi, 0, @dt), 0) select dateadd(hour, datediff(hour, 0, @dt), 0)
How to add data to a table with a Primary Key (when you need to ignore this primary key) SET IDENTITY_INSERT tableA ON -- Now you can make a list of fields with Primary Key and add records like: INSERT Into tableA ([id], [c2], [c3], [c4], [c…
Example of rounding date to hour and minute declare @dt datetime set @dt = '09-22-2007 15:07:38.850' select dateadd(mi, datediff(mi, 0, @dt), 0) select dateadd(hour, datediff(hour, 0, @dt), 0)
Below is an example of correctly canceling a transaction with an error: update Params set Value=168 where Param = 'SessionHoursLimit' PRINT @@TRANCOUNT BEGIN TRY BEGIN TRAN PRINT @@TRANCOUNT update Params set Value=167 where Param = 'SessionHours…
The log cleanup process should be done regularly, and a professional administrator should be responsible for it. However, it may happen that on your small development project for testing, logs unexpectedly exceed the set size and the following problem arises:
Simple MERGE example for TSQL. The example assumes that we are working with two tables of the same structure (in real life, this condition is not necessary). The TargetTable and SourceTable tables consist of only two fields: Id - some identifier. Name - object name.
By default, the length of a string in MSSQL Manager queries is limited, and when the string size is large enough, only its part will be retrieved in the query, but there is a way to bypass this issue. To select a long string, it is enough to simply assign the name to the field with the name [XML_F52E2B61-18A1-11d1-B105-00805F49916B].