MSSQL - Checking if a string contains only digits
Example of checking if a string contains only digits: SELECT * FROM my_table WHERE user_name NOT LIKE '%[^0-9]%';
Example of checking if a string contains only digits: SELECT * FROM my_table WHERE user_name NOT LIKE '%[^0-9]%';
Example of applying SPLIT_STRING for all rows in the set using one script. -- Creating a dataset for the example declare @tbl table(path varchar(max)); insert into @tbl select 'root_home_user' union select 'lib_var_simple' union select 'var_...
Example of returning a parameter when executing a dynamically created query. May be useful in cases where you need to return parameters for further processing in a script, for example, a procedure. We will use this for <b>sp_executesql</b>.
Table Hints Table Hints relate only to tables and views for which they are specified. These hints are intended to determine the locking method, specify a particular index, and the method of data processing in tables, for example, scanning or searching. Syntax: Arguments: With the keyword
To add a comment to a table field in MSSQL, use: To change a comment to a table field in MSSQL, use: To delete a comment to a table field in MSSQL, use:
Добавление описания к полю в таблице EXEC sp_addextendedproperty @name = N\'MS_Description\', @value = N\'Описание поля\', @level0type = N\'SCHEMA\', @level0name = N\'CRM\', -- Вместо \'dbo\' ставим название своей схемы если отличается @lev…
Examples of getting the query text by session identifier DECLARE @sqltext VARBINARY(128) SELECT @sqltext = sql_handle FROM sys.sysprocesses WHERE spid = (YourSessionID) SELECT TEXT FROM sys.dm_exec_sql_text(@sqltext) GO SELECT TEXT FROM sy…
Example of selecting fields from a temporary table with all parameters. Can be used for regular tables as well. #tmp - your temporary table
--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 =