Practical-1: AIM: Practical On Transaction Control Language. Theory
Practical-1: AIM: Practical On Transaction Control Language. Theory
DBMS File
PRACTICAL-1
COMMIT command:-
COMMIT command is used to permanently save any transaction into the database.
When we use any DML command like INSERT, UPDATE or DELETE, the changes made
by these commands are not permanent, until the current session is closed, the changes made
by these commands can be rolled back.
To avoid that, we use the COMMIT command to mark the changes as permanent. Following
is commit command's syntax,
Commit;
Himanshu Jain(01050118118)
DBMS File
ROLLBACK command:-
This command restores the database to last commited state. It is also used with
SAVEPOINT command to jump to a savepoint in an ongoing transaction.
If we have used the UPDATE command to make some changes into the database, and
realise that those changes were not required, then we can use
the ROLLBACK command to rollback those changes, if they were not commited using
the COMMIT command.
Following is rollback command's syntax
Rollback to savepoint name;
SAVEPOINT command:-
SAVEPOINT command is used to temporarily save a transaction so that you can rollback to that
point whenever required.
Following is savepoint command's syntax,
SAVEPOINT savepoint name;
Himanshu Jain(01050118118)
DBMS File
4. SET TRANSACTION:-
Syntax:
SET TRANSACTION [Read Write | Read Only];
PRACTICAL -2
System: This includes permissions for creating session, table, etc and all types of
Object: This includes permissions for any command or query to perform any
GRANT: Used to provide any user access privileges or other priviliges for the database.
REVOKE: Used to take back permissions from any user.
GRANT USAGE ON `employeedata`.* TO ‘Himanshu’@'localhost' WITH GRANT OPTION;
Himanshu Jain(01050118118)
DBMS File
Himanshu Jain(01050118118)
DBMS File
PRACTICAL- 3
AIM : Practical based on Natural Join.
SQL Join is used to fetch data from two or more tables, which is joined to appear as single
set of data. It is used for combining column from two or more tables by using values
common to both tables.
JOIN Keyword is used in SQL queries for joining two or more tables. Minimum required
condition for joining table, is (n-1) where n, is number of tables. A table can also join to
itself, which is known as, Self Join.
Types of JOIN
Following are the types of JOIN that we can use in SQL:
Inner
Outer
Left
Right
SELECT * FROM
Natural JOIN
Natural Join is a type of Inner join which is based on column having same name and same
datatype present in both the tables to be joined.
The syntax for Natural Join is,
Example of Natural JOIN:-
Here is the test table,
Himanshu Jain(01050118118)
DBMS File
In the above example, both the tables being joined have ID column(same name and same
datatype), hence the records for which value of ID matches in both the tables will be the result of
Natural Join of these two tables.
Himanshu Jain(01050118118)
DBMS File
PRACTICAL -4
ON table-name1.column-name = table-name2.column-name;
ON table-name1.column-name = table-name2.column-name;
ON table-name1.column-name = table-name2.column-name;
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 VIEWS
We can create View using CREATE VIEW statement. A View can be created from a single table
or multiple tables.
Syntax:
Examples:
Creating View from a single table:
In this example we will create a View named DetailsView from the table
StudentDetails.
Query:
CREATE VIEW DetailsView AS
SELECT FirstName, LastName
FROM Test
WHERE id < 5;
To see the data in the View, we can query the view in the same manner as we query a table.
Every PL/SQL statement ends with a semicolon (;). PL/SQL blocks can be nested within other
PL/SQL blocks using BEGIN and END. Following is the basic structure of a PL/SQL block −
DECLARE
<declarations section>
BEGIN
<executable command(s)>
EXCEPTION
<exception handling>
END;
Example:-
DECLARE
message varchar2(20):= 'Hello, World!';
BEGIN
dbms_output.put_line(message);
END;
Practical-7
Aim:- Implement PL/SQL program using control structure.
FOR Loop:-
A FOR LOOP is a repetition control structure that allows you to efficiently
write a loop that needs to execute a specific number of times.
Syntax;-
FOR counter IN initial_value .. final_value LOOP
sequence_of_statements;
END LOOP;
Following is the flow of control in a For Loop −
The initial step is executed first, and only once. This step allows you to declare and
initialize any loop control variables.
Next, the condition, i.e., initial_value .. final_value is evaluated. If it is TRUE, the body of
the loop is executed. If it is FALSE, the body of the loop does not execute and the flow of
control jumps to the next statement just after the for loop.
After the body of the for loop executes, the value of the counter variable is increased or
decreased.
The condition is now evaluated again. If it is TRUE, the loop executes and the process
repeats itself (body of loop, then increment step, and then again condition). After the
condition becomes FALSE, the FOR-LOOP terminates.
Example:-
Case Statement:-
CASE Syntax:-
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
WHEN conditionN THEN resultN
ELSE result
END;
Example:-
GOTO Statement:-
The SQL GOTO statement is used to alter the flow of a program. When the
execution reaches the GOTO statement, it will jump unconditionally to the label specified in the
goto statement.
Syntax:-
--List of Statements
GOTO label
........
........
label:
statements
Example:-
IF-THEN Statement:-
IF ( condition ) THEN
statement
END IF;
Example:-