Creating Trigger in SQL Server Table

SQL Trigger
Trigger is a action which will perform when the table gets insert, update or delete. We can choose the options on what the trigger should get invoked and create the syntax as below

CREATE Trigger triggername
ON tblname
FOR INSERT,UPDATE,DELETE -- We can add or remove the criteria here
AS
BEGIN

-- Action steps needs to carried out should be given here.

END

Creating Trigger in SQL Server Table was last modified: November 15th, 2017 by Justin Antony

Insert value on an identity column of a SQL Server table

Insert value identity column SQL Server table

SET IDENTITY_INSERT dbo.Sampletable ON
Insert into dbo.Sampletable(a,b,c) values (1,2,3)  --> Here a is the identity column but values can be inserted after turning the Identity_insert ON. 
SET IDENTITY_INSERT dbo.Sampletable OFF

 

Insert value on an identity column of a SQL Server table was last modified: October 1st, 2017 by Justin Antony

Find position of a string in SQL Server

The char index function will return the position of the string. It will always return the first position and its occurrence based on the start position we mention

select charindex('s','jesus',0)
select charindex('s','jesus',4)

 

The first select will return 3 starting position is 0

The second select will return 5. It will ignore first occurrence since starting position is 4.

Find position of a string in SQL Server was last modified: October 1st, 2017 by Justin Antony

Track User activity on a Sql Server

Track User Activity

Track the User activity on a SQL machine by using the following command and you can check theType of Command the user used

  1. The Login Time and the When the last batch got executed
  2. From which program the server got invoked
  3.  CPU and Memory using
  4. DB Usage
select * from master.dbo.sysprocesses where nt_username = 'Author'

 

Track User activity on a Sql Server was last modified: October 1st, 2017 by Justin Antony

SQL error details

SQL ERROR Tracking

SQL Error can be tracked by using the following keywords. This will fetch the information at run time on the event of any error occurs.

ERROR_SEVERITY()
ERROR_STATE()
ERROR_MESSAGE()
ERROR_NUMBER()

 

SQL error details was last modified: October 1st, 2017 by Justin Antony