DBMS Lab Manual
DBMS Lab Manual
LAB MANUAL
NAME:
YEAR/SEM/BRANCH:
ROLL NUMBER:
1
MEC / IT / DATABASE MANAGEMENT SYSTEMS LABORATORY
Institution Vision and Mission
Vision
Mission
To prepare the students with high professional skills and ethical values
To impart knowledge through best practices
To instil a spirit of innovation through Training, Research and Development
To undertake continuous assessment and remedial measures
To achieve academic excellence through intellectual, emotional and social stimulation
Vision
Mission
M1: Equip the students with high quality education and carrying out research in emerging
technologies in Information Technology
M2: Expose the students, faculty and staff to a globally competitive learning experience
M3: Motivate the students to realize the responsibility of being professionally proficient
information technocrats to serve the society by inculcating Ethical and Environmental
aspects.
2
MEC / IT / DATABASE MANAGEMENT SYSTEMS LABORATORY
Program Educational Objectives (PEOs):
PEO1: Graduates will have successful career in IT and related industries or pursue higher
education and research or evolve as entrepreneurs.
PEO2: Graduates will have the ability and attitude to adapt emerging technological
changes in Information Technology.
PEO3: Graduates will excel as socially committed engineers with high ethical values,
leadership qualities and empathy for the needs of society.
PO2 Problem Analysis: Identify, formulate, review research literature, and analyze
complex engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
PO5 Modern Tool Usage: Create, select, and apply appropriate techniques, resources,
and modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.
PO6 The Engineer and Society: Apply reasoning informed by the contextual
knowledge to assess societal, health, safety, legal and cultural issues and the consequent
3
MEC / IT / DATABASE MANAGEMENT SYSTEMS LABORATORY
responsibilities relevant to the professional engineering practice.
PO8 Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.
PO9 Individual and Team work: Function effectively as an individual, and as a member
or leader in diverse teams, and in multidisciplinary settings.
PO12 Lifelong Learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological
change.
PSO2: Apply appreciable knowledge of IoT, Cloud Computing and Cyber Security to develop
reliable IT solutions.
PSO3: Exhibit proficiency in Artificial Intelligence and Big Data Analytics for providing
solutions to real world problems in Industry and Research establishments
4
MEC / IT / DATABASE MANAGEMENT SYSTEMS LABORATORY
Do’s and Dont’s in the Laboratory:
DO’s
Know the location of the fire extinguisher and the first aid box and how to use them in
case of an emergency.
Read and understand how to carry out an activity thoroughly before coming to the
laboratory.
Shut down your computer, when you leave from the laboratory.
DON’Ts
Do not insert metal objects such as clips, pins and needles into the computer casings.
Do not touch, connect or disconnect any plug or cable without your lecturer/laboratory
technician’s permission.
5
MEC / IT / DATABASE MANAGEMENT SYSTEMS LABORATORY
LIST OF PROGRAMS
6
MEC / IT / DATABASE MANAGEMENT SYSTEMS LABORATORY
Index
AIM:
OBJECTIVES
THEORY
● ALTER – The structure of a table can be modified by using the ALTER TABLE command.
This command is used to add a new column, modify the existing column definition and to
include or drop integrity constraint.
● DROP - It will delete the table structure provided the table should be empty.
PROCEDURE
CREATION OF TABLE:
SYNTAX:
EXAMPLE:
EXAMPLE:
ALTER TABLE Employee ADD (phone_no char (20));
Syntax:
EXAMPLE:
Alter table Employee add(salary number(7), age Number(5));
Syntax:
EXAMPLE:
Syntax:
EXAMPLE:
Syntax:
Rename <oldtable> to <new table>;
EXAMPLE:
rename Employee to Employee1;
Syntax:
Example:
DESTROYING TABLES
Syntax:
DROP TABLE <TABLE NAME>;
Example:
DROP TABLE Employee;
RESULT:
AIM:
To execute the Data Manipulation Language (DML) commands and DCL statements in RDBMS.
OBJECTIVES
THEORY
DML commands are the most frequently used SQL commands and is used to query and
manipulate the existing database objects. Some of the commands are
1. INSERT
This is used to add one or more rows to a table. The values are separated by commas and the
data types char and date are enclosed in apostrophes. The values must be entered in the same
order as they are defined.
2. SELECT
It is used to retrieve information from the table.it is generally referred to as querying the table.
We can either display all columns in a table or only specify column from the table.
3. UPDATE
It is used to alter the column values in a table. A single column may be updated or more than
one column could be updated.
4. DELETE
After inserting row in a table we can also delete them if required. The delete command consists
of a from clause followed by an optional where clause
PROCEDURE
INSERT COMMAND
(a) Inserting a single row into a table:
Syntax:
insert into <table name> values (<expression1>,<expression2>)
Example:
(b) Inserting more than one record using a single insert commands:
Syntax:
insert into <table name> values (&col1, &col2, ….)
Example:
SQL> INSERT INTO EMPLOYEE
VALUES(&EMPNO,'&ENAME','&DESIGNATIN'&SALARY');
Example :
SELECT COMMAND
Syntax:
Example:
Syntax:
Select<column1>,<column2>fromtablename;
Example:
Syntax:
Example:
Syntax:
Example:
UPDATE COMMAND
(a) updating all rows
Syntax:
Example:
Example:
DELETE COMMAND
Example:
delete from Employee where empno=101;
Example:
Delete from Employee;
OBJECTIVES
THEORY:
Data Control Language (DCL) consists of various commands which are related to data
sharing and security of data in database.
They are
GRANT
REVOKE
Granting Privileges:
Objects that are created by a user are owned and controlled by that user. If user wishes to
access any of the objects belonging to another user, the owner of the object will have to
give permissions for such access. This is called Granting of Privileges.
Granting privileges using the GRANT statements:
The GRANT statements provide various types of access to database objects such as
tables, views.
Syntax:
GRANT {object privileges} ON
object name
TO username;
Object Privileges:
RESULT:
The DML commands are executed successfully and Familiarized DCL statements.
THEORY:
Constraints are the Rules which are enforced on the data being stored in a table
Syntax:
Syntax:
Example:
CREATE TABLE example_table (
employee_id INT,
department_id INT,
employee_name VARCHAR(50),
PRIMARY KEY (employee_id, department_id)
);
);
Example :
ON DELETE CASCADE is set then DELETE operation in master table will trigger the
DELETE operation for corresponding records in the detail table.
Syntax:
A CONSTRAINT can be given User Defined Name, the syntax is: CONSTRAINT < constraint
name><constraint definition>
Example code :
Example :
Example :
DEFAULT Constraint
);
Example :
THEORY:
SQL View
A view in SQL is a logical subset of data from one or more tables. View is used to restrict data access.
Syntax of displaying a view is similar to fetching data from table using Select statement.
Syntax:
SELECT * from view_name;
Types of View
There are two types of view,
Simple View
Complex View
Example :
Insert into sam (empno,ename) values(110,'mec');
Example :
UPDATE STATEMENT:
A view can be updated under certain conditions:
The SELECT clause may not contain the keyword DISTINCT.
The SELECT clause may not contain summary functions.
The SELECT clause may not contain set functions.
The SELECT clause may not contain set operators.
The SELECT clause may not contain an ORDER BY
clause. The FROM clause may not contain multiple tables.
The WHERE clause may not contain subqueries.
The query may not contain GROUP BY or
HAVING. Calculated columns may not be updated.
All NOT NULL columns from the base table must be included in the view in
order for the INSERT query to function.
DROP A VIEW:
Obviously, where you have a view, you need a way to drop the view if it is no longer needed.
SYNTAX:
SQL> DROP VIEW <VIEW_NAME>
Example :
UPDATE STATEMENT:
CREATE or REPLACE force view sam AS SELECT empNO,Ename FROM Employee;
UPDATE sam set empno = 105 WHERE ename = 'MANU';
select * from sam;
select * from employee;
A nested query is a query that appears inside another query, and it helps retrieve data from
multiple tables or apply conditions based on the results of another query.
Q1: Display all employee names and salary whose salary is greater than minimum salary of
the company and job title starts with A.
2. Use like operator to match job and in select clause to get the result.
Ans: SQL>
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
employee_name VARCHAR(255),
salary DECIMAL(10, 2),
job_title VARCHAR(100)
);
FROM employees
WHERE salary > (SELECT MIN(salary) FROM employees)
AND job_title LIKE 'A%';
Doe:
SQL>
JOIN QUERIES:
A JOIN clause is used to combine rows from two or more tables, based on a related column between
them.
SYNTAX:
SELECT table1.column1,table1.column2,table2.column1,....
FROM table1
INNER JOIN table2
ON table1.matching_column = table2.matching_column;
Example:
Result:
Thus views, nested queries and join queries were implemented Successfully.
THEORY:
PLSQL stands for "Procedural Language extensions to SQL", and can be used in
Oracle databases. PLSQL is closely integrated into the SQL language, yet it adds
programming constructs that are not native to SQL.
Advantages of PL/SQL
1. PL/SQL supports not only SQL data manipulation but also provides facilities of
conditional checking, branching and looping.
2. PL/SQL sends an entire block of statements to the Oracle engine at one time.
3. PL/SQL permits dealing with errors and displaying user friendly messages when
the error occurs.
4. Via PL/SQL all sorts of calculations can be done quickly without the use of
Oracle Engine
5. Applications written in PL/SQL are portable to any computer hardware and
operating system where Oracle is operational.
The different sections of PL/SQL block are as follows:
DECLARE SECTION
Declarations of memory variables, constants, cursors etc in PL/SQL
BEGIN
SQL executable statements
PL/SQL executable statements
EXCEPTION
SQL or PL/SQL code to handle errors that may arise during the execution of the
code blockStudy of PL/SQL block
In addition to SQL commands, PL/SQL can also process data using flow of statements. The
flow of control statements are classified into the following categories.
• Conditional control -Branching
• Iterative control - looping
• Sequential control
BRANCHING in PL/SQL:
Sequence of statements can be executed on satisfying certain condition .
If statements are being used and different forms of if are:
1.Simple IF
2.ELSIF
3. ELSE IF
EXAMPLE :
DECLARE
day_of_week VARCHAR2(10) := 'Monday';
statement VARCHAR2(50);
BEGIN
CASE day_of_week
WHEN 'Monday' THEN
statement := 'It''s the start of the week.';
WHEN 'Wednesday' THEN
statement := 'Halfway through the week!';
WHEN 'Friday' THEN
statement := 'TGIF! It''s Friday!';
ELSE
statement := 'It''s a regular day.';
END CASE;
DBMS_OUTPUT.PUT_LINE(statement);
END;
EXAMPLE :
DECLARE
grade CHAR(1);
marks NUMBER := 85;
BEGIN
grade :=
CASE
WHEN marks >= 90 THEN 'A'
WHEN marks >= 80 THEN 'B'
WHEN marks >= 70 THEN 'C'
WHEN marks >= 60 THEN 'D'
ELSE 'F'
END;
SIMPLE LOOP
Syntax:
LOOP
statement1;
EXIT [ WHEN Condition];
END LOOP;
EXAMPLE :
DECLARE
counter NUMBER := 1;
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE('Iteration ' || counter);
counter := counter + 1;
EXIT WHEN counter > 5;
END LOOP;
END;
FOR LOOP
Syntax:
FOR counter IN [REVERSE]
LowerBound..UpperBound
LOOP
statement1;
statement2;
END LOOP;
EXAMPLE :
DECLARE
loop_counter NUMBER;
BEGIN
FOR loop_counter IN 1..5
LOOP
DBMS_OUTPUT.PUT_LINE('Number: ' || loop_counter);
END LOOP;
END;
AIM:
To Implement Procedures
THEORY:
Procedure is a subprogram used to perform a specific action. A subprogram is a
named block of PL/SQL. There are two types of subprograms in PL/SQL namely Procedures
and Functions. Every subprogram will have a declarative part, an executable part or body,
and an exception handling part, which is optional. Declarative part contains variable
declarations. Body of a subprogram contains executable statements of SQL and PL/SQL.
Statements to handle exceptions are written in exception part.
Procedure specification begins with CREATE and ends with procedure name or
parameters list. Procedures that do not take parameters are written without a parenthesis. The
body of the procedure starts after the keyword IS or AS and ends with keyword END.
A procedure may be passed multiple parameters. IN | OUT | IN OUT specifies the mode of
the parameter. Type specifies the datatype of the parameter.
IN - The parameter can be referenced by the procedure or function. The value of the
parameter cannot be overwritten by the procedure or function.
OUT - The parameter cannot be referenced by the procedure or function, but the value of the
parameter can be overwritten by the procedure or function.
Procedure body contains the SQL and PL/SQL statements to perform the procedure's task.
Exception Section:
The Exception section of a PL/SQL Block starts with the reserved keyword
EXCPTION. This section is optional. Any errors in the program can be handled in this
section, so that the PL/SQL Blocks terminates gracefully. If the PL/SQL Block contains
exceptions that cannot be handled, the Block terminates abruptly with errors.
Advantages:
When client executes a procedure or a function, the processing is done in the server.
Server is likely to me more powerful than the clients which in turn mean that stored procedures
should run faster. This reduces network traffic.
As the procedures/functions are stored in the Oracle database there is no need to transfer
the code from the clients to the database server or to transfer intermediate results from the
server to the clients. This results in much less network traffic and again improves scalability
The subprograms are compiled and stored in the Oracle database as stored programs
and can be invoked whenever required. As they are stored in compiled form when called,
they only need to be executed. Hence they save time needed for compilation. They allow
breaking the program into manageable modules. They provide reusability and maintainability
for the code.
Disadvantages:
There is an overhead involved in embedding or calling PL/SQL procedures from SQL
in Oracle due to the context switching that the Oracle database has to perform. This may be
significant in terms of performance but usually this overhead is outweighed by performance
advantages of using PL/SQL.
More memory may be required on the Oracle database server when using Oracle
PL/SQL packages as the whole package is loaded into memory as soon as any object in the
package is accessed
101 Nithya
102 Maya
IMPLEMENTATION OF FUNCTIONS
THEORY :
24
IMPLEMENTATION OF TRIGGERES
Aim :
To implement of triggers
IF (:new.m1 >= 50 AND :new.m2 >= 50 AND :new.m3 >= 50) THEN
:new.result := 'pass';
ELSE
MEC / IT / DATABASE MANAGEMENT SYSTEMS LABORATORY 48
:new.result := 'Fail';
END IF;
END;
/
1 row created.
SQL>
ERROR at line 1:
ORA-20998: INVALID
ERROR ORA-06512: at
"SCOTT.T2", line 2
AIM:
To design and implement banking System
STEPS:
1. Create the DB for banking system source request the using SQL
2.Establishing ODBC connection
3. Click add button and select oracle in ORA home 90 click finished
window will appear give the data source name as oracle and give the user id as scott
5.Now click the test connection a window will appear with server and user name give user
as scott and password tiger Click ok.
6.Visual Basic Application:-
Create Standard exe project in to and design ms from in request format.
To add ADODC Project Select Component and check ms ADO data control click ok.
Now the Control is added in the tool book.
Create Standard exe project in to.
7.ADODC CONTEOL FOR ACCOUNT FROM:- Click customs and property window and
window will appear and select ODBC data source name as oracle and click apply as the some
window
52
MEC / IT / DATABASE MANAGEMENT SYSTEMS LABORATORY
TRANSACTION_Click()
Form3.Show
End Sub
SOURCE CODE FOR FORM 2
Private Sub CLEAR_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
Private Sub
DELETE_Click()
Adodc1.Recordset.DELETE MsgBox "record deleted"
Adodc1.Recordset.MoveNext If Adodc1.Recordset.EOF = True Then
Adodc1.Recordset.MovePrevious
End If
End Sub
Private Sub EXIT_Click()
Unload Me
End Sub
Private Sub
HOME_Click()
Form1.Show
End Sub
Private Sub
INSERT_Click() Adodc1.Recordset.AddNew
End Sub
Private Sub
TRANSACTION_Click()
Form3.Show
End Sub
Private Sub UPDATE_Click() Adodc1.Recordset.UPDATE MsgBox "record updated
successfully"
End Sub
SOURCE CODE FOR FORM 3
Private Sub ACCOUNT_Click()
Form2.Show
End Sub
Private Sub CLEAR_Click()
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub
DEPOSIT_Click()
53
MEC / IT / DATABASE MANAGEMENT SYSTEMS LABORATORY
Dim s As String s = InputBox("enter the amount to be deposited")
Text2.Text = Val(Text2.Text) + Val(s) A = Text2.Text MsgBox "CURRENT BALANCE IS
Rs" + Str(A) Adodc1.Recordset.Save Adodc1.Recordset.UPDATE
Sub Private
Sub
EXIT_Click()
Unload Me End
Sub Private
Sub
HOME_Click()
Form1.Show End
Sub Private Sub
WITHDRAW_Click()
Dim s As String s = InputBox("enter the amount to be deleted")
Text2.Text = Val(Text2.Text) - Val(s) A = Text2.Text MsgBox "current balance is Rs" +
Str(A)
Adodc1.Recordset.Save
Adodc1.Recordset.UPDATE
End Sub
OUTPUT:
54
MEC / IT / DATABASE MANAGEMENT SYSTEMS LABORATORY
Result:
Thus the banking system was designed and implemented successfully.
55
MEC / IT / DATABASE MANAGEMENT SYSTEMS LABORATORY
EXPERIMENT NO: 10
AIM:
To design and implement Student Information System.
STEPS:
4. Click add button and select oracle in ORA home 90, click finish
5. A window will appear given the data source home as oracle and select TNS source name as
lion and give the used id as SWTT
7. The above procedure must be follow except the table , A select the table as library
8. Write appropriate Program in form each from created in VB from each from created in VB
form project.
i. ADMINISTRATOR Table
This table holds the profile information of the application super users otherwise
known as system administrators. They have control of the software meaning that they can
perform additional tasks that other users cannot ordinarily perform. Every software of this
nature has such users and this one is no exception. The table contains the following
columns; ADMIN_ID, TITLE, FRIST_NAME, LAST_NAME, and DEPARMENT_ID.
The column ADMIN_ID is the primary key column (primary key disallows duplicate values
and nulls in a column) every table should have a primary key column, as this acts like table
indexing.
ii.ALL_COURSE Table
This table keeps the courses offered by students in different departments in the school. The
table contains the following columns; COURSE_ID, COURSE_TITLE, and COURSE_CODE.
The COURSE_ID is the primary key column.
iv.APP_USER_L Table
This table contains application login details for application lecturers. The table columns are;
USRNAME, PASSWD and LECTURER_ID. The column LECTURER_ID is the primary
key column.
v.APP_USER_S Table
This table contains application login details for application students.
The table columns are;
USRNAME, PASSWD and MATRIG_NO. The column MATRIG_NO is the primary key
column.
vi.DEPARTMENTS Table
This table holds information about the schools departments. The table contains the following
columns; DEPARTMENT_ID and DEPARTMENT_NAME. The column DEPARTMENT_ID is
the primary key column.
vii.GRADES Table
This is more like the main table in the database as all other tables relate to this table
directly or in some other way. This table holds students examination records. The table
contains the following columns;
GRADES_ID, SESSION1, REG_NUMBER, DEPARTMENT_ID, LEVEL1,
MATRIG_NO,FRIST_NAME,LAST_NAME,COURSE_CODE,GRADE,CREDIT_UNIT,
SCORE, LECTURER_ID and GRADE_POINT. The column GRADES_ID is the primary
key column.
viii.LECTURERS Table
This table holds the profile information of the application lecturers. The table contains the
following columns; LECTURER_ID, TITLE, FRIST_NAME, LAST_NAME, and
DEPARMENT_ID. The column LECTUTER_ID is the primary key column.
REG_TABLE Table
ix.
This table contains student‟s registration details i.e. if a student is registered for the
semester this table is used to store that information. The table contains the following
columns; REG_ID, REG_NUMBER, MATRIG_NO, FRIST_NAME,LAST_NAME,
LEVEL1, DEPARTMENT_ID and SESSION1. The column REG_ID is the primary key
column.
x. STUDENTS Table
This table holds the profile information of the application students. The table contains the
following columns; MATRIG_NO, TITLE, FRIST_NAME, LAST_NAME, and
57
MEC / IT / DATABASE MANAGEMENT SYSTEMS LABORATORY
DEPARMENT_ID. The column MATRIG_NO is the primary key column.
RESULT:
Thus the student information system was designed and implemented successfully.
58
MEC / IT / DATABASE MANAGEMENT SYSTEMS LABORATORY
EXPERIMENT NO: 11
AIM:
STEPS:
Create a database for payroll processing which request the using SQL
Establish ODBC connection
In the administrator tools open data source ODBC
Click add button and select oracle in ORA home 90, click finish
A window will appear given the data source home as oracle and select TNS source name as
lion and give the used id as SWTT
ADODC CONTROL FOR SALARY FORM:-
The above procedure must be follow except the table , A select the table as salary
Write appropriate Program in form each from created in VB from each from created in VB
form project.
59
MEC / IT / DATABASE MANAGEMENT SYSTEMS LABORATORY
PROGRAM FOR FORM 1
60
MEC / IT / DATABASE MANAGEMENT SYSTEMS LABORATORY
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = "" End
Sub
Private Sub delte_Click()
Adodc1.Recordset.Delete MsgBox "Record Deleted"
If Adodc1.Recordset.EOF = True
Then Adodc1.Recordset.MovePrevious
End If
End Sub
Private Sub exit_Click()
Unload Me
End Sub
Private Sub main_Click() Form1.Show
End Sub
Private Sub
modify_Click()
Adodc1.Recordset.Update
End Sub
OUTPUT:
61
MEC / IT / DATABASE MANAGEMENT SYSTEMS LABORATORY
RESULT:
Thus payroll system was designed and implemented successfully.
62
MEC / IT / DATABASE MANAGEMENT SYSTEMS LABORATORY