Laboratory Record Note Book: Rajalakshmi Institute of Technology
Laboratory Record Note Book: Rajalakshmi Institute of Technology
Laboratory Record Note Book: Rajalakshmi Institute of Technology
SEMESTER IV
1
211719104072
RAJALAKSHMI INSTITUTE OF
TECHNOLOGY
KUTHAMBAKKAM, CHENNAI-600124.
BONAFIDE CERTIFICATE
NAME: MADHULIKAINDRAGANTI
SEMESTER IV
BRANCH : CSE
Certified that this is a bonafide record of work done by the above student in
the
2
211719104072
INDEX
Name: MADHULIKA INDRAGANTI Sec: B
3a 05-03-2021 Views 18
3b 05-03-2021 Sequences 21
3c 05-03-2021 Synonyms 23
DATABASE PROGRAMMING
5a 19-03-2021 Procedures 28
5b 19-03-2021 Functions 32
6 20-03-2021 Triggers 36
3
211719104072
DATE : 19-02-2021
AIM:
To create table and implement data definition and data manipulation commands in SQL
DESCRIPTION:
Creating a table
Altering table structure by adding, deleting or modifying columns
Destroy databases and database objects.
These commands will primarily be used by database administrators during the setup and removal
phases of a database project.
THE ORACLE TABLE – DUAL - Dual is a small oracle table which consists of only
onerow and one column and contains the value X in that column.
SELECT - This command is used to display the contents of the table or those of
aparticular column.
UPDATE-A SQL UPDATE statement that changes the data of one or more records in
atable. Either all the rows can be updated, or a subset may be chosen using a condition
DELETE -An SQL DELETE statement removes one or more records from a table.
Asubset may be defined for deletion using a condition, otherwise all records are removed
COMMIT - This command is used to permanently stored the data in the database.
4
211719104072
SQL> create table stud (snamevarchar2(30), sid varchar2(10), sage number(2), sarea
varchar2(20));
Table created.
SQL>desc stud;
NameNull? Type
SNAMENullVARCHAR2(30)
SIDNullVARCHAR2(10)
SAGENullNUMBER(2)
SAREANullVARCHAR2(20)
ALTER TABLE
Table altered.
SQL>desc stud;
NameNull? Type
Table altered.
SQL>desc stud;
NameNull? Type
5
211719104072
SAREA VARCHAR2(20)
SDEPT VARCHAR2(20)
Table altered.
SQL>desc studs;
NameNull? Type
SNAME VARCHAR2(30)
SID VARCHAR2(10)
SAGE NUMBER(10)
SAREA VARCHAR2(20)
TRUNCATE TABLE:
TRUNCATE TABLE removes all rows from a table, but the table structure and its columns,
constraints, indexes and so on remain.
SQL> truncate table studs;
Table truncated.
SQL>desc studs
NameNull? Type
SNAME VARCHAR2(30)
SID VARCHAR2(10)
SAGE NUMBER(10)
SAREA VARCHAR2(20)
SDEPT VARCHAR2(20)
DROP TABLE:
Drop table removes one or more table definitions completely from the database,by removing
all data, indexes, triggers, constraints, and permission specifications for those tables.
SQL> drop table studs;
Table dropped.
6
211719104072
CREATION OF TABLE
SYNTAX:
1 row created.
1 row created.
TCL COMMANDS
COMMIT:
SQL> commit;
The data is stored permanently.
SAVE POINT:
SQL>savepoint A;
8
211719104072
RESULT :
Thus the SQL commands for data definitions and data manipulation have been executed and the
output have been verified.
9
211719104072
DATE :26-02-2021
AIM:
To create table and execute simple and nested queries using SQL commands
DESCRIPTION:
ORDER BY CLAUSE - The order by clause arranges the contents of the table inascending
order (by default) or in descending order (if specified explicitly) according to the specified
column.
GROUP BY CLAUSE-The group by clause is another section of the select statement. This
optional class tells oracle to group rows based on distinct values that exists for specified
columns.
The having clause can be used in conjunction with the group by clause. Having imposes a
condition on the group by clause, which further filters the groups created by the group by
clause.
UNION CLAUSE: Multiple queries can be put together and their output combined using the
union clause. The union clause merges the output of two or more queries into a single set of
rows and columns.
INTERSECT CLAUSE: Multiple queries can be put together and their output can be
combined using the intersect clause. The intersect clause outputs only rows produced by both
the queries intersected. The output in an intersect clausewill include only those rows that are
retrieved by both the queries. SQL Correlated Subqueries
Correlated subqueries are used for row-by-row processing. Each subquery is executed once for
every row of the outer query.
JOINS:
Joins are normally used to retrieve data from more than one table
The keyword JOIN, joins one or more tables together in a results set.
To perform a join, there must be a common key that defines how the rows in the table
correspond to each other.
All sub-queries can be converted to joins, however ,all joins cannot be converted to sub-queries.
10
211719104072
COMMANDS
Subquery Syntax
SELECT select_list FROM table WHERE expr operator (SELECT select_list FROM
table);
– The subquery (inner query) executes once before the main query (outer query).
– In the syntax:
– Can place the subquery in a number of SQL clauses, including the following:
– WHERE clause
– HAVING clause
– FROM clause
Ashwin 19
Bhavesh 18
BETWEEN OPERATOR
SQL> select sname,sarea, sid from studs where sid between 102 and 104;
11
211719104072
GROUP BY CLAUSE:
SAREA RESULT
Annanagar 1000
Nungambakkam 500
Kilpauk 100
HAVING CLAUSE:
SQL> select sarea, sum(spocket) result from studs group by sarea having spocket<600;
SAREA RESULT
nungambakkam 500
kilpauk 100
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
12
211719104072
PRODNAME PRODNO
table 10001
chair 10010
desk 10110
cot 11110
sofa 10010
Tvstand 11010
1 row created.
1 row created.
13
211719104072
SET OPERATIONS:
SQL> select prodname from product where prodno=10010 union select prodname from sale where
prodno=10010;
PRODNAME
chair
sofa
SQL> select prodname from product where prodno=11110 intersect select prodname from sale
where prodno=11110;
PRODNAME
Cot
CORRELATED SUBQUERY
A correlated subquery is evaluated once for each row processed by the parent statement.
The parent statement can be a SELECT, UPDATE, or DELETE statement.
A correlated subquery is one way of reading every row in a table and comparing values in
each row against related data. It is used whenever a subquery must return a different result
or set of results for each candidate row considered by the main query. In other words, user
can use a correlated subquery to answer a multipart question whose answer depends on the
value in each row processed by the parent statement.
CORRELATED UPDATE :
SQL> UPDATE table1 alias1SET column = (SELECT expression From table2 alias2WHERE
alias1.column =alias2.column);
Use a correlated subquery to update rows in one table based on rows from another table.
14
211719104072
JOINS:
CARTESIAN JOIN:
A Cartesian join is also known as cross join.
If there are two tables, then the Cartesian join is obtained when every row of one table is
joined to a row in another table.
SYNTAX
EXAMPLE:
SQL>SELECT * FROM EMP,DEPT;
INNER JOIN:
The inner join joins two or more tables, returning only matched rows;
It require that both tables involved in join must have a primary- foreignkey relationship.
Example for an employee and department table ‘a’ is the alias for employee
Here ‘a’ is the alias name for Here ‘b’ is the alias name for
emp_id,enam
location
15
211719104072
OUTER JOIN:
The SQL OUTER JOIN command is used to display the elements in a table,regardless of
whether they are present in the second table.
ISO method->(+) by placing this symbol in where clause,on the other side of the table,for
which all the rows need to be included.(available in Oracle 8i).
SYNTAX:
SELECT Column_list FROM Left_table LEFT [OUTER] JOIN Right_Table ON
Condition.
16
211719104072
SYNTAX:
SYNTAX:
A full outer join is essentially a combination of left and right outer joins, i.e.
The records from the table on left are included even if there are no matching records on the
right.
The records from the table on the right are included even if there are no matching record on the left.
SYNTAX:
SELECT Column_list FROM left_table FULL [OUTER] JOIN right _table ON condition.
RESULT:
Thus, the SQL commands for database querying using simple and nested queries have been
executed successfully and the output is verified.
17
211719104072
EX.NO:3a) VIEWS
DATE: 05-03-2021
AIM:
Syntax
CREATE VIEW view_name AS
SELECT column1, column2.....
FROM table_name
WHERE [condition];
1.Query to create a view to have customer name and age from the CUSTOMERS table.
View created.
Updating a View
18
211719104072
set age = 35
where name = 'Ramesh';
Output:
OUTPUT:
Dropping Views
1.Query to drop the CUSTOMERS_VIEW from the CUSTOMERS table.
19
211719104072
OUTPUT:
RESULT:
Thus the SQL commands to execute views have been executed successfully and the output is
verified.
20
211719104072
EX.NO:3b) SEQUENCES
DATE: 05-03-2021
AIM:
SYNTAX:
SQL>
create sequence sequence_1
start with 1
increment by 1
minvalue 0
maxvalue 100
cycle;
Sequence created.
Table created.
1 row(s) inserted.
1 row(s) inserted.
OUPUT:
I
NAME
D
1 Ramesh
2 Suresh
21
211719104072
Dropping Sequences
Sequence dropped.
SQL>
create sequence sequence_2
start with 100
increment by -1
minvalue 1
maxvalue 100
cycle;
Sequence created.
Table created.
1 row(s) inserted.
1 row(s) inserted.
OUTPUT:
ID NAME
100 Ramesh
99 Suresh
DROPPING SEQUENCES:
Sequence dropped.
RESULT:
Thus the SQL commands to execute sequences have been executed successfully and the output
is verified
22
211719104072
EX.NO:3c) SYNONYMS
DATE: 05-03-2021
AIM:
Table created.
1 row(s) inserted.
1 row(s) inserted.
Synonym created.
SQL>select * from s;
I
NAME
D
1 Ramesh
2 Suresh
SQL>drop synonym s;
Synonym dropped.
RESULT:
Thus the SQL commands to execute synonyms have been executed successfully and the output
is verified
23
211719104072
AIM:
To implement data programming using implicit cursors using SQL commands.
SQL> create table customers(id number, name varchar2(10), age number, address
varchar2(30),salary number);
Table created.
SQL>
Declare
total_rows number(2);
begin
update customers
ifsql%notfound then
elsifsql%found then
total_rows := sql%rowcount;
end if;
end;
24
211719104072
OUTPUT:
6 customers selected
1 row(s) updated.
RESULT:
Thus the SQL program to execute data programming using implicit cursors have been executed
successfully and the output is verified.
25
211719104072
DATE: 12-03-2021
AIM: To implement data programming using explicit cursors using SQL commands.
SYNTAX:
Table created.
SQL>
declare
c_idcustomers.id%type;
c_namecustomers.name%type;
c_addrcustomers.address%type;
cursorc_customers is
begin
26
211719104072
openc_customers;
loop
end loop;
closec_customers;
end;
OUTPUT:
1 Ramesh Ahmedabad
2 Khilan Delhi
3 kaushik Kota
4 Chaitali Mumbai
5 Hardik Bhopal
6 Komal MP
RESULT:
Thus, the SQL program to execute data programming using explicit cursors have been executed
successfully and the output is verified.
27
211719104072
EX.NO:5a) PROCEDURES
DATE:19-03-2021
AIM:
To implement procedures using SQL programming.
SYNTAX:
(i) Write a PL/SQL Procedure that displays the string 'Hello World!'
SQL>
create or replace procedure greetings
as
begin
dbms_output.put_line('Hello World!');
end;
/
begin
greetings;
end;
/
OUTPUT:
Hello World
Statement processed.
(ii) Write a PL/SQL Procedure that finds the minimum of two values.
SQL>
declare
a number;
b number;
28
211719104072
c number;
begin
if x < y then
z:= x;
else
z:= y;
end if;
end;
begin
a:= 23;
b:= 45;
findmin(a, b, c);
end;
Output:
(iii) Write a PL/SQL Procedure that computes the square of value of a passed value.
SQL>
Declare
a number;
begin
x := x * x;
29
211719104072
end;
begin
a:= 23;
squarenum(a);
end;
Output:
Table created
SQL>
create or replace procedure "insertuser" (id in number, name in varchar2)
is
begin
insert into user1 values(id,name);
end;
/
Procedure created.
SQL>
begin
insertuser(101,'Rahul');
dbms_output.put_line('Record inserted successfully');
end;
/
Record inserted successfully
Statement processed.
OUTPUT:
ID Name
101 Rahul
30
211719104072
RESULT:
Thus,the SQL programs to execute procedures have been executed and the output is verified.
31
211719104072
EX.NO:5b) FUNCTIONS
DATE: 19-03-2021
AIM:
SYNTAX:
(i) Write a PL/SQL function that computes and returns the addition of two numbers.
SQL>
create or replace function adder(n1 in number, n2 in number)
return number
is
n3 number(8);
begin
n3 :=n1+n2;
return n3;
end;
/
Function created
declare
n3 number(2);
begin
n3 := adder(11,22);
dbms_output.put_line('Addition is: ' || n3);
end;
/
OUTPUT:
Addition is: 33
Statement processed.
(ii) Write a PL/SQL function that computes and returns the maximum of two values.
32
211719104072
SQL>
declare
a number;
b number;
c number;
function findmax(x in number, y in number)
return number
is
z number;
begin
if x > y then
z:= x;
else
z:= y;
end if;
return z;
end;
begin
a:= 23;
b:= 45;
c := findmax(a, b);
dbms_output.put_line(' Maximum of (23,45): ' || c);
end;
/
OUTPUT:
Maximum of (23,45): 45
Statement processed.
(iii) Write a PL/SQL function that will return the total number of CUSTOMERS in the
customers table.
SQL> create table customers(id number, name varchar2(10), age number, address varchar2(30),
salary number);
Table created.
33
211719104072
SQL>
create or replace function totalcustomers
return number is
total number(2) := 0;
begin
select count(*) into total from customers;
return total;
end;
/
Function created.
declare
c number(2);
begin
c := totalcustomers();
dbms_output.put_line('Total no. of Customers: ' || c);
end;
/
OUTPUT:
SQL>
declare
num number;
factorial number;
function fact(x number)
return number
is
34
211719104072
f number;
begin
if x=0 then
f := 1;
else
f := x * fact(x-1);
end if;
return f;
end;
begin
num:= 6;
factorial := fact(num);
dbms_output.put_line(' Factorial '|| num || ' is ' || factorial);
end;
/
OUTPUT:
Factorial 6 is 720
Statement processed.
RESULT:
Thus,the SQL programs to execute functions have been executed and the output is verified.
35
211719104072
EX.NO:6 TRIGGERS
DATE: 20-03-2021
AIM:
Table created.
36
211719104072
SQL>
Trigger created.
OUTPUT:
SQL>update customers
set salary = salary + 500
where id = 2;
37
211719104072
OUTPUT:
RESULT:
Thus,the SQL programs to execute triggers have been executed successfully and the output is
verified.
38
211719104072
DATE :26-03-2021
AIM:
THEORY:
User-defined exceptions
DECLARE
<declarations section>
BEGIN
<executable command(s)>
EXCEPTION
<exception handling goes here >
........
WHEN others THEN
39
211719104072
exception3-handling-statements
END;
Example
DECLARE
pssn number(4);
pfname varchar2(15);
pbdate date;
BEGIN
SELECT fname, bdate INTO pfname, pbdate
FROM employee205
WHERE ssn = &pssn;
DBMS_OUTPUT.PUT_LINE ('Name: '|| pfname);
DBMS_OUTPUT.PUT_LINE ('Date of Birth: ' || pbdate);
EXCEPTION
WHEN no_data_found THEN
dbms_output.put_line('No such Employee!');
WHEN others THEN
dbms_output.put_line('Error!');
END;
EXECUTION 1:
Enter value for pssn: 999
old 8: WHERE ssn = &pssn;
new 8: WHERE ssn = 999;
Name: NANDA
Date of Birth: 30-MAY-05
40
211719104072
EXECUTION 2:
Raising Exceptions
Exceptions are raised by the database server automatically whenever there is any internal
database
error, but exceptions can be raised explicitly by the programmer by using the command
RAISE.
DECLARE
exception_name EXCEPTION;
BEGIN
IF condition THEN
RAISE exception_name;
END IF;
EXCEPTION
WHEN exception_name THEN
statement;
END;
USER-DEFINED EXCEPTIONS:
PL/SQL allows to define own exceptions according to the need of the program. A user-
defined exception must be declared and then raised explicitly, using either a RAISE
statement or the procedure
DBMS_STANDARD.RAISE_APPLICATION_ERROR.
41
211719104072
DECLARE
my-exception EXCEPTION;
Example:
The following example illustrates the concept. This program asks for assn, when the user
enters an invalid ssn, the exception invalid_ssn is raised.
DECLARE
pssn number(4);
inputssn number(4);
pfname varchar2(15);
pbdate date;
invalid_ssn EXCEPTION;
BEGIN
PSSN:=&inputssn;
IF Pssn<= 0 THEN
RAISE invalid_ssn;
ELSE
SELECT fname, bdate INTO pfname, pbdate
FROM employee205
WHERE ssn = pssn;
DBMS_OUTPUT.PUT_LINE ('Name: '|| pfname);
DBMS_OUTPUT.PUT_LINE ('Date of Birth: ' || pbdate);
END IF;
EXCEPTION
WHEN invalid_ssn THEN
dbms_output.put_line('SSN must be greater than zero!');
WHEN no_data_found THEN
dbms_output.put_line('No such Employee!');
WHEN others THEN
dbms_output.put_line('Error!');
END;
/
SQL> /
42
211719104072
SQL> /
Enter value for inputssn: 200
old 8: PSSN:=&inputssn;
new 8: PSSN:=200;
No such Employee!
SQL> /
Enter value for inputssn: 0
old 8: PSSN:=&inputssn;
new 8: PSSN:=0;
SSN must be greater than zero!
PL/SQL procedure successfully completed.
RESULT:
Thus,the SQL programs to execute triggers have been executed successfully and the output is
verified.
43
211719104072
APPLICATION
DATE: 09-04-2021
AIM:
ER DIAGRAM:
CHEN NOTATION:
CHEN NOTATION:
44
211719104072
REPRESENTING RELATIONSHIPS:
1: N Relationships.
Solution: Introduce a third Intersection relation and copy keys from original two
relations.
CHEN NOTATION:
Note that this can also be shown in the ER diagram. Also, look for potential added
attributes in the intersection relation.
45
211719104072
The repeating fields will be removed from the original data table, leaving the following.
ItemNo, Description
All of these fields except the primary key will be removed from the original table. The primary key
will be left in the original table to allow linking of data:
46
211719104072
Never treat price as dependent on item. Price may be different for different sales orders (discounts,
special customers, etc.)
Along with the unchanged table below, these tables make up a database in second normal form:
ClerkNo, ClerkName
All of these fields except the primary key will be removed from the original table. The primary key
will be left in the original table to allow linking of data as follows:
Together with the unchanged tables below, these tables make up the database in third normal form.
ItemNo, Description
47
211719104072
RESULT:
Thus,the SQL programs to execute data design using ER modeling normalization and application
have been executed successfully and the output is verified.
48
211719104072
AIM:
Provides Access with the information it requires to join the information in the tables
together as needed.
Determine the purpose of database: This helps to prepare for the remaining steps.
2.1.2 Find and organize the information required: Gather all of the types of information to
record in the database, such as product name and order number.
2.1.3 Divide the information into tables: Divide information items into major entities
orsubjects, such as Products or Orders. Each subject then becomes a table.
49
211719104072
2.1.4 Turn information items into columns: Decide what information to store in eachtable. Each
item becomes a field, and is displayed as a column in the table. For example, an Employees
table might include fields such as Last Name and Hire Date.
2.1.5 Specify primary keys: Choose each table’s primary key. The primary key is a column thatis
used to uniquely identify each row. An example might be Product ID or Order ID.
2.1.6 Set up the table relationships: Look at each table and decide how the data in one table
isrelated to the data in other tables. Add fields to tables or create new tables to clarify the
relationships, as necessary.
2.1.7 Refine the design: Analyze the design for errors. Create the tables and add a few recordsof
sample data. See if it can get the results from the tables. Make adjustments to the design, as
needed.
These are ten general principles for user interface design. They are called "heuristics"
because they are more in the nature of rules of thumb than specific usability guidelines.by
Jakob Nielsen
The system should always keep users informed about what is going on, through
appropriate feedback within reasonable time.
The system should speak the users' language, with words, phrases and concepts familiar to
the user, rather than system-oriented terms. Follow real-world conventions, making
information appear in a natural and logical order.
50
211719104072
Users often choose system functions by mistake and will need a clearly marked "emergency
exit" to leave the unwanted state without having to go through an extended dialogue.
Support undo and redo.
Users should not have to wonder whether different words, situations, or actions mean the
same thing. Follow platform conventions.
Even better than good error messages is a careful design which prevents a problem from
occurring in the first place. Either eliminate error-prone conditions or check for them and
present users with a confirmation option before they commit to the action.
Minimize the user's memory load by making objects, actions, and options visible. The user
should not have to remember information from one part of the dialogue to another.
Instructions for use of the system should be visible or easily retrievable whenever
appropriate.
Accelerators -- unseen by the novice user -- may often speed up the interaction for the
expert user such that the system can cater to both inexperienced and experienced users.
Allow users to tailor frequent actions.
Dialogues should not contain information which is irrelevant or rarely needed. Every extra
unit of information in a dialogue competes with the relevant units of information and
diminishes their relative visibility.
Error messages should be expressed in plain language (no codes), precisely indicate the
problem, and constructively suggest a solution.
51
211719104072
Even though it is better if the system can be used without documentation, it may be
necessary to provide help and documentation. Any such information should be easy to
search, focused on the user's task, list concrete steps to be carried out, and not be too large.
It also provides capability to produce custom libraries and objects that can be loaded at
runtime or bound into the distributed application.
Every time the user load a VB or VBA project, user will be greeted by roughly the layout
shown in Figure and these five GUI tools. First, the toolbox(1) contains all the GUI
elements/controls needed to create any VB form and the front end to all VB programs. For
example, after the pointer tool there is the image control, label, textbox, and frame and command
52
211719104072
button as the first five of 20 standard controls which are used constantly in VB programs. Another
advantage of these basic controls is that they fill 60-90% of all programming needs and are
automatically included in the VB runtime.
Second is form(2). Think of it as it can size it, color it, give it a caption("Database Test" in
this case) and fill the form with GUI controls which helps the program do useful works. Putting
controls on the form is as easy as clicking on the control (say the command button) in the toolbox
and then dragging and sizing it on the form (see the "Exit" button on the form).
The third part of the Basic canvas is the menus and toolbars (3) which manage and control
all of VB/VBA.Most of us will be familiar with many of the menu and icons. File, Edit, View, Run,
Window, Help menus should be familiar to any Word Perfect, Excel, or Netscape users. Likewise
icons for File Open, File Save, Cut, Copy, Paste, Find, Run programs, Pause Program, Halt
Program can be seen along the toolbar. Along with built in wizards and custom command centers in
some controls, this is the heart of VB.
Fourth is the Project Explorer (4) which user uses to access all the forms and coding
filesin the VB program. The PE-Project Explorer is such a handy navigation device which will find
using it all the time to switch among different forms and code.
Fifth and even more frequently used than the Project Explorer is the Properties sheet (5).
Note that the "Exit" command button is highlighted in the form and is also the control listed in the
Properties sheet. The Properties sheet is both the elegance and the swamp of VB. If user want to
change the property of any control like its color, shape, caption, or whatever - the Property sheet is
the place to go. But a command button has 32 properties - and some controls have hundreds, hence
the swamp.
User will find in developing in Visual Basic that spends a large percentage of time using the
Project Explorer and Property sheet. It is worthwhile to get to know them well. Project Explorer
is the means of navigating around the various parts of VB; while Property sheets allows to set the
very basic look and feel plus behavior of all the forms in Visual Basic.
53
211719104072
The toolbox icon - toggles the main toolbox of form controls on and off.
The form icon in the Project Explorer. Click on this and the active Form
will appear in the edit window.
The toolbar handle. Every toolbar has one. Pull on it to move/reposition
the toolbar anywhere on the screen.
The Project Explorer icon - toggle this to make the Project Explorer appear
or disappear.
Property sheet icon - toggle this to make the Property sheet appear or
disappear.
FORM DESIGN:
Forms don’t usually get much attention from code-level developers. We add a form and off we
go, plugging in various controls and using them as containers for information. But setting up
forms’ properties is important for creating visually pleasant, consistent, and intuitive interfaces.
It should specify the proper border style of a form. The options are:
None
Fixed Single
Sizable
Fixed Dialog
Fixed ToolWindow
Sizable ToolWindow
Using None is rarely a good idea, since such forms don’t have a title bar or the control menu
box,so users can’t close or resize them. The default form value is Sizable (allowing users to
resize theform), but this is a good choice only in cases where all the form elements are designed
to resizealong with the form itself.The Fixed Dialog style offers a border and doesn’t allow a
form to beresized, but it lacks Minimize and Maximize buttons in the top-right corner. To
include thosebuttons, use the Fixed Single style. Sizable ToolWindow and Fixed
54
211719104072
ToolWindow styles aregenerally used for forms that need to float over and allow changes to be
made to the main forms.
User should also address the form’s start position. The available start position styles are:
Manual
Windows Default
CenterScreen
CenterOwner
The default style is Manual, which means that the form will appear in the same location at both
runtime and design time. Windows Default puts a form in the upper-left corner on the screen.
CenterScreen places a form in the center of the user’s screen regardless of the screen resolution.
CenterOwner places a form in the center of the owner form. An owner is a form on top of which
the current form is to appear. When no owner is specified, the form shows up in the center of
the desktop.
Before simply dropping controls on a form, consider what kind of data the control will oversee
and how the users will interact with that data. The guidelines provided below will help user
choose the best controls for a particular type of data.
The first rule of form controls is that they should have consistent characteristics, such as look,
feel, and size. Users shouldn't need to learn specific visual cues and usage parameters for each
control.
The text box controls should be the same height as the combo boxes. By default, the height
property of text boxes is different from that of the combo boxes. User should change the height
value of the text boxes to match that of the combo boxes (since the height property is read-only
in combo boxes). Obviously, this rule applies only to single-line text boxes.
User should use the proper controls for the data need to display. If user is displaying read-only
data, you should not use a text box and modify its properties so that other users can’t make
changes to its text. Instead, use a label. Text box controls should be used only for editable data.
55
211719104072
When there is a need to display fewer than five options in a list and the user has to choose only
one item, option buttons are the best choice. Many applications use combo boxes to display
such information, but from the user's standpoint, it’s much better to see all options at once
rather than having to scroll through the listings in a combo box.
Keep in mind that when users should be able to select more than one item from a small list of
selections, using check boxes is a good idea. As with option buttons, check boxes let users see
all options available at the same time, but check boxes also allow the selection of multiple items
from the list.
When need to display a larger number of items for users to choose from, it’s not feasible to use
option buttons or check boxes because of the amount of real estate they would take up on the
form. In such cases, display data either in combo boxes or list boxes to save space.use multiple-
selection list boxes to let users select more than one item at a time; combo boxes allow only one
item to be selected.
Developers sometimes use combo boxes and list boxes to display more than one column of
data; however, grid controls may be easier for users to understand (and easier to code).
When using labels next to corresponding controls, left-align the labels and follow label captions
with a colon for better readability. Also, align labels vertically to the corresponding controls.
Figure A provides an example of these label rules in action.
FIGURE A
Always set the BackStyle property of label controls to Transparent to make sure that labels have
the same BackColor as the parent form.
56
211719104072
Whenever there is a need to prevent users from using a control temporarily, it’s preferable to
disable the control rather than hide it. Disabling a control prevents the user from clicking it, but
it doesn’t significantly alter the way the form looks. Hiding controls may take the users by
surprise or lead them to believe that something is wrong with an application. When selecting
controls, also consider newer VB options, such as Tab Control, Tree View, Progress Bar, and
Toolbar, to improve the form layout and design.
57
211719104072
MENU DESIGN:
THEORY:
To start adding menu items to the application, open an existing project or start a new
project, then click on Tools in the menu bar of the Visual Basic IDE and select Menu
Editor. click on the Menu Editor, the Menu Editor dialog will appear. In the Menu Editor
dialog , key in the first item File in the caption text box. use the ampersand ( & ) sign in
front of F so that F will be underlined when it appears in the menu, and F will become the
hot key to initiate the action under this item by pressing the Alt key and the letter F. After
typing &File in the Caption text box, move to the name textbox to enter the name for this
menu item, type in menuFile here. Now, click the Next button and the menu item &File will
move into the empty space below, as shown in the following diagram:
58
211719104072
Then add in other menu items on the menu bar by following the same procedure, as shown
in the diagram below:
59
211719104072
Click Ok, the menu items will be shown on the menu bar of the form.
Now, proceed to add the sub menus. In the Menu Editor, click on the Insert button between
File and Exit and then click the right arrow key, and the dotted line will appear. This shows
the second level of the menu, or the submenu. Now key in the caption and the name. Repeat
the same procedure to add other submenu items. Here, we are adding New, Open, Save,
Save As and Exit.
60
211719104060
Now click the OK button and go back to the form. To see the dropped down
submenus click on the item File, as shown.
PRACTICE EXERCISE:
Personal
Detail
Branch wise
Detail
Mark
Mark Detail
Grade Detail
Exit
61
211719104060
62
211719104060
63
211719104060
In the Personal Information form add Menu to navigate to the Main Menu(Intro Form)
In the Mark form add Menu to navigate to the Grade Details(Grade Form)
In the Grade form add Menu to navigate to the Mark Details(Mark Form)
64
211719104060
CODING:
65
211719104060
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
End If
End Sub
Private Sub cmdmoveprev_Click()
Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.BOF Then
Adodc1.Recordset.MoveFirst
End If
End Sub
"'"MsgBoxcs
End Sub
66
211719104060
Unload Me
Load Intro
Intro.Show
End Sub
RESULT:
Thus,the data connectivity with front end tools has been executed successfully and the output
is verified.
67
211719104060
DATE:23-04-2021
AIM:
To implement case study using real life database application using SQL commands.
1. Create the DB for banking system source request the using SQL
3.Click add button and select oracle in ORA home 90 click finished
4.A 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
>>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 and design ms from in request format
ADODC CONTROL 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.
68
211719104060
Form2.Show
End Sub
Private Sub
EXIT_Click()
Unload Me
End Sub
Private Sub
69
211719104060
TRANSACTION_Click()
Form3.Show
End Sub
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
Private Sub
DELETE_Click()
Adodc1.Recordset.MovePrevious
End If
End Sub
70
211719104060
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
successfully"
End Sub
71
211719104060
Form2.Show
End Sub
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub
DEPOSIT_Click()
EndSub
PrivateSub
EXIT_Click()
UnloadMe
EndSub
72
211719104060
PrivateSub
HOME_Click()
Form1.Show End
WITHDRAW_Click()
Str(A)
Adodc1.Recordset.Save
Adodc1.Recordset.UPDATE
End Sub
73
RESULT:
Thus,the case study using real life database application has been executed successfully and
the output is verified.
74
EX.NO: 11 DISTRIBUTED DATABASE
DATE:30-04-2021
AIM:
Description:
A distributed database is a database in which storage devices are not all attached to a
common processing unit such as the CPU, controlled by a distributed database management
system. (together sometimes called a distributed database system). It may be stored in multiple
computers, located in the same physical location; or may be dispersed over a network of
interconnected computers. Unlike parallel systems, in which the processors are tightly coupled
and constitute a single database system, a distributed database system consists of loosely-coupled
sites that share no physical components.
There are two principal approaches to store a relation r in a distributed database system:
A) Replication
B) Fragmentation/Partitioning
A) Replication: In replication, the system maintains several identical replicas of the same relation
r in different sites.
B) Fragmentation: The relation r is fragmented into several relations r1, r2, r3......rn in such a way
that the actual relation could be reconstructed from the fragments and then the fragments are
scattered to different locations. There are basically two schemes of fragmentation:
Linked servers provide SQL Server the ability to access data from remote data sources. Using these
mechanisms, we can issue queries, perform data modifications and execute remote procedures.
We can use the T-SQL function OPENROWSET to query a remote data source without a linked
server.
75
Steps:
Create a linked server to another SQL Server instance using the T-SQL
procedure sp_addlinkedserver. The syntax of sp_addlinkedserver is
EXECsp_addlinkedserver
[@server= ] 'server'
, [ @provider= ] 'provider_name'
,[ @srvproduct= ] 'product_name' [
, [ @datasrc= ] 'data_source'
[ , [ @location= ] 'location' ]
[ , [ @provstr= ] 'provider_string'
76
[ , [ @catalog= ] 'catalog' ]
Parameter Description
Server Local name used for the linked server.
Product name of the OLE DB data source. For SQL Server instances, the
product_name
product_name is 'SQL Server'.
This is the unique programmatic identifier for the OLE DB provider. When not
provider_name specified, the provider name is the SQL Server data source. The explicit
provider_name for SQL Server is SQLNCLI (for Microsoft SQL Native Client
OLE DB Provider).
data_source This is the data source as interpreted by the OLE DB provider.
Location The location interpreted by the OLE DB provider.
provider_string The connection string specific to the OLE DB provider.
Catalog This varies from the database systems.
3. Add linked server definitions on each member server that contains the
connection information required to run distributed queries on the other
member servers. This gives a distributed partitioned view access to
data on the other servers.
4. Defining Distributed Partition Views:
After you create the member tables, you define a distributed partitioned view on
each member server, with each view having the same name. This
enables queries that reference the distributed partitioned view name to
run on one or more of the member servers. The system operates as if a
copy of the original table is on each member server, but each server
has only a member table and a distributed partitioned view.
Create the following distributed partitioned view:
CREATE VIEW Customers AS select statement
Queries:
1. Insert and
Display details in
77
into <tablename>
values(list of
values); select
*from
<tablename>;
select sum(totalstock) 'Total Books' from BooksView where price between 25 and
100
3. Update the book price of book No=1234 from $45 to $55 at site S3.
USE [S1]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
78
[ISBN] [uniqueidentifier] NOT NULL,
[ISBN] ASC
) ON [PRIMARY]
GO
GO
USE [S4]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
79
[State] [varchar](50) NULL,
[StoreNo] ASC
) ON [PRIMARY]
GO
GO
USE [S4]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
80
[Qty] [int] NULL
) ON [PRIMARY]
GO
GO
FOREIGN KEY([StoreNo])
GO
GO
81
insert into s4.dbo.BookStore
values(newid(),'LasVegas','CA','5677',80000);
82
select * from s4.dbo.BookStore
--Find the total number of books in stock where price is between $15 and $55
83
select * from s1.dbo.Stock union
--Find the total number of books in stock where price is between $15 and $55
group by bv.ISBN
group by bv.ISBN
84
RESULT:
Thus the distributed database has been executed successfully and the output is verified.
85
EX.NO:12 DEADLOCK DETECTION ALGORITHM FOR DISTRIBUTED
DATE: 07-05-2021
Aim:
To implement deadlock detection algorithm for distributed database using wait-for graph
Description:
T5 initiated at site S3
86
CODINGS:
Connected to:
varchar2(10));
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
87
SQL> insert into dd1
values('t3','x2','x7','s1');
1 row created.
1 row created.
1 row created.
1 row created.
t1 x1 x8 s1
t1 x6 x2 s2
t2 x4 x7 s2
t2 x5 s3
t3 x2 x7 s1
t4 x7 s2
t4 x8 x5 s3
t5 x3 x7 s3
8 rows selected.
SQL> ed dd1;
SQL> @dd1;
42 /
88
SELECT trans, lock1, wait
ERROR at line 3:
malformed
malformed
malformed
89
ORA-06550: line 26, column 1:
SQL> ed dd1;
SQL> @dd1;
42 /
ll(c) := ss.lock1;
SQL> ed dd1;
SQL> @dd1;
42 /
t1 x1 x8
t1 x6 x2
t2 x4 x7
t2 x5
t3 x2 x7
t4 x7
t4 x8 x5
t5 x3 x7
x5<-x5deadlock occured
90
x2<-x2deadlock occured
x7<-x7deadlock occured
x7<-x7deadlock occured
x7<-x7deadlock occured
x8<-x8deadlock occured
SQL> ed dd2;
SQL> @dd2;
37 /
t1 x1 x8
t3 x2 x7
SQL> ed dd3;
SQL> ed dd3;
SQL> @dd3;
40 /
ERROR at line 3:
91
PL/SQL: Item ignored
malformed
malformed
malformed
malformed
SQL> ed dd3;
SQL> @dd3;
41 /
92
*
ERROR at line 3:
malformed
malformed
malformed
93
malformed
SQL> ed dd3;
SQL> @dd3;
41 /
t1 x6 x2
t2 x4 x7
t4 x7
x7<-x7deadlock occured
no deadlock
SQL> ed dd4;
SQL> @dd4;
37 /
ERROR at line 3:
94
ORA-06550: line 19, column 15:
malformed
malformed
malformed
malformed
SQL> ed dd4;
SQL> @dd4;
37 /
t2 x5
t4 x8 x5
t5 x3 x7
95
x5<-x5deadlock occured
SQL> ed dd1;
SQL> @dd1;
42 /
t1 x1 x8
t1 x6 x2
t2 x4 x7
t2 x5
t3 x2 x7
t4 x7
t4 x8 x5
t5 x3 x7
x5<-x5deadlock occured
x2<-x2deadlock occured
x7<-x7deadlock occured
x7<-x7deadlock occured
x7<-x7deadlock occured
x8<-x8deadlock occured
SQL>
DD1 :
declare
cursor c1 is
FROM dd1;
96
type c_list is varray(20) of dd1.loc%type;
ll c_list:=c_list();
l2 c_list1:=c_list1();
t c_list:=c_list();
c integer := 0;
d integer :=0;
f integer :=0;
ss c1%rowtype;
begin
open c1;
loop
c := c+1;
ll.extend;
ll(c) := ss.loc;
f := f+1;
t.extend;
t(f) := ss.trans;
d :=d+1;
l2.extend;
l2(d) := ss.wait;
dbms_output.put_line(ss.trans||' '||ss.loc||'
97
'||ss.wait); end loop;
for i in 1 .. c loop
for j in 1 .. d loop
if(ll(i) != '-')then
dbms_output.put_line(ll(i)||'<-'||l2(j)||'deadlock occured');
end if;
end if;
end loop;
end loop;
end;
DD2:
declare
cursor c1 is
FROM dd1
WHERE Site='s1';
ll c_list:=c_list();
l2 c_list1:=c_list1();
t c_list:=c_list();
c integer := 0;
d integer :=0;
98
ss c1%rowtype;
begin
open c1;
loop
c := c+1;
ll.extend;
ll(c) := ss.loc;
d :=d+1;
l2.extend;
l2(d) := ss.wait;
end loop;
for i in 1 .. c loop
for j in 1 .. d loop
dbms_output.put_line(ll(i)||'<-'||l2(j)||'deadlock occured');
end if;
end loop;
end loop;
end;
DD3:
declare
cursor c1 is
99
SELECT trans, loc, wait
FROM dd1
WHERE Site='s2';
ll c_list:=c_list();
l2 c_list1:=c_list1();
t c_list:=c_list();
c integer := 0;
d integer :=0;
e integer :=0;
ss c1%rowtype;
begin
open c1;
loop
c := c+1;
ll.extend;
ll(c) := ss.loc;
d :=d+1;
l2.extend;
l2(d) := ss.wait;
100
end loop;
for i in 1 .. c loop
for j in 1 .. d loop
dbms_output.put_line(ll(i)||'<-'||l2(j)||'deadlock occured');
end if;
end loop;
end loop;
if (e = 0) then
end if;
end;
DD4:
declare
cursor c1 is
FROM dd1
WHERE Site='s3';
ll c_list:=c_list();
l2 c_list1:=c_list1();
t c_list:=c_list();
c integer := 0;
d integer :=0;
101
ss c1%rowtype;
begin
open c1;
loop
c := c+1;
ll.extend;
ll(c) := ss.loc;
d :=d+1;
l2.extend;
l2(d) := ss.wait;
end loop;
for i in 1 .. c loop
for j in 1 .. d loop
dbms_output.put_line(ll(i)||'<-'||l2(j)||'deadlock occured');
end if;
end loop;
RESULT:
Thus the program to execute deadlock detection algorithm for distributed database using
102