Instagram
youtube
Facebook
Twitter

MS SQL Server NOT Operator

MS SQL Server NOT Operator

  • NOT operator is used to negotiate a condition in SELECT, INSERT, UPDATE or DELETE.
  • Syntax:
NOT condition

Example:

  • NOT Operator with IS NULL condition
SELECT * FROM [University].[dbo].[student] WHERE Name IS NOT NULL;   
Id Name Branch CGPA
EN19CS301254 Ravi CSE 9.34
EN19CS301246 Savi CSE 8.23
EN19CS301248 Aayush CSE 7.25
EN19CS301258 Kavi NULL NULL
  • NOT Operator with LIKE condition
SELECT * FROM [University].[dbo].[Student] WHERE name NOT LIKE 'S%';
Id Name Branch CGPA
EN19CS301254 Ravi CSE 9.34
EN19CS301248 Aayush CSE 7.25
EN19CS301258 Kavi NULL NULL
  • NOT Operator with BETWEEN condition
SELECT * FROM [University].[dbo].[student] WHERE Age NOT BETWEEN 16 AND 18; 
Id Name Branch CGPA Age
EN19CS301254 Ravi CSE 9.86 19 
EN19CS301248 Aayush CSE 7.25 20
EN19CS301258 Kavi CSE 7.50 19
  • NOT Operator with EXISTS condition
SELECT * FROM [University].[dbo].[student] WHERE NOT EXISTS (SELECT * FROM[University].[dbo].[Staff] WHERE Student.Branch = Staff.Branch);