Posts

When we add a column with default constraint will the Ct version changes or not

use prism /* Creating a table*/ Create table dbo.Prismtest ( Id int primary key identity(1,1), [Name] Varchar(10)) alter table dbo.Prismtest add [Address2] varchar(100) default('abc') not null  select * from dbo.prismtest insert into dbo.Prismtest ([Name]) values ('def' )  select ct.* FROM changetable(changes dbo.Prismtest,1 ) as ct  LEFT JOIN dbo.Prismtest a on a.id=ct.id  -- 54067710    /Checking the data in CT table*/ select change_tracking_Current_version()  -- 54067711  /* Here check the CT version is getting changed or not  -- Important */  Alter table dbo.Prismtest Enable change_tracking WITH (TRACK_COLUMNS_UPDATED = OFF);

To Check the permissions of the service accounts

Select P.name As Principal, class_desc As PermissionLevel, permission_name As PermissionGranted, ObjectName = Case class When 0 Then DB_NAME() When 1 Then OBJECT_SCHEMA_NAME(major_id) + N'.' + OBJECT_NAME(major_id) End From sys.database_permissions As DP Inner Join sys.database_principals As P On P.principal_id = DP.grantee_principal_id Where permission_name In ('insert', 'update', 'delete', 'control', 'alter') And state = 'G'; -- Grant

Count and Unique identifier value

---------------  Count in the table --------------- select count(1) from table sp_spaceused '[audit].ChangeRequestSecurityVulnerabilityHistory' ----------------- Inserting the data in the column of unique identifier ---------- [Guid] [uniqueidentifier] NOT NULL --- insert the data in Unique identifier NEWID ( )

Executing the function with the table type and parameter

use prism DECLARE @Variable AS audit.ChangeRequestActivityQueueType  INSERT INTO @Variable([ChangeRequestId],[Guid],[Timestamp],[ChangeRequestHistoryTransactionId],[CommentHistoryId])  VALUES(12345,NEWID ( ),'2-21-2020',12345,12345)  SELECT * from  [audit].[GetChangeRequestSecurityUpdateActivities](@StudentVariable)  

T-SQL Script to find High CPU Queries

SELECT TOP 50 Convert(varchar, qs.creation_time, 109) as Plan_Compiled_On, qs.execution_count as ' Total Executions ', qs.total_worker_time as ' Overall CPU Time Since Compiled ', Convert(Varchar, qs.last_execution_time, 109) as ' Last Execution Date / Time ', cast(qs.last_worker_time as varchar) +'    ( '+ cast(qs.max_worker_time as Varchar)+' Highest ever ) ' as ' CPU Time for Last Execution ( Milliseconds ) ', Convert(varchar,(qs.last_worker_time/(1000))/(60*60)) + ' Hrs ( i . e . ' + convert(varchar,(qs.last_worker_time/(1000))/60) + ' Mins & ' + convert(varchar,(qs.last_worker_time/(1000))%60) + ' Seconds ) ' as ' Last Execution Duration ', qs.last_rows as ' Rows returned ', qs.total_logical_reads/128 as ' Overall Logical Reads ( MB ) ', qs.max_logical_reads/128 ' Highest Logical Reads ( MB ) ', qs.last_logical_reads/128 ' Logi...

sql-server-full-text-search-contains-function

select top 2 * from dbo.OrbitSearchCacheLongTexts where fieldid=22  SELECT * FROM dbo.OrbitSearchCacheLongTexts WHERE CONTAINS(IndexedWords,'"*12345*"') and fieldid=22 SELECT * FROM dbo.OrbitSearchCacheLongTexts where IndexedWords like '%12345%' and fieldid=22

Removing special characters of a string using function

alter Function [dbo].[RemoveNonAlphaCharacters](@Temp VarChar(1000))  Returns VarChar(1000)  AS  Begin        Declare @KeepValues as varchar(50)      Set @KeepValues = '%[^0-9a-zA-Z @\.\-]%'      While PatIndex(@KeepValues, @Temp) > 0          Set @Temp = Stuff(@Temp, PatIndex(@KeepValues, @Temp), 1, '')        Return @Temp  End ================================================================= use ods ;with CR AS( select issue_id,  stringvalue from ssistemp.jirastage.JiraDroidBugIssueCustomfieldvalue  where custom_field_id = 10686 ) select CC=dbo.RemoveNonAlphaCharacters(CASE WHEN (CR.Stringvalue LIKE 'http://prism.qualcomm.com/CR/%'                   or CR.Stringvalue  LIKE 'https://orbit/CR/%' ) then replace(replace(CR.Stringvalue,'http://prism.qualcomm.com/CR/',''),'https://...