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]%';
18 posts
Example of checking if a string contains only digits: SELECT * FROM my_table WHERE user_name NOT LIKE '%[^0-9]%';
Добавление описания к полю в таблице 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…
--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'
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…
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.
This query returns a set of table fields with all characteristics. The method is also applicable and works great with views VIEW. SELECT ORDINAL_POSITION ,COLUMN_NAME ,DATA_TYPE ,CHARACTER_MAXIMUM_LENGTH ,IS_NULLABLE ,COLUMN_DEFAULT…
Adding Records to a Table Ignoring IDENTITY: -- Enable SET IDENTITY_INSERT tableA ON -- You must specify the full list of columns for INSERT: INSERT Into tableA ([id], [c2], [c3], [c4], [c5] ) SELECT [id], [c2], [c3], [c4], [c5] FROM tableB...
A useful example of changing the encoding (COLLATION) on an already created database. In this example, the Russian encoding is set: Cyrillic_General_CI_AS USE master; GO -- Switching the DB to single-user mode ALTER DATABASE [database_name] SET…
Example of creating a SEQUENCE in MSSQL: CREATE SEQUENCE [dbo].[CardNum] AS [bigint] START WITH 1 INCREMENT BY 1 MINVALUE -9223372036854775808 MAXVALUE 9223372036854775807 CACHE GO This script will create a SEQUENCE…