Index: S.N O. Experiment Date Remark S T. Sign
Index: S.N O. Experiment Date Remark S T. Sign
Index: S.N O. Experiment Date Remark S T. Sign
We can also add and drop constraints of the table using the
ALTER command.
DROP:-
ALTER is a DDL command which changes or modifies the
existing structure of the database, and it also changes the
schema of database objects.
We can also add and drop constraints of the table using the
ALTER command.
TRUNCATE:- TRUNCATE is another DDL command which deletes
or removes all the records from the table.
EXPERIMENT :-2
AIM:- To apply integrity constraints on tables like PRIMARY
KEY,FOREIGN KEY,CHECK,NOT NULL,etc.
THEORY:-
NOT NULL:- This constraint specifies that the column cannot
have NULL or empty values.
The example above displays the name of all the customers who
have placed an order.
LEFT join: The LEFT JOIN keyword returns all records from the
left table (table1), and the matching records from the right table
(table2). The result is 0 records from the right side, if there is no
match.
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
The LEFT JOIN keyword returns all records from the left table
(Customer), even if there are no matches in the right table
(Orders).
RIGHT join: The RIGHT JOIN keyword returns all records from
the right table (table2), and the matching records from the left
table (table1). The result is 0 records from the left side, if there is
no match.
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;
The RIGHT JOIN keyword returns all records from the right table
(workers), even if there are no matches in the left table (orders).
FULL join: The FULL OUTER JOIN keyword returns all records
when there is a match in left (table1) or right (table2) table
records.
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name
WHERE condition;
EXPERIMENT 6
AIM: Write the queries to implement the sub queries.
Theory: A subquery is a SQL query nested inside a larger query.
• A subquery may occur in :
o - A SELECT clause
o - A FROM clause
o - A WHERE clause
• The subquery can be nested inside a SELECT, INSERT,
UPDATE, or DELETE statement or inside another subquery.
• A subquery is usually added within the WHERE Clause of
another SQL SELECT statement.
• You can use the comparison operators, such as >, <, or =.
The comparison operator can also be a multiple-row operator,
such as IN, ANY, or ALL.
• A subquery is also called an inner query or inner select, while
the statement containing a subquery is also called an outer
query or outer select.
• The inner query executes first before its parent query so that
the results of an inner query can be passed to the outer
query.
Syntax:
Q. How to find marks of student whose name is Anil and lives in
Delhi?
• The MINUS set operator compares the result sets from two
queries, but returns only the distinct rows in the result set of
the left query that are absent from the result set of the right
query.
• Only the UNION set operator supports the ALL keyword. The
ALL keyword is not valid with the INTERSECT, MINUS, or
EXCEPT set operators, from which only distinct rows are
returned.
• When comparing rows to calculate a set intersection or
difference, two NULL values are considered equal in
INTERSECT and MINUS operations.
UNION:
UNION ALL:
INTERSECT:
EXCEPT/MINUS:
EXPERIMENT 8
AIM: Write the queries to create the views and queries based on
views.
Theory:-
Views in SQL are kind of virtual tables. 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.
Creating a
view from a
single table.
Simple if statement
Demonstrations using IF control function:-
Demonstrations using CASE function:-
EXPERIMENT 10
AIM: Writ the queries to implement the concept of
correlated subqueries.
Theory:-
Correlated subqueries are used for row-by-row processing. Each
subquery is executed once for every row of the outer query.