Download Information System Design Laboratory Laboratory Manual Third Year - Information Technology

Document related concepts

Tandem Computers wikipedia , lookup

DBase wikipedia , lookup

Oracle Database wikipedia , lookup

Microsoft Access wikipedia , lookup

Database wikipedia , lookup

Relational algebra wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Ingres (database) wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Clusterpoint wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Join (SQL) wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Database model wikipedia , lookup

Relational model wikipedia , lookup

SQL wikipedia , lookup

PL/SQL wikipedia , lookup

Transcript
Laboratory Manual
Information System Design Laboratory
Third Year - Information Technology
Teaching Scheme
Examination Scheme
Theory : 01 Hrs/Week
Term Work: 25 Marks
Practical : 04 Hrs/Week/Batch
Practical :
——
Oral : 50 Marks
Prepared By
Prof.Patil Pradeep M.
Prof.Shah Sahil K.
Department of Information Technology
Vidya Pratishthan’s College of Engineering
Baramati – 413133, Dist- Pune (M.S.)
INDIA
JUNE 2013
Table of Contents
1 Assignment for Reference
1.1 Problem Statement . . . . . . . . . .
1.2 Pre Lab . . . . . . . . . . . . . . . .
1.3 Hardware and Software Requirement
1.4 Theory . . . . . . . . . . . . . . . . .
1.4.1 Visual Basic:Quick Overview
1.4.2 Visual Basic Environment . .
1.5 Post Lab . . . . . . . . . . . . . . . .
1.6 Viva Questions . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
2 Assignment for Reference:Creating first
2.1 Problem Statement . . . . . . . . . . . .
2.2 Pre Lab . . . . . . . . . . . . . . . . . .
2.3 Theory . . . . . . . . . . . . . . . . . . .
2.3.1 Creating Your First Application
2.3.2 Important Controls in VB.NET
2.3.3 Creating variables in VB.NET .
2.4 Post Lab . . . . . . . . . . . . . . . . . .
2.5 Viva Questions . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1
1
1
1
1
1
2
4
4
VB.NET Application
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
5
5
5
5
5
6
8
9
10
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
3 Assignment on GUI Design:Simple Calculator
3.1 Problem Statement . . . . . . . . . . . . . . . .
3.2 Pre Lab . . . . . . . . . . . . . . . . . . . . . .
3.3 Theory . . . . . . . . . . . . . . . . . . . . . . .
3.4 Steps to create a simple calculator application .
3.5 Post Lab . . . . . . . . . . . . . . . . . . . . . .
3.6 Viva Questions . . . . . . . . . . . . . . . . . .
Application
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
11
11
11
11
12
13
13
4 Assignment on GUI Design:Usage of MDI
4.1 Problem Statement . . . . . . . . . . . . . .
4.2 Pre Lab . . . . . . . . . . . . . . . . . . . .
4.3 Theory . . . . . . . . . . . . . . . . . . . . .
4.3.1 Introduction to MDI . . . . . . . . .
4.3.2 Characteristics of MDI Application .
4.3.3 MDIChild Property . . . . . . . . .
4.3.4 Steps to design a MDI application .
4.3.5 Steps For creating a Menu . . . . . .
4.4 Post Lab . . . . . . . . . . . . . . . . . . . .
4.5 Viva Questions . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
14
14
14
14
14
15
15
15
15
16
16
i
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
TABLE OF CONTENTS
TABLE OF CONTENTS
5 ER/EER Diagram
5.1 Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.2 Pre Lab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.3 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.3.1 Basic concepts of ER Diagram: Various types of attributes,Relationship sets, Mapping cardinalities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.3.2 Symbolic Notations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.3.3 Enhanced ER-diagram(EERD): . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.3.4 Conversion of ER diagram to tables . . . . . . . . . . . . . . . . . . . . . . . . .
5.4 Post Lab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.5 Viva Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17
17
17
17
6 Creation of database tables from ER Diagrams using SQL
6.1 Problem Statement . . . . . . . . . . . . . . . . . . . . . . . .
6.2 Pre Lab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.3 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.3.1 Introduction to SQL: . . . . . . . . . . . . . . . . . . .
6.3.2 DATA DEFINITION LANGUAGE(DDL) . . . . . . .
6.3.3 DATA INTEGRITY . . . . . . . . . . . . . . . . . . .
6.3.4 SELECT Command . . . . . . . . . . . . . . . . . . .
6.4 Post Lab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.5 Viva Questions . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
23
23
23
23
23
24
25
28
29
29
7 Assignment on DML Commands
7.1 Problem Statement . . . . . . . . . . . . . . . . . . . . .
7.2 Pre Lab . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.3 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.3.1 DATA MANIPULATION LANGUAGE (DML):
7.4 Post Lab . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.5 Viva Questions . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
30
30
30
30
30
32
32
8 Study and implementation of SQL queries using Joins
8.1 Problem Statement . . . . . . . . . . . . . . . . . . . . .
8.2 Pre Lab . . . . . . . . . . . . . . . . . . . . . . . . . . .
8.3 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8.3.1 Introduction to database Joins . . . . . . . . . .
8.3.2 Types of Joins . . . . . . . . . . . . . . . . . . .
8.4 Post Lab . . . . . . . . . . . . . . . . . . . . . . . . . . .
8.5 Viva Questions . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
33
33
33
33
33
35
37
38
clauses
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
39
39
39
39
40
41
41
42
43
43
44
44
9 Study and implementation of SQL queries operators
9.1 Problem Statement . . . . . . . . . . . . . . . . . . . .
9.2 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.2.1 LIKE CONDITION : . . . . . . . . . . . . . .
9.2.2 IN CONDITION : . . . . . . . . . . . . . . . .
9.2.3 BETWEEN CONDITION : . . . . . . . . . . .
9.2.4 EXISTS CONDITION : . . . . . . . . . . . . .
9.2.5 GROUP BY CLAUSE: . . . . . . . . . . . . .
9.2.6 HAVING CLAUSE : . . . . . . . . . . . . . . .
9.2.7 ORDER BY CLAUSE: . . . . . . . . . . . . .
9.3 Post Lab . . . . . . . . . . . . . . . . . . . . . . . . . .
9.4 Viva Questions . . . . . . . . . . . . . . . . . . . . . .
ii
and
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
17
18
19
20
21
21
TABLE OF CONTENTS
TABLE OF CONTENTS
10 Creation and Execution of simple programs in PL/SQL (Procedures and Functions)
10.1 Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.2 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.2.1 PL/SQL (Procedural Language/Structured Query Language) . . . . . . . . . . .
10.2.2 FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.2.3 PROCEDURES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.3 Post Lab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.4 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.5 Viva Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
45
45
45
45
46
47
47
47
48
11 Creation and Execution of Triggers
11.1 Problem Statement . . . . . . . . .
11.2 Theory . . . . . . . . . . . . . . . .
11.2.1 PL/SQL Cursors Types : .
11.2.2 Triggers . . . . . . . . . . .
11.3 Post Lab . . . . . . . . . . . . . . .
11.4 Viva Questions . . . . . . . . . . .
.
.
.
.
.
.
49
49
49
49
51
52
52
12 Implementation of Mini Project/application.
12.1 Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12.2 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
53
53
53
References
55
and
. . .
. . .
. . .
. . .
. . .
. . .
Cursors in
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
iii
PL/SQL
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
List of Figures
2.1
Creation of Variables in VB.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8
3.1
Layout of Calculator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12
4.1
Layout of MDI Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
16
5.1
5.2
5.3
ER Diagram Notations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ER Diagram:Sample Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Reduction of ER Diagram to tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
19
20
21
6.1
Enforcing Integrity Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
26
8.1
8.2
8.3
8.4
8.5
8.6
Employee table .
Orders table . . .
Resulting table of
Resulting table of
Resulting table of
Resulting table of
34
34
35
36
36
37
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
JOIN operation . . . . . . . . . .
INNER JOIN operation . . . . . .
LEFT OUTER JOIN operation .
RIGHT OUTER JOIN operation
iv
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Assignment 1
Assignment for Reference
1.1
Problem Statement
To be aware of the front end tool VB.NET
1.2
Pre Lab
• Refer introduction from book VB.NET wrox publication
• Refer introduction from book VB.NET black book
1.3
Hardware and Software Requirement
• System with minimum 1GB RAM
• Microsoft .NET Framework
• Microsoft Visual Studio
1.4
1.4.1
Theory
Visual Basic:Quick Overview
VISUAL BASIC is a high level programming language which evolved from the earlier DOS version called
BASIC. BASIC means Beginners’ All Purpose Symbolic Instruction Code. It is a very easy programming
language to learn. VISUAL BASIC is a VISUAL and events driven Programming Language. These are
1
1.4. THEORY
Assignment for Reference
the main divergence from the old BASIC. In BASIC, programming is done in a text-only environment
and the program is executed sequentially.
Features of Visual Programming
• Offers a set of the predefined graphical objects.
• Event driven programming i.e. the code segments can be associated with the events like click,
double click etc.
• Provides a wide set of the predefined functions and classes.
• Responds to the mouse and the keyboard events.
• Sequential and the Random file access.
• Interaction with the database.
• Supports modular programming(Procedures & Functions)
• Supports Object Oriented Programming
Advantages of Visual Programming
• User can develop the Applications in minimum time.
• The applications developed are user friendly.
• Applications are simple, powerful.
• Maintenance (Applying Changes), Debugging (Tracing & eliminating the errors) of the application
is easier.
1.4.2
Visual Basic Environment
• Integrated Development Environment(IDE)
To start Visual Studio,follow the sequence as
Start→Programs→Microsoft Visual Studio2005→Microsoft Visual Basic
The New Project dialog box displayed from which select the project type as Standard Exe, It will
display the Integrated Development Environment of VB,which include Menu Bar, Context Menu
or Pop-up Menu, Toolbar, Project Explorer Window, Control Toolbox, Properties window, Code
editor window,Form Designer, Code Editor Window, Form Layout Window.
Lab Manual - ISDL
2Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
1.4. THEORY
Assignment for Reference
• Menu Bar
Set of options available in Visual Basic grouped as File, Edit, View and so on.The menu options
are displayed when the user click on the individual menu. The underlined alphabet in the menu
name indicates the shortcut of the menu. E.g. the File menu options can be displayed either by
a mouse click on it or using combination Alt + F.
• Context Menu OR Pop-up Menu
The context or the Pop Up Menu is displayed when the user Right Click on the certain object.
The context menu can be used to quickly perform the desired actions without accessing the Menu
options or using the toolbar. E.g. When the user right click on the form a context menu id
displayed with the options like cut,copy, paste etc.
• Toolbar
It is displayed just below the Menu Bar in the Visual Basic Environment. It displays a sequence
of buttons. The options available in the toolbar are available in the menus. It might be time
consuming to access the menu items, instead of that the tool bar buttons can be clicked in less
time to perform the desired operation. E.g. To save a file using a menu the steps may be to open
the options in the FILE menu and select the SAVE option, instead of that the user can easily click
on the save button on the Standard toolbar.
• Project Explorer Window
It offers the list of all the elements of the project. A project is the collection of the files you use
to build an application. User can refer the individual items in the VB Environment project using
the Project Explorer Window. By default it is displayed on the Right hand of the form.
• Toolbox
It provides a set of standard tools that you can use at design time to place controls on a form.
Controls can be added to the toolbox with the components option from the project menu.
• Properties window
List of the property settings for the selected form or control either in an alphabetic or categorized
order. The window is divided in two columns, the left column displays the property names while
the right column displays the default property values. The user can set the property values at the
Design Time using properties window.
• Form Designer
It serves as container to hold/place controls, graphics, and pictures. It works as a window for
designing the interface of application to create the look which wants.The list of all the form
designers is displayed in the Project Explorer Window.
Lab Manual - ISDL
3Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
1.5. POST LAB
Assignment for Reference
• Code Editor Window
It is a window where code is to be written, it is highly specialized word processor with a number
of features that make writing Visual Basic code a lot easier. To move to the code editor window
click on the View code tool in Project Explorer Window.
• Form Layout Window
It gives a Visual idea of the position of the form in relation to screen.
1.5
Post Lab
This assignment is just for reference and is only meant for basic understanding of VB .NET environment.
1.6
Viva Questions
1. What is difference between VB and other programming language?
2. What is the advantage of VB over C or C++?
3. Why VB is called object oriented programming language?
4. What are the different objects in VB?
5. What are the different Windows in VB Environment?
Lab Manual - ISDL
4Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
Assignment 2
Assignment for Reference:Creating
first VB.NET Application
2.1
Problem Statement
To develop first application in VB.NET and to understand various features associated with different
controls in VB.NET.
2.2
Pre Lab
• Concept of VB.NET Environment
• Basic Understanding of Visual Studio IDE
2.3
2.3.1
Theory
Creating Your First Application
Steps to create a new project in VB.NET:• On the File menu, click New Project to display the Create Project dialog box.
• In the New Project dialog box, select the type of project.(Standard Exe)
• Click OK.
Executing the project
There are several ways to execute a project.
5
2.3. THEORY
Assignment for Reference:Creating first VB.NET Application
• Click Run from the menu bar → Select Start.
OR
• Press F5 key from the keyboard.
OR
• Click on the Start button from the tool bar.
As soon as the project is executed, the form set as the start up object is displayed.
How an event driven application works.
Event is an action recognized by a form or control. Event-driven applications execute Basic code in
response to an event. Each form & control in VB has a predefined set of events. If one of these
events occurs & there is code in the associated event procedure, VB invokes that code. Objects in VB
automatically recognize a predefined set of events. A section of code-an event procedure corresponds
to each event. The types of events recognized by an object vary, but many types are common to most
controls.
Sequence of events in an event driven application:
• The application starts & a form is loaded and displayed.
• The form receives an event.
• If there is code in the corresponding event procedure, it executes.
• The application waits for the next event.
2.3.2
Important Controls in VB.NET
1. Text box control
It is the standard control for accepting input from the user as well as to display the output. It can
handle string (text) and numeric data but not images or pictures.The text property of the text
box can be used to access the contents of the text box control. It can be used to enter the single
line text or the multi line text into it. The user can edit, select, cut or copy the contents of the
text box.
2. Command button
The command button is one of the most important controls as it is used to execute commands. It
displays an illusion that the button is pressed when the user click on it. The most common event
associated with the command button is the Click event, and the syntax for the procedure is as
follows
Lab Manual - ISDL
6Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
2.3. THEORY
Assignment for Reference:Creating first VB.NET Application
Private Sub Command1click()
Statements
End Sub
3. Labels
The label is a very useful control for Visual Basic, as it is not only used to provide instructions
and guides to the users, it can also be used to display outputs.
4. Check Box
The Check Box control lets the user selects or unselects an option. When the Check Box is checked,
its value is set to 1 and when it is unchecked, the value is set to 0. You can include the statements
Check1.Value=1 to mark the Check Box and Check1.Value=0 to unmark the Check Box, as well
as use them to initiate certain actions.
5. Combo Box
The function of the Combo Box is also to present a list of items where the user can click and select
the items from the list. However, the user needs to click on the small arrowhead on the right of
the combo box to see the items which are presented in a drop-down list. In order to add items to
the list, you can also use the AddItem method.
6. Option Button
The Option Box control also lets the user selects one of the choices. However,two or more Option
Boxes must work together because as one of the Option Boxes is selected, the other Option Boxes
will be unselected. In fact, only one Option Box can be selected at one time. When an option box
is selected, its value is set to True and when it is unselected; its value is set to False.
7. List Box
The function of the List Box is to present a list of items where the user can click and select the
items from the list. In order to add items to the list, we can use the AddItem method.
The items in the list box can be identified by the ListIndex property, the value of the ListIndex
for the first item is 0, the second item has a ListIndex 1, and the second item has a ListIndex 2
and so on.
8. Scrollbar Control
A Scrollbar Control is a VB control containing a thumb. We can move the scrollbar by dragging
it, clicking the mouse to either side of the scrollbar , or using the keyboard. It is used to select a
discrete value or a set of consecutive values in a range.
There are 2 types of scrollbars:
Horizontal and vertical scrollbar i.e. HScroll and VScroll
Lab Manual - ISDL
7Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
2.3. THEORY
2.3.3
Assignment for Reference:Creating first VB.NET Application
Creating variables in VB.NET
Variable is a storage area of the computer’s memory.
Simple Example:
Figure 2.1: Creation of Variables in VB.NET
A breakdown of the variable Declaration:
Dim
Short for dimension. It’s a type of variable. You declare (or ”tell” Visual Basic) that you are setting up
a variable with this word.
number1
This is a variable. After the Dim word, Visual Basic is looking for the name of your variable.
As Integer
We’re telling Visual Basic that the variable is going to be a number (integer).
One can declare a variable using the Dim, Private, Public, or Static keyword.
The scope rules are simple as follows:
• Use of Dim inside a procedure to declare a local (dynamic) variable, which is visible only inside
that procedure.
• Use of Dim or Private outside procedure blocks,but inside a Class or Module block to create
variables that can be accessed from anywhere inside that class or module but not from elsewhere
in the project.
• Use of Public inside a Module block to create global variables.that is, variables that exist for the
entire programfor lifetime and that can be accessed from anywhere in the current project(i.e.from
one form to the other within entire project/application)
• Use Public inside a Class block to create a public field for that class.
• Use the Static keyword to declare static variables inside a procedure.
The following piece of code demonstrates the five types of variables:
Lab Manual - ISDL
8Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
2.4. POST LAB
Assignment for Reference:Creating first VB.NET Application
Module MyModule
’This global variable is visible to the entire application.
Public myGlobalVar As String
’These variables are visible only inside the current module.
Private myModuleVar As String
Dim myModuleVar2 As String
Sub MyProcedure()
’This private variable is visible only inside this procedure.
Dim myPrivateVar As String
’This static variable maintains its value between consecutive calls to this procedure.
Static counter As Integer
.
.
End Sub
End Module
2.4
Post Lab
This assignment is just for reference and is only meant for basic understanding of VB .NET controls
and their use with simple examples.You should be able to develop following applications in VB.NET
1. A simple application that makes use of labels, Text box and command button controls.
2. A simple application that makes use of Check box ,option buttons controls.
3. A simple application that makes use of List box, combo box controls.
Lab Manual - ISDL
9Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
2.5. VIVA QUESTIONS
2.5
Assignment for Reference:Creating first VB.NET Application
Viva Questions
1. What is a event? What are the different forms Event?
2. What are the different controls used in VB?
3. What is difference between Option button and check box?
4. What is difference between combo box and list box?
5. What are the different properties of command button?
6. What is difference between text box and rich text box?
7. What are the different types of scrollbar control?
Lab Manual - ISDL
10
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
Assignment 3
Assignment on GUI Design:Simple
Calculator Application
3.1
Problem Statement
Implement a simple calculator using VB.NET
3.2
Pre Lab
• Controls used in VB.NET
• Basic knowledge about programming in VB.NET
3.3
Theory
Develop a simple calculator application by making use of following controls in VB.NET
• TextBox
• Command Button
Following operations must be supported in developed application
• Arithmetic operations like Addition,Subtraction etc.
• Finding Square root and square of a number.
• Finding SIN,COS,TAN of entered number.
11
3.4. STEPS TO CREATE A SIMPLE CALCULATOR
Assignment APPLICATION
on GUI Design:Simple Calculator Application
Design your GUI as shown in following figure:
Figure 3.1: Layout of Calculator
3.4
Steps to create a simple calculator application
1. Open VB Environment (Click the ”Start” button. Choose the ”All Programs” menu item. Choose
the ”Microsoft Visual Basic 2005/2008” menu item.).
2. Select Standard EXE and press open button.
3. By default,Form1 will get loaded.
4. Add the controls like textbox and command buttons from toolbox to the Form1.
5. Change the text and name property of each and every control added.
6. Group all the buttons using proper alignment.
7. Switch to code view of Form1 and write the code for click event of each command button.
Lab Manual - ISDL
12
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
3.5. POST LAB
Assignment on GUI Design:Simple Calculator Application
Sample Code for Square root of a number:
Private Sub btnsqrt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnsqrt.Click
TextBox1.Text = Sqrt(TextBox1.Text)
End Sub
3.5
Post Lab
After completing this assignment,discuss different controls used in this assignment and discuss the
properties associated with each control in detail.
3.6
Viva Questions
1. How to display the value in text box.
2. What event of command button we use to accept the number form user.
3. How to accept number 12 from user (Give the logic).
Lab Manual - ISDL
13
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
Assignment 4
Assignment on GUI Design:Usage of
MDI
4.1
Problem Statement
Develop an application in VB.NET that makes use of MDI (Multiple Document Interface) form for
creating a menu and connecting other form.
4.2
Pre Lab
• Concept of Properties related with different controls in VB.NET
4.3
4.3.1
Theory
Introduction to MDI
MDI (Multiple Document Interface) Application is an application in which one can view and work with
several documents at once.
Example of an MDI application is Microsoft Excel. Excel allows us to work with several documents or
sheets at once.
In contrast, SDI (Single Document Interface) applications are the applications which allow us to work
with a single document at once.
Example of a single document application is Microsoft Word in which only one document is visible at a
time.
14
4.3. THEORY
4.3.2
Assignment on GUI Design:Usage of MDI
Characteristics of MDI Application
• There can be only one MDI form in the application.
• There can be as many child forms as user want.
• All the child forms can be displayed only within the MDI forms workspace.
• When the child form is minimized its icon appears on the MDI form instead of on the taskbar.
• The form control like label, text box cannot be placed on the MDI form except the picture box
control.
• Menus can be created on the MDI form.
4.3.3
MDIChild Property
To set the newly added form to the project as the child form, set the MDIChild Property of the form
to true.
4.3.4
Steps to design a MDI application
• Step 1:-Open VB Environment (Click the ”Start” button. Choose the ”All Programs” menu item.
Choose the ”Microsoft Visual Basic 2008 Express Edition” menu item.).
• Step 2:-Select Standard EXE and press open button.
• Step 3:-Go to project Explorer, Right Click on form1, ADD MDIForm.
• Step 4:-Open MDIForm
• Step 5:-In the same way Add Form2
• Step 6:-Open Form properties by Right clicking on form1.
• Step 7:-Open Form properties by Right clicking on form1, change MDIChild property True. Same
for Form2.
• Step 8 :-Open Form2 properties by Right clicking on form2,change MDIChild property True.
4.3.5
Steps For creating a Menu
• Step 1:- Open MDIForm
• Step 2:-Open Menu Editor
Lab Manual - ISDL
15
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
4.4. POST LAB
Assignment on GUI Design:Usage of MDI
• Step 3:-Give the Caption Menu editor and any name.
• Step 4:-Open MDI Menu press on form1 open menu, and Write a code as shown below.
Private sub F1 click()
Form1.show
End sub
• Step 5:- Same for Frorm2 open Menu
Sample layout of MDI Application is as shown in figure:
Figure 4.1: Layout of MDI Application
4.4
Post Lab
After completing this assignment,discuss different controls used in this assignment and discuss the
properties associated with each control in detail.Check the use of menustrip and how it can be used for
different applications.
4.5
Viva Questions
1. MDI stands for?
2. What is difference between MDI Form and Normal Form(SDI)?
3. What is the use of MDI Form?
4. What are the different characteristics of MDI Form?
5. How to make child form for MDI form?
Lab Manual - ISDL
16
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
Assignment 5
ER/EER Diagram
5.1
Problem Statement
Design and draw an ER/EER diagram using standard notations for service industry(like Hospital,
Airline, hotel, insurance, health case etc) and map this diagram into Database Tables.
5.2
Pre Lab
• Concept of Relation
• Concept of Relational model and algebra
5.3
5.3.1
Theory
Basic concepts of ER Diagram: Various types of attributes,Relationship
sets, Mapping cardinalities.
A database can be modeled as a collection of entities and relationship among Entities:
Entity: It is an object that exists and is distinguishable from other objects. Example: specific person,
company, event, plant
Entity set: An entity set is a set of entities of the same type that share the same properties. Example:
set of all persons, companies, trees, holidays etc.
Attributes: Entities have properties which are known as attributes.
Example: People have names and addresses Attributes can be of following types:
17
5.3. THEORY
ER/EER Diagram
1. Simple: eg. Roll no
2. Composite attributes:. eg Name,Address
3. Single-valued: Roll No
4. Multi-valued attributes: eg. Phone-numbers
5. Derived attributes: Can be computed from other attributes
E.g. Age, Given date of birth.
Relationship: A relationship is an association among several entities
Example: Glass is a part of Window.
Here,one can see ‘IS-A’ kind of relationship.
Mapping Cardinalities
Express the number of entities to which another entity can be associated via a relationship set. Most
useful in describing binary relationship sets. For a binary relationship set the mapping cardinality must
be one of the following types:
1. One to one
2. One to many
3. Many to one
4. Many to many
5.3.2
Symbolic Notations
Components to draw entity relationship diagram
Rectangles: represent entity sets.
Diamonds: represent relationship sets.
Lines: link attributes to entity sets and entity sets to relationship sets.
Ellipses: represent attributes
Double ellipses: represent multi valued attributes.
Dashed ellipses: denote derived attributes.
Underline: indicates primary key attributes.
Sample Notations are as shown in following figure.
Lab Manual - ISDL
18
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
5.3. THEORY
ER/EER Diagram
Figure 5.1: ER Diagram Notations
5.3.3
Enhanced ER-diagram(EERD):
• Includes all modeling concepts of basic ER
• Additional concepts: subclasses/superclasses, specialization/generalization, categories, attribute
inheritance
• The resulting model is called the enhanced-ER or Extended ER (E2R or EER) model
• It is used to model applications more completely and accurately if needed
• It includes some object-oriented concepts, such as inheritance
It Includes :
1. Specilization
2. Generalization
3. Aggregation
Lab Manual - ISDL
19
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
5.3. THEORY
ER/EER Diagram
Example of ER Diagram:
Figure 5.2: ER Diagram:Sample Example
5.3.4
Conversion of ER diagram to tables
Primary keys allow entity sets and relationship sets to be expressed uniformly as tables which represent
the contents of the database.
A database which conforms to an E-R diagram can be represented by a collection of tables. For each
entity set and relationship set there is a unique table which is assigned the name of the corresponding entity set or relationship set. Each table has a number of columns (generally corresponding to attributes),
which have unique names.
Converting an E-R diagram to a table format is the basis for deriving a relational database design from
an E-R diagram.A strong entity set reduces to a table with the same attributes.
Ex. Customer(customer-id, customer-name, customer-street, customer-city)Schema can be reduced as
shown in following figure:
Lab Manual - ISDL
20
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
5.4. POST LAB
ER/EER Diagram
Figure 5.3: Reduction of ER Diagram to tables
5.4
Post Lab
After completing this assignment,discuss different entity types and relation types with sample examples.Try to convert ER/EER diagrams to database tables.
5.5
Viva Questions
1. What is Data Model?
2. What is E-R model?
3. What is Object Oriented model?
4. What is an Entity?
5. What is an Entity type? What is an Extension of entity type?
6. What is an Entity set?
7. What is Weak Entity set?
8. What is an attribute?
9. What is a Relation Schema and a Relation?
10. What is degree of a Relation?
Lab Manual - ISDL
21
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
5.5. VIVA QUESTIONS
ER/EER Diagram
11. What is Relationship?
12. What is Relationship set?
13. What is Relationship type?
14. What is degree of Relationship type?
Lab Manual - ISDL
22
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
Assignment 6
Creation of database tables from ER
Diagrams using SQL
6.1
Problem Statement
Create Database Tables in RDBMS from ER Diagram in Previous assignment .
6.2
Pre Lab
• Concept of relational algebra
6.3
6.3.1
Theory
Introduction to SQL:
The Structured Query Language (SQL) comprises one of the fundamental building blocks of modern
database architecture. SQL defines the methods used to create and manipulate relational databases on
all major platforms.
SQL comes in many flavors. Oracle databases utilize their proprietary PL/SQL.Microsoft SQL Server
makes use of Transact-SQL. However, all of these variations are based upon the industry standard ANSI
SQL.
SQL commands can be divided into three main types.
1. Data Definition Language
2. Data Manipulation Language
3. Data Control Language
23
6.3. THEORY
6.3.2
Creation of database tables from ER Diagrams using SQL
DATA DEFINITION LANGUAGE(DDL)
It contains the commands used to create and destroy databases and database objects. These commands
will primarily be used by database administrators during the setup and removal phases of a database
project.
DDL Commands:
a) Create table command :
Syntax
CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
.......
)
Example:
This example demonstrates how one can create a table named “Person”, with four columns. The column
names will be“LastName”, “FirstName”, “Address”, and “Age”.
CREATE TABLE Person
( LastName varchar,
FirstName varchar,
Address varchar,
Age int );
Creating table from another (existing table) table:
Syntax:
CREATE TABLE tablename
[(columnname,columnaname)]]
AS SELECT columnname,columnaname
FROM tablename;
b) Alter table command:
Once table is created within a database, one may wish to modify the definition of that table.The ALTER
command allows to make changes to the structure of a table without deleting and recreating it.
Syntax:
Lab Manual - ISDL
24
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
6.3. THEORY
Creation of database tables from ER Diagrams using SQL
ALTER TABLE table_name
ADD (newcolumn_name1 data_type(size),
newcolumn_name2 data_type(size), .......);
Example:
ALTER TABLE personal_info
ADD salary money null;
This example adds a new attribute to the personal
info table i.e. an employee’s salary. The “money”
argument specifies that an employee’s salary will be stored using a dollars and cents format. Finally, the
“null” keyword tells the database that it’s OK for this field to contain no value for any given employee.
c. Drop table command:
DROP command allows us to remove entire database objects from our DBMS. For example, if we want
to permanently remove the personal
info table that we created, one’d use the following command:
Syntax:
DROP TABLE table_name;
Example:
DROP TABLE personal_info;
6.3.3
DATA INTEGRITY
Enforcing data integrity ensures the quality of the data in the database. For example, if an employee is
entered with an employee
id value of “123”, the database should not allow another employee to have
an ID with the same value.
Two important steps in planning tables are to identify valid values for a column and to decide how to
enforce the integrity of the data in the column. Data integrity falls into four categories:
• Entity integrity
• Domain integrity
• Referential integrity
• User-defined integrity
There are several ways of enforcing each type of integrity as shown in figure:
ENTITY INTEGRITY:
Entity integrity defines a row as a unique entity for a particular table. Entity integrity enforces the integrity of the identifier column(s) or the primary key of a table (through indexes, UNIQUE constraints,
Lab Manual - ISDL
25
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
6.3. THEORY
Creation of database tables from ER Diagrams using SQL
Figure 6.1: Enforcing Integrity Constraints
PRIMARY KEY constraints, or IDENTITY properties).
DOMAIN INTEGRITY:
Domain integrity is the validity of entries for a given column. You can enforce domain integrity by
restricting the type (through data types), the format (through CHECK constraints and rules), or the
range of possible values (through FOREIGN KEY constraints, CHECK constraints, DEFAULT definitions, NOT NULL definitions, and rules).
REFERENTIAL INTEGRITY:
Referential integrity preserves the defined relationships between tables when records are entered or
deleted. In Microsoft SQL Server, referential integrity is based on relationships between foreign keys
and primary keys or between foreign keys and unique keys. Referential integrity ensures that key values
are consistent across tables. Such consistency requires that there be no references to nonexistent values
and that if a key value changes, all references to it change consistently throughout the database.
1. PRIMARY KEY CONSTRAINT:
Definition:- The primary key of a relational table uniquely identifies each record in the table. A
primary key constraint ensures no duplicate values are entered in particular columns and that
NULL values are not entered in those columns.
2. NOT NULL CONSTRAINT:
This constraint ensures that NULL values are not entered in those columns.
Lab Manual - ISDL
26
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
6.3. THEORY
Creation of database tables from ER Diagrams using SQL
3. UNIQUE CONSTRAINT:
This constraint ensures that no duplicate values are entered in those columns.
4. CHECK CONSTRAINT:
The CHECK constraint enforces column value restrictions. Such constraints can restrict a column,
for example, to a set of values, only positive numbers, or reasonable dates.
5. FOREIGN KEY CONSTRAINT:
Foreign keys constrain data based on columns in other tables. They are called foreign keys because
the constraints are foreign–that is, outside the table.
For example,
Suppose a table contains customer addresses, and part of each address is a United States two-character
state code. If a table held all valid state codes, a foreign key constraint could be created to prevent a
user from entering invalid state codes.
To create a table with different types of constraints:
SYNTAX:
CREATE TABLE table_name
(
column_name1 data_type [constraint],
column_name2 data_type [constraint],
.......
)
Example:
Create table customer
( customer-name char(20) not null,
customer-street char(30),
customer-city char(30),
primary key ( customer-name));
create table branch
( branch-name char(15) not null,
branch-city char(30),
assets number,
primary key ( branch-name));
create table account
( branch-name char(15),
Lab Manual - ISDL
27
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
6.3. THEORY
Creation of database tables from ER Diagrams using SQL
account-number char(10) not null,
balance number,
primary key ( account-number),
foreign key ( branch-name) references branch,
check (balance>500));
6.3.4
SELECT Command
The SELECT command is the most commonly used command in SQL. It allows database users to
retrieve the specific information they desire from an operational database.
Syntax:
SELECT A1,A2..
FROM tablename
WHERE predicate
A1, A2 is the list of attributes and predicate is the condition which must be satisfied by the resulting
rows.
Example:
Following command displays list of all last names in personal
info table :
SELECT last_name
FROM personal_info
The command shown below retrieves all of the information contained within the personal
info table.
The asterisk is used as a wildcard in SQL. This means ”Select everything(all records) from the personal
info table.”
SELECT * FROM personal_info;
Finally, the WHERE clause can be used to limit the records that are retrieved to those that meet specified criteria. If some one is interested in reviewing the personnel records of all highly paid employees.
The following command retrieves all of the data contained within personal
info for records that have
a salary value greater than 50,000:
SELECT * FROM account
WHERE balance > 50000
Lab Manual - ISDL
28
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
6.4. POST LAB
6.4
Creation of database tables from ER Diagrams using SQL
Post Lab
After completing this assignment,compare different DDL commands and try to make use of the same
for sample examples by trying each possibility.
6.5
Viva Questions
1. SQL stands for?.
2. How many types of SQL commands exist?Enlist the same.
3. How data retrieval can be achieved in case of RDBMS.?Which command is used for the same?
4. How one can modify the existing table?
5. What are primary keys and foreign keys?
6. What is the difference between primary key and unique key?
7. Enlist DDL commands.
8. Write the syntax of CREATE Table command to specify the primary and foreign keys.
9. Write the syntax of SELECT command.
10. How do you communicate with an RDBMS?
Lab Manual - ISDL
29
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
Assignment 7
Assignment on DML Commands
7.1
Problem Statement
Use DML statements such as INSERT, UPDATE,DELETE to insert the data into tables and to update/delete the data inserted into/from tables if required.
7.2
Pre Lab
• Concept of SQL and relational algebra
7.3
7.3.1
Theory
DATA MANIPULATION LANGUAGE (DML):
After the database structure is defined with DDL, database administrators and users can utilize the
Data Manipulation Language to insert, retrieve and modify the data contained within it.
a. INSERT COMMAND:
The INSERT command in SQL is used to add records to an existing table.
Format 1:-Inserting a single row of data into a table
Syntax:
INSERT INTO table_name
[(columnname,columnname)]
VALUES (expression,expression);
30
7.3. THEORY
Assignment on DML Commands
Example:
INSERT INTO customer
values(’xeta’,’lincon’, calcuuta)
create table depositor
( customer-name char(20) not null,
account-number char(10) not null,
primary key ( customer-name,account-number),
foreign key ( account-number) references account,
foreign key ( customer-name) references customer);
Format 2 : Inserting data into a table from another table
Syntax:
INSERT INTO tablename
SELECT columnname,columnname
FROM tablename;
b.UPDATE COMMAND:
The UPDATE command can be used to modify information contained within a table.
Syntax:
UPDATE tablename
SET columnname=expression,columnname=expression,..
WHERE columnname=expression;
Each year,company gives all employees a 3 % cost-of-living increase in their salary. The following SQL
command could be used to quickly apply this to all of the employees stored in the database:
Example:
UPDATE account
SET balance=balance*1.03
c. DELETE COMMAND :
The DELETE command can be used to delete information contained within a table.
Syntax:
DELETE FROM tablename
WHERE search condition;
Lab Manual - ISDL
31
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
7.4. POST LAB
Assignment on DML Commands
The DELETE command with a WHERE clause can be used to remove particular record from the
account table: Example:
DELETE FROM account
WHERE account-number=12345;
The following command deletes all the rows from the table account:
DELETE FROM account;
7.4
Post Lab
After completing this assignment,compare different DML commands and try to make use of the same
for sample examples by trying each possibility.Write your analysis as concluding points.
7.5
Viva Questions
1. What is DML (Data Manipulation Language)?
2. What is DML Compiler?
3. What is basic difference between delete and truncate table command?
4. How to insert Date in SQL table?Give syntax.
5. Whether multiple rows can be inserted at once inside a table.Justify.
Lab Manual - ISDL
32
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
Assignment 8
Study and implementation of SQL
queries using Joins
8.1
Problem Statement
Study and implement the SQL queries on sample tables using Join and all versions of joins.
8.2
Pre Lab
• Concept of SQL and relational algebra
8.3
Theory
8.3.1
Introduction to database Joins
Sometimes we have to select data from two or more tables to make our result complete. We have to
perform a join. Tables in a database can be related to each other with keys.
In the “Employees” table shown below, the “Employee ID” column is the primary key,meaning that no
two rows can have the same Employee ID. The Employee ID distinguishes two persons even if they have
the same name.
• The “Employee ID” column is the primary key of the “Employees” table
• The “Prod ID” column is the primary key of the “Orders” table
• The “Employee ID” column in the “Orders” table is used to refer to the persons in the “Employees”
table without using their names
33
8.3. THEORY
Study and implementation of SQL queries using Joins
Employees table:
Figure 8.1: Employee table
Orders table:
Figure 8.2: Orders table
Referring to Two Tables,We can select data from two tables by referring to two tables, like this:
Example:
Who has ordered a product, and what did they order?
SELECT Employees.Name, Orders.Product
FROM Employees, Orders
WHERE Employees.Employee_ID=Orders.Employee_ID;
Result:
Lab Manual - ISDL
34
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
8.3. THEORY
Study and implementation of SQL queries using Joins
Figure 8.3: Resulting table of JOIN operation
OR one can select data from two tables by means of JOIN keyword.
8.3.2
Types of Joins
a)INNER JOIN : The INNER JOIN returns all rows from both tables where there is a match. If
there are rows in Employees that do not have matches in Orders, those rows will not be listed.
Syntax:
SELECT field1, field2, field3
FROM first_table
INNER JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield;
Example:
Who has ordered a product, and what did they order?
SELECT Employees.Name, Orders.Product
FROM Employees
INNER JOIN Orders
ON Employees.Employee_ID=Orders.Employee_ID;
Result:As shown in figure 8.4.
b) LEFT OUTER JOIN:
The LEFT JOIN returns all the rows from the first table (Employees), even if there are no matches in
the second table (Orders). If there are rows in Employees that do not have matches in Orders, those
rows also will be listed.
Syntax :
SELECT field1, field2, field3
Lab Manual - ISDL
35
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
8.3. THEORY
Study and implementation of SQL queries using Joins
Figure 8.4: Resulting table of INNER JOIN operation
FROM first_table
LEFT JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield;
Example :
List all employees, and their orders(if any).
SELECT Employees.Name, Orders.Product
FROM Employees
LEFT JOIN Orders
ON Employees.Employee_ID=Orders.Employee_ID;
Results:
Figure 8.5: Resulting table of LEFT OUTER JOIN operation
Lab Manual - ISDL
36
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
8.4. POST LAB
Study and implementation of SQL queries using Joins
c) RIGHT OUTER JOIN:
The RIGHT JOIN returns all the rows from the second table (Orders),even if there are no matches in the
first table (Employees). If there had been any rows in Orders that did not have matches in Employees,
those rows also would have been listed.
Syntax :
SELECT field1, field2, field3
FROM first_table
RIGHT JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield;
Example :
List all orders, and who has ordered(if any).
SELECT Employees.Name, Orders.Product
FROM Employees
RIGHT JOIN Orders
ON Employees.Employee_ID=Orders.Employee_ID;
Results:
Figure 8.6: Resulting table of RIGHT OUTER JOIN operation
8.4
Post Lab
After completing this assignment,compare different joins and try to make use of the same for sample
examples by trying each possibility.Write your analysis as concluding points.
Lab Manual - ISDL
37
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
8.5. VIVA QUESTIONS
8.5
Study and implementation of SQL queries using Joins
Viva Questions
1. What is a “join”?
2. Which are the different types of joins?
3. What is the difference between “inner” and “outer” joins?
4. Out of JOIN and SUB-QUERY, which one is more efficient?
5. What is outer join?Explain with examples.
Lab Manual - ISDL
38
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
Assignment 9
Study and implementation of SQL
queries operators and clauses
9.1
Problem Statement
Implement SQL queries using standard Operators like (ALL, IN, BETWEEN,EXCEPT, LIKE) and by
making use of clauses in SQL.
9.2
9.2.1
Theory
LIKE CONDITION :
The LIKE condition allows to use wildcards in the where clause of an SQL statement. This allows to
perform pattern matching. The LIKE condition can be used in any valid SQL statement - select, insert,
update, or delete.
The patterns that can be chosen are:
% allows to match any string of any length (including zero length)
allows to match on a single character
Example 1:
To find all of the clients whose city begins with M.
SELECT *FROM client
WHERE name like ’M%’;
39
9.2. THEORY
Study and implementation of SQL queries operators and clauses
Example 2:
To find suppliers whose name does not start with ’M’.
SELECT *FROM client
WHERE name not like ’M%’;
Example 3:
To find all suppliers whose name is 6 characters long, where the first two characters is
’Mu’ and the last 3 characters is ’bai’.
SELECT *FROM client
WHERE name like Mu_bai;
9.2.2
IN CONDITION :
The IN function helps to reduce the need to use multiple OR conditions.
SYNTAX :
SELECT columns
FROM tables
WHERE column1 in (value1, value2, .... value_n);
This SQL statement will return the records where column1 is value1, value2..., or value_n.
The IN function can be used in any valid SQL statement - select, insert, update,or delete.
Example 1
SELECT *
FROM client
WHERE name in ( ’Mumbai’ , ’Delhi’, );
This would return all rows where the client city is either Mumbai or Delhi.
Example 2
SELECT *
FROM client
WHERE name not in ( ’Mumbai’);
This would return all rows where the client city is not Mumbai.
Lab Manual - ISDL
40
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
9.2. THEORY
9.2.3
Study and implementation of SQL queries operators and clauses
BETWEEN CONDITION :
The BETWEEN condition allows to retrieve values within a range.
Syntax :
SELECT columns
FROM tables
WHERE column1 between value1 and value2;
This SQL statement will return the records where column1 is within the range of value1 and value2
(inclusive).
Example 1
SELECT *
FROM salesman
WHERE salary between 2500 AND 5000;
This would return all rows where the salesmen salary is between 2500 and 5000, inclusive.
Example 2
SELECT *
FROM salesman
WHERE salary not between 2500 and 5000;
9.2.4
EXISTS CONDITION :
The EXISTS condition is considered ”to be met” if the subquery returns at least one row.
SYNTAX:
SELECT columns
FROM tables
WHERE EXISTS ( subquery );
Example
SELECT *
FROM client
WHERE EXISTS
(select *
Lab Manual - ISDL
41
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
9.2. THEORY
Study and implementation of SQL queries operators and clauses
from sales
where sales.client_id = client.client_id);
This select statement will return all records from the client table where there is at least
one record in the sales table with the same client_id.
Example
SELECT *
FROM client
WHERE NOT EXISTS
(select *
from sales
where sales.client_id = client.client_id);
This select statement will return all records from the client table where there are
no records in the sales table with the same client_id.
9.2.5
GROUP BY CLAUSE:
The GROUP BY clause can be used in a SELECT statement to collect data across multiple records
and group the results by one or more columns.
SELECT column1, column2, ... column_n, aggregate_function
(expression)
FROM tables
WHERE predicates
GROUP BY column1, column2, ... column_n;
Where,aggregate_function can be a function such as sum,count,min,max.
Example
To return citywise data of clients.
SELECT client_id, name, SUM (salary) as "Total salary"
FROM client
GROUP BY city;
Lab Manual - ISDL
42
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
9.2. THEORY
9.2.6
Study and implementation of SQL queries operators and clauses
HAVING CLAUSE :
The HAVING clause is used in combination with the GROUP BY clause. It can be used in a SELECT
statement to filter the records that a GROUP BY returns.
Syntax:
SELECT column1, column2, ... column_n,
aggregate_function (expression)
FROM tables
WHERE predicates
GROUP BY column1, column2, ... column_n
HAVING condition1 ... condition_n;
Example
To return the name of the department and the total sales (in the associated department).
The HAVING clause will filter the results so that only departments with sales greater than
1000 will be returned.
SELECT department, SUM (sales) as "Total sales"
FROM order_details
GROUP BY department
HAVING SUM (sales) > 1000;
9.2.7
ORDER BY CLAUSE:
The ORDER BY clause allows you to sort the records in your result set. The ORDER BY clause can
only be used in SELECT statements. The ORDER BY clause sorts the result set based on the columns
specified. If the ASC or DESC value is omitted, the system assumed ascending order.
Syntax:
SELECT columns
FROM tables
WHERE predicates
ORDER BY column ASC/DESC;
Where,ASC indicates ascending order. (default)
DESC indicates descending order.
Lab Manual - ISDL
43
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
9.3. POST LAB
Study and implementation of SQL queries operators and clauses
SELECT sales_id, client_id, to_char(sales_date,DD/MM/YY)
FROM sales
ORDER BY to_char(sales_date,DD/MM/YY);
This would return all records sorted by the date field from sales table.
9.3
Post Lab
After completing this assignment,analyze different clauses and operators in SQL and try to make use of
the same for sample examples by trying each possibility.Write your analysis as concluding points.
9.4
Viva Questions
1. What is the difference between GROUP BY and ORDER BY clauses?
2. What is the difference between a “where” clause and a “having” clause?
3. When using a count(disitnct) is it better to use a self-join or temp table to find redundant data,
and provide an example?
4. How to find out the 10th highest salary in SQL query?
5. What is the use of DESC in SQL?
6. Which operator performs pattern matching?
7. What are the wildcards used for pattern matching?
8. How to Select last N records from a Table?
9. Identify error in following SQL:
SELECT EMPNO, SUM(SAL) FROM EMP
GROUP BY EMPNO
HAVING ENAME= "KENT";
a) Syntax Error
b) SUM() is not an aggregate function
c) HAVING can not be used with GROUP BY
d) The Having condition has to be based on some column that appears in the select list.
10. Explain the ORDER BY clause with proper syntax.
Lab Manual - ISDL
44
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
Assignment 10
Creation and Execution of simple
programs in PL/SQL (Procedures
and Functions)
10.1
Problem Statement
Write and execute simple PL/SQL programs using Procedures and Functions in PL/SQL.
10.2
Theory
10.2.1
PL/SQL (Procedural Language/Structured Query Language)
It is Oracle Corporation’s proprietary procedural extension to the SQL database language, used in the
Oracle database. Some other SQL database management systems offer similar extensions to the SQL
language. PL/SQL’s syntax strongly resembles that of Ada, and just like some Ada compilers of the
1980s, the PL/SQL runtime system uses Diana as intermediate representation. The key strength of
PL/SQL is its tight integration with the Oracle database.
Basic code structure in PL/SQL
DECLARE
TYPE / item / FUNCTION / PROCEDURE declarations
BEGIN
Statements
45
10.2. THEORY
Creation and Execution of simple programs in PL/SQL (Procedures and Functions)
EXCEPTION
EXCEPTION handlers
END;
The DECLARE and EXCEPTION sections are optional.
Simple Example:
DECLARE
number1 NUMBER(2);
number2 NUMBER(2) := 17; -- value default
text1 VARCHAR2(12) := ’Hello world’;
text2 DATE := SYSDATE; -- current date and time
BEGIN
SELECT street_number
INTO number1
FROM address
WHERE name = ’Sahil’;
END;
10.2.2
FUNCTIONS
Functions in PL/SQL are a collection of SQL and PL/SQL statements that perform a task and should
return a value to the calling environment.
SYNTAX:
CREATE OR REPLACE FUNCTION <function_name> [(input/output variable declarations)] RETURN return_type
<IS|AS>
[declaration block]
BEGIN
<PL/SQL block WITH RETURN statement>
[EXCEPTION
EXCEPTION block]
END;
Example:
CREATE OR REPLACE FUN add(a in number,b out number,c in out number) return number IS
BEGIN
dbms_output.put_line(’a = ’ || a || ’ b = ’ || b || ’ c = ’ || c);
Lab Manual - ISDL
46
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
10.3. POST LAB Creation and Execution of simple programs in PL/SQL (Procedures and Functions)
dbms_output.put_line(’Addition Result = ’);
return (a+b+c);
END FUN;
10.2.3
PROCEDURES
Procedures are the same as Functions, in that they are also used to perform some task with the difference
being that procedures cannot be used in a SQL statement and although they can have multiple out
parameters they do not return a value.
SYNTAX:
CREATE OR REPLACE PROCEDURE <procedure_name> [(input/output variable declarations)]
<IS|AS>
[declaration block]
BEGIN
<PL/SQL block statements>
[EXCEPTION
EXCEPTION block]
END;
Example:
CREATE OR REPLACE PROC add(a in number,b out number,c in out number) return number IS
BEGIN
dbms_output.put_line(’a = ’ || a || ’ b = ’ || b || ’ c = ’ || c);
dbms_output.put_line(’Addition Result = ’||(a+b+c));
END PROC;
10.3
Post Lab
After completing this assignment,solve following sample examples by trying each possibility.Write your
analysis as concluding points.
10.4
Exercise
1. Write a PL/SQL code block that will accept an account number from the user. check if the users
balance is less than the minimum balance, only then deduct Rs. 100/- from the balance. The
process is fired on the Acc Master table.(Use conditional control- If-Else If-Else-End If).
Lab Manual - ISDL
47
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
10.5. VIVA QUESTIONS
Creation and Execution of simple programs in PL/SQL (Procedures and Functions)
2. Write a PL/SQL code block to calculate the area of a circle for a value of radius varying from 3
to 7, consisting of two columns Radius & Area.(Use Iterative control- the While loop).
3. Write a PL/SQL block of code for inverting a number 5639 to 9365.(Use Iterative control- the For
loop).
4. Write a PL/SQL block of code to achieve the following: if there are no transactions taken place in
the last 365 days then mark the account status as inactive, and then record the account number,
the opening date & the type of account in the Inactive Acct Mstr table.
10.5
Viva Questions
1. What is difference between SQL and PL/SQL?
2. What is PL/SQL Block?
3. What is difference between procedures and functions?
4. What are the different iterative controls in PL/SQL?
5. Give the structure of PL/SQL block.
Lab Manual - ISDL
48
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
Assignment 11
Creation and Execution of Triggers
and Cursors in PL/SQL
11.1
Problem Statement
Write and execute cursors and triggers in PL/SQL.
11.2
Theory
11.2.1
PL/SQL Cursors Types :
Implicit Cursors :
Implicit cursors are automatically created and used by Oracle every time you issue a select statement
in PL/SQL. If you use an Implicit cursors, Oracle will perform the open, fetches, and close for you
automatically. Implicit cursors are used in statements that return only one row. If the SQL statement
returns more than one row, an error will occur.
In the following PL/SQL code block, the select statement makes use of an implicit cursor:
Example:
Begin
Update emp Set empno=empno Where 1=2;
Dbms_output.put_line(sql%rowcount ||’ ’|| ’ rows are affected by the update statement’);
End;
Cursor For loops
Normally when you use explicit cursors, cursors have to be opened, the data has to be fetched, and
49
11.2. THEORY
Creation and Execution of Triggers and Cursors in PL/SQL
finally the cursor needs to be closed. A cursor for loop automatically performs the open, fetch, and close
procedures, which simplifies your job.
Example:
Declare Cursor emp_cursor
is Select empno, ename,sal From emp;
V_emp emp%RowType;
Begin
For emp_info IN emp_cursor
LOOP
Dbms_output.put_line (’Employee id : ’||emp_info.empno||’Employee name : ’||
emp_info.ename||’Employee salary:’||emp_info.sal);
End LOOP;
End;
Explicit Cursors
Explicit cursors are created by the programmer, and with these you can do operations on a set of rows,
which can be processed one by one. You use explicit cursors when you are sure that the SQL statement
will return more than one row. You have to declare an explicit cursors in the declare section at the
beginning of the PL/SQL block. Once you declare your cursor, the explicit cursors will go through these
steps:
1. Declare. This clause initializes the cursor into memory.
2. Open the previously declared cursor is now open and memory is allotted.
3. Fetch The previously declared and opened cursor can now access data;
4. Close The previously declared, opened, and fetched cursor is closed , which also releases memory
allocation.
Example:
Declare Cursor empcursor(empn in number) Is
select * from emp where empno=empn;
Empvar emp%rowtype;
Begin
Dbms_output.put_line(’Getting records for employee no. 7521’);
Open empcursor(7521);
Loop
Fetch empcursor into empvar;
Lab Manual - ISDL
50
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
11.2. THEORY
Creation and Execution of Triggers and Cursors in PL/SQL
Exit when empcursor%notfound;
Dbms_output.put_line(’emp name : ’ || empvar.ename);
Dbms_output.put_line(’emp salary : ’ || empvar.sal);
End loop;
Close empcursor;
End;
11.2.2
Triggers
Triggers are simply stored procedures that are ran automatically by the database whenever some event
(usually a table update) happens. We wont spend a great deal of time talking about how to write
triggers, because if you know how to write stored procedures, you already know how to write triggers.
What we will discuss is how to set them up to be executed whenever something happens to the table.
PL/SQL Triggers
Triggers are basically PL/SQL procedures that are associated with tables, and are called whenever a
certain modification (event) occurs. The modification statements may include INSERT, UPDATE, and
DELETE.
SYNTAX:
CREATE [OR REPLACE]
TRIGGER trigger_name
BEFORE (or AFTER)
INSERT OR UPDATE [OF COLUMNS] OR DELETE
ON tablename
[FOR EACH ROW [WHEN (condition)]]
BEGIN
...
END;
Example:
CREATE OR REPLACE TRIGGER PERSON_INSERT_BEFORE
BEFORE
INSERT ON PERSON
FOR EACH ROW
BEGIN
DBMS_OUTPUT.PUT_LINE(BEFORE INSERT OF
|| :NEW.NAME);
END;
Lab Manual - ISDL
51
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
11.3. POST LAB
11.3
Creation and Execution of Triggers and Cursors in PL/SQL
Post Lab
After completing this assignment,solve sample examples by using cursors and triggers.Write your analysis
as concluding points.
11.4
Viva Questions
1. What is trigger and cursor in PL/SQL?
2. What are the types of trigger and cursor?
3. How to delete a trigger?
4. Why we write a cerate or replace in PL/SQL Block?
5. What is row level and statement level trigger?
Lab Manual - ISDL
52
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
Assignment 12
Implementation of Mini
Project/application.
12.1
Problem Statement
Implement a system for any Commercial Organization using ORACLE as a back end and VB.NET as
a front end tool.
12.2
Theory
Prepare a detailed report of your mini project covering following details:
1. Title of the Project.
2. Abstract
3. Introduction
4. Scope
5. Software/Hardware Requirements Specification
6. Entity Relationship Diagram with EER features
7. Data Dictionary
8. Relational Database Design
9. Database Normalization
53
12.2. THEORY
Implementation of Mini Project/application.
10. Graphical User Interface(Screenshots)
11. Source Code: (should be in CD)
12. Data Reports
13. Testing document
14. Future Enhancement
15. Conclusion
16. References/bibliography
You may choose any topics (not limited to following) for your mini project:
• Performance appraisal system
• Employee Information System
• Human Resource monitoring system
• Administrations and Management of Policies for insurance agent.
• Hotel Occupancy monitoring
• Hospital staff database
• Payroll system in the college
• Passengers Database for airline industry
• Aviation Industry Information System
• Customers Feedback monitoring.
• Patients History database
• Sales Force Automation
• Marketing Info Systems
• Inventory Control Systems
• Online investment Management
• Cash Management System
Lab Manual - ISDL
54
Prof.Patil P.M&Prof.Shah S. K. VPCOE, Baramati
References
[1] “Visual Basic 6 Programming, Black Book DreamTeach Press. [12]
[2] Dr. P.S.Deshpande, “SQL and PL/SQL for Oracle 10g Black Book”, DreamTech Press [05]
[3] “Visual Basic 6 Programming”, Tata McgrawHill ,Content Development Group.[05]
[4] Urman S., Hardman R., McLAUGHLIN M., “PL/SQL Programming: Develop Database
Driven PL/SQL Applications”, Tata McGraw-Hill Edition, 2004,ISBN 0 -07 - 059779 - 0
[5] Rosenzweig B., Silvestrova E., “Oracle PL/SQL by Example”, 3rd Edition,Pearson Education
ISBN 81-297-0503-6.[10]
[6] “Beginning Visual Basic 2005”,Wrox publication. [01]
[7] Ivan Bayross,”SQL PL/SQL:The Programming Language of Oracle [17]
55