Professional Documents
Culture Documents
The LIKE operator is used to match text string patterns. In terms of syntax structure, it fits into a boolean
expression just as an equals sign normally would.
The BETWEEN operator in SQL is used to select values within a given range.
IN operator allows to easily test if the expression matches any value in the list of values. It is used to remove
the need for multiple OR conditions in SELECT, INSERT, UPDATE or DELETE. NOT IN is used to
exclude the rows in your list. Any kind of duplicate entry will be retained.
Syntax:
SELECT column_name(s)
FROM table_name
WHERE column_name IN (list_of_values);
ORDER BY:
- The ORDER BY clause sorts the result-set in ascending or descending order.
- It sorts the records in ascending order by default. DESC keyword is used to sort the records in descending order.
HAVING:
- The HAVING clause is used to specify a search condition for a group or an aggregate.
- Having is used in a GROUP BY clause. If you are not using a GROUP BY clause then you can use the HAVING
function like a WHERE clause.
INNER JOIN:
In SQL, INNER JOIN selects records that have matching values in both tables as long as the condition is satisfied. It returns the
combination of all rows from both the tables where the condition satisfies.
Syntax:
FROM table1
ON table1.matching_column = table2.matching_column;
OUTER JOIN:
We use the SQL OUTER JOIN to match rows between tables. We might want to get match rows along with unmatched rows as well
from one or both of the tables. We have the following three types of SQL OUTER JOINS:
Syntax:
OR
NATURAL JOIN:
Natural Join joins two tables based on the same attribute name and datatypes. The resulting table will contain all the attributes of
both the table but keep only one copy of each common column.
Syntax:
SELECT *
EQUI JOIN:
An equijoin is an operation that combines multiple tables based on equality or matching column values in the associated tables.
Syntax:
SELECT (column_list | *)
FROM table_name1
JOIN table_name2
ON table_name1.column_name = table_name2.column_name;
Inner Join
Outer Join
Natural Join
Equi Join
Experiment 10 - Introduction of VIEW. How to create VIEW. Explain with an example.
A VIEW in SQL Server is like a virtual table that contains data from one or multiple tables. It does not hold
any data and does not exist physically in the database. Similar to a SQL table, the view name should be unique
in a database. A view also has rows and columns as they are in a real table in the database.
We can create a view by selecting fields from one or more tables present in the database. A View can either
have all the rows of a table or specific rows based on certain condition.
It contains a set of predefined SQL queries to fetch data from the database. It can contain database tables from
single or multiple databases as well.
A VIEW does not require any storage in a database because it does not exist physically. In a VIEW, we can
also control user security for accessing the data from the database tables. We can allow users to get the data
from the VIEW, and the user does not require permission for each table or column to fetch data.
Syntax:
CREATE VIEW view_name AS
SELECT column1, column2.....
FROM table_name
WHERE condition;