Constraints enable the RDBMS to enforce the integrity of the database automatically, without the need to create triggers, rule or defaults.
Types of Constraints: NOT NULL, CHEQUE, UNIQUE, PRIMARY KEY, FOREIGN KEY.
Write SQL Query to find second highest salary of Employee.
There are many ways to find second highest salary of Employee in SQL, you can either use SQL Join or Subquery to solve this problem. Here is SQL query using Subquery :
SELECT MAX(Salary) from Employee WHERE Salary NOT IN (select MAX(Salary) FROM Employee );
Write an SQL Query find number of employees according to gender whose DOB is between 01/01/1960 to 31/12/1975.
SELECT COUNT(*), sex from Employees WHERE DOB BETWEEN ‘01/01/1960 ' AND ‘31/12/1975’ GROUP BY sex;
find all Employee records containing the word "Joe", regardless of whether it was stored as JOE, Joe, or joe.
SELECT * from Employees WHERE upper(EmpName) like upper('joe%');
Write a SQL Query to find year from date.
SELECT YEAR(GETDATE()) as "Year";
Write an SQL Query to check whether date passed to Query is date of given format or not.
SQL has IsDate() function which is used to check passed value is date or not of specified format ,it returns 1(true) or 0(false) accordingly.
SELECT ISDATE('1/08/13') AS "MM/DD/YY";
It will return 0 because passed date is not in correct format.