CP4152 DBP Lab Manual (ME)
CP4152 DBP Lab Manual (ME)
LABORATORY RECORD
Name : ----------------------------------------------------
Subject : ---------------------------------------
Year/Semester : ---------------------------------------
1
ROEVER ENGINEERING COLLEGE
ELAMBALUR, PERAMBALUR – 621 220.
BONAFIDE CERTIFICATE
Certified that this is the Bonafide record of Practical done in
Held on………….……
2
CONTENTS
EX.
PAGE
DATE NAME OF THE EXPERIMENT NO.
Marks SIGNATURE
NO.
3
EX.NO:1
Date:
AIM:
To create the database and write DDL, DML and TCL Queries to retrieve information from the
database.
ALGORITHM:
2. Using create command create a table which contain the attribute of employee.
3. Execute various DDL, DML and TCL commands to retrieve information from the database.
4. Stop.
DDL COMMANDS
CREATE TABLE
CREATE TABLE ……AS SELECT
ALTER TABLE………ADD
ALTER TABLE………MODIFY
DROP TABLE
RENAME
1.CREATE TABLE
Syntax: Create table tablename (column_name1 data_ type constraints, column_name2 data_
type constraints …)
4
SQL> create table emp(eno number(10),ename varchar2(10),dno number(10),sal number(10),jobid
varchar2(10),mgrid varchar2(10));
Table created
2.1 Syntax For Create A from An Existing Table With Selected Fields
SQL> create table <traget table name> select empno, ename from <source table name>;
SQL> create table emp2 as select empno, ename from emp;
Table created.
SQL> desc emp2
Name Null? Type
------------------ -------- ----------------------
EMPNO NUMBER (4)
EMPNAME VARCHAR2(10)
3.DESC
This is used to view the structure of the table.
SQL> desc emp;
5
Name Null? Type
----------------------------------------- -------- ----------------------------
ENO NUMBER(10)
ENAME VARCHAR2(10)
DNO NUMBER(10)
SAL NUMBER(10)
JOBID VARCHAR2(10)
MGRID VARCHAR2(10)
3.ALTER TABLE
3.1ADD
SQL> alter table emp add(primary key(eno), addr varchar2(10));
Table altered.
Table altered.
6
Name Null? Type
----------------------------------------- -------- ----------------------------
ENO NOT NULL NUMBER(10)
ENAME VARCHAR2(10)
DNO NUMBER(10)
SAL NUMBER(10)
JOBID CHAR(20)
MGRID VARCHAR2(10)
ADDR VARCHAR2(10)
PHNO NUMBER(5)
Table altered.
MGRID VARCHAR2(10)
ADDR VARCHAR2(10)
PHNO VARCHAR2(10)
4. DROP TABLE
Table altered.
7
----------------------------------------- -------- ----------------------------
ENO NOT NULL NUMBER(10)
ENAME VARCHAR2(10)
DNO NUMBER(10)
SAL NUMBER(10)
JOBID CHAR(20)
MGRID VARCHAR2(10)
ADDR VARCHAR2(10)
Table altered.
Table dropped.
5. TRUNCATE TABLE
If there is no further use of records stored in a table and the structure has to be retained then the
records alone can be deleted.
8
Syntax: TRUNCATE TABLE <TABLE NAME>;
Table truncated.
6. RENAME
Can rename the table provided you are the owner of the table.
The generalized syntax is:
RENAME old_table_name TO new_table_name;
Example:
SQL > RENAME emp TO Employee;
Table renamed.
DML COMMANDS
1. INSERT
2. UPDATE
3. DELETE
4. SELECT
1.INSERT COMMAND
9
SQL> insert into emp values (1,‟A‟,‟AP‟,2, 5000);
1 row created.
1.2 Inserting more than one record using a single insert commands:
Syntax: insert into <table name> values (&col1, &col2, ….)
SQL> /
Enter value for empno: 3
Enter value for ename: C
Enter value for job: ASP
Enter value for deptno: 2
Enter value for sal: 15000
SQL> /
Enter value for empno: 4
Enter value for ename: D
Enter value for job: ASP
Enter value for deptno: 1
Enter value for sal: 20000
old 1: insert into emp values(&empno,'&ename','&job',&deptno,&sal)
new 1: insert into emp values(4,'D','ASP',1,20000)
1 row created.
SQL> /
Enter value for empno: 5
Enter value for ename: E
Enter value for job: PROF
Enter value for deptno: 2
Enter value for sal: 50000
old 1: insert into emp values(&empno,'&ename','&job',&deptno,&sal)
new 1: insert into emp values(5,'E','PROF',2,50000)
1 row created.
10
2.SELECT COMMANDS
EMPNAME JOB
------------------- ----------------
A AP
B AP
C ASP
D ASP
E PROF
6 rows selected.
Query 2:Display deptno from the table employee avoiding the duplicated values.
DEPTNO
------------
1
2
To select specific rows from a table we include „where‟ clause in the select command.
It can appear only after the „from‟ clause.
2 rows updated.
4. DELETE
Syntax: Delete from table where conditions;
Query 5: Delete only those who are working as Professor
SQL> delete from emp where job='PROF';
1 row deleted.
5. CONCATENATION
SQL> select empname || ' is working as ' || job ||' AS "PROFESSION" from emp;
PROFESSION
----------------------------------
A is working as AP.
B is working as AP.
C is working as ASP.
13
D is working as ASP
DCL COMMANDS
1. GRANT COMMAND
Syntax:
Grant < database_priv [database_priv…..] > to <user_name> identified by
<password> [,<password…..];
Grant <object_priv> | All on <object> to <user | public> [With Grant Option ];
2.REVOKE COMMAND
Syntax:
Revoke <database_priv> from <user [, user ] >;
Revoke <object_priv> on <object> from < user | public >;
<database_priv> -- Specifies the system level priveleges to be granted to the users or roles.
This includes create / alter / delete any object of the system.
<object_priv> -- Specifies the actions such as alter / delete / insert / references / execute /
select / update for tables.
[ With Grant Option ] – Allows the recipient user to give further grants on the objects.
The privileges can be granted to different users by specifying their names or to all users by
using the “Public” option.
TCL COMMANDS
Syntax:
1. SAVEPOINT:
14
SAVEPOINT <SAVE POINT NAME>;
2.ROLLBACK:
ROLL BACK <SAVE POINT NAME>;
3.COMMIT:
Commit;
Q1: Develop a query to grant all privileges of employees table into departments table
Ans:
SQL> Grant all on employees to departments;
Grant succeeded.
Q2: Develop a query to grant some privileges of employees table into departments table
Ans:
SQL> Grant select, update , insert on departments to departments with grant
option;
Grant succeeded.
Q3: Develop a query to revoke all privileges of employees table from departments table
Ans:
SQL> Revoke all on employees from departments;
Revoke succeeded.
Q4: Develop a query to revoke some privileges of employees table from departments table
Ans:
SQL> Revoke select, update , insert on departments from departments;
Revoke succeeded.
15
EMPNO ENAME JOB DEPTNO SAL
---------- -------------------- ------------- ---------- ----------
1 Manju AP 1 10000
2 Arav ASP 2 15000
3 Gowtham ASP 1 15000
4 Karthik Prof 2 30000
5 Anu AP 1 10000
16
EX.NO:2
Date:
DATABASE QUERYING - SIMPLE QUERIES,NESTED QUERIES,SUBQUERIES AND
JOINS
AIM:
To perform Simple queries, Nested queries, Sub queries and Joins using DML command.
1.NESTED QUERIES:
Nesting of queries one within another is known as a nested query.
2.SUB QUERIES:
The query within another is known as a sub query. A statement containing sub query is
called parent statement. The rows returned by sub query are used by the parent statement.
Types
1. Sub queries that return several values
Sub queries can also return more than one value. Such results should be made use along
with the operators in and any.
2. Multiple queries
Here more than one sub query is used. These multiple sub queries are combined by
means of „and‟ & „or‟ keywords
3. Correlated sub query
A sub query is evaluated once for the entire parent statement whereas a correlated Sub
query is evaluated once per row processed by the parent statement.
BETWEEN:
SQL includes a between comparison operator to specify that a value be less than or equal to
some value and greater than or equal to some other value.
Q1: Find the name of the employees who are receiving salary between 12000 and 25000
SQL > select employee name
from employee
17
where sal between 12000 and 25000;
Sample Output:
no rows selected;
Q2: Find the name of the employees who are receiving salary between 15000 and 30000
SQL > select employee name
from employee
where sal between 15000 and 30000;
Sample Output:
EMPNAME
------------------
B
C
D
AND OR:
The keywords AND and OR are Boolean operators used to specify compound conditions in
the where clause.
Q3: Find the name of the employees who are receiving salary greater than 5000 or all
employees with salary less than 40000 but greater than 10000
SQL > SQL> select empname from emp1718 where sal >5000 and(sal>10000 and
sal<40000);
EMPNAME
--------------------
C
D
LIKE
The LIKE operator is used to filter the result set based on a string pattern. It is always
used in the where clause.
Q4: Find the names of the employees where the first letter starting with A;
SQL > select empname
from employee
18
where empname like ‘a%’
Sample Output:
EMPNAME
-------------------
Anu
NOT LIKE
Q5:Display all the details of the records whose employee name does not starts with ‗A‘.
IN AND NOT IN
IN: The in connective tests for set membership.
Q6: Display the Name, Employee Number present in the department number 1.
SQL > select empno,empname
from employee
where deptno in(‘1’);
Sample Output:
EMPNO EMPNAME
------------ -----------------
2 B
4 D
NOT IN: The not in connective tests for the absence of set membership.
Q7: Display the Name, Employee Number who are not present in the department
number 1
SQL > select empno,empname
from employee
where deptno not in(‘1’);
19
Sample Output:
EMPNO EMPNAME
------------ -----------------
1 A
3 C
HAVING
Q8:Display department wise total salary of all employees except for department 3.
DEPTNO SUM(SAL)
---------- ----------
1 70000
2 10000
ORDERBY
Query 9: List the records in the emp table orderby salary in ascending order.
Ans:
SQL> select * from emp order by sal;
Q10: List the records in the emp table orderby salary in descending order.
Ans:
SQL> select * from emp order by sal desc;
SQL> select ename from emp where job= (select job from emp where ename='Arav');
ENAME
--------------
Arav
Gowtham
Q12: Issue a query to display information about employees who earn more than
any employee in dept 1.
SQL> select * from emp where sal>(select max(sal) from emp where empno=1);
Q13: Display the details of those who draw the salary greater than the average salary.
SQL> select distinct * from emp x where x.sal >= (select avg(sal) from emp);
21
NUMERIC FUNCTIONS
Q14:
SQL> select abs(-20) result from dual;
RESULT
---------
20
Q15:
SQL> select power (2,10) result from dual;
RESULT
---------
1024
Q16:
SQL> select round(15.359,2) result from dual;
RESULT
---------
15.36
Q17:
SQL> select sqrt (36) result from dual;
RESULT
---------
6
Q18:
Sql>select mod(5,2) from dual;
RESULT
---------
1
22
STRING FUNCTIONS
Q18:
SQL> select lower('ORACLE') result from dual;
RESULT
------
oracle
Q19:
RESULT
------
ORACLE
Q20:
RESULT
------
Oracle
Q21:
RESULT
-----
oracle
Q22:
RESULT
----------
####oracle
23
Q23:
RESULT
----------
oracle^^^^
BUILT-IN DATATYPES IN SQL
Table created.
1 row created.
DATE1
---------
29-JUN-18
JOIN QUERIES:
The purpose of a join concept is to combine data spread across tables. A join is actually
performed by the “where‟ clause which combines specified rows of tables.
Syntax:
24
Select columns from table1, table2 where logical expression;
Tables used
SQL> select * from emp;
1.SIMPLE JOIN
1. EQUI-JOIN
Q1: Display the employee details, departments that the departments are same in both the
emp and dept.
1.2.NON-EQUIJOIN
25
Q2: Display the employee details, departments that the departments are not same in both
the emp and dept.
SQL > select * from emp,dept where emp.deptno!=dept.deptno;
3.INNER JOIN
Inner join returns the matching rows from the tables that are being joined.
Syntax:
SELECT table1.column1, table2.column2...
FROM table1
INNER JOIN table2
ON table1.common_field = table2.common_field;
Consider the following two relations :
i) Employee(Emp_name, City)
26
EMP_NAME CITY
Hari Pune
OM Mumbai
Smith Nashik
Jay Solapur
EMPLOYEE
i)
EMPLOYEE_SALARY
OM IT 7000
Hill Computer 8000
Jay IT 5000
Example:
EMP_NAME SALARY
27
Hari 10000
OM 7000
Jay 5000
4.OUTER JOIN
An outer join returns all the rows returned by simple join as well as those rows from one
table that do not match any row from the table. The symbol (+) represents outer join.
4.1 LEFT OUTER JOIN
The SQL LEFT JOIN returns all rows from the left table, even if there are no matches in
the right table.
Syntax:
SELECT table1.column1, table2.column2...
FROM table1
LEFT OUTER JOIN table2
ON table1.common_field = table2.common_field;
EMP_NAME SALARY
Hari 10000
OM 7000
Smith
Jay 5000
The SQL RIGHT JOIN returns all rows from the right table, even if there are no matches
in the left table.
Syntax:
28
SELECT table1.column1, table2.column2...
FROM table1
RIGHT OUTER JOIN table2
ON table1.common_field = table2.common_field;
The SQL FULL JOIN combines the results of both left and right outer joins.
Syntax:
SELECT table1.column1, table2.column2...
FROM table1
FULL OUTER JOIN table2
ON table1.common_filed = table2.common_field;
29
OM Mumbai 7000
Smith Nashik
Jay Solapur 5000
Hill 8000
CONSTRAINTS
1. NOT NULL CONSTRAINT
Ensures that a column cannot have NULL value.
2. DEFAULT CONSTRAINT
Provides a default value for a column when none is specified.
3. UNIQUE CONSTRAINT
Ensures that all values in a column are different.
4. PRIMARY KEY
Uniquely identified each rows/records in a database table.
5. FOREIGN KEY
Uniquely identified a rows/records in any another database table.
6. CHECK CONSTRAINT
The CHECK constraint ensures that all values in a column satisfy certain conditions.
Queries
Q1. Create the employee table with NOT NULL and PRIMARY KEY constraint.
Ans:
SQL > CREATE TABLE EMPLOYEE (ID INT NOT NULL, NAME VARCHAR (20) NOT
NULL, AGE INT NOT NULL, ADDRESS CHAR (25), SALARY DECIMAL (18, 2),
PRIMARY KEY (ID));
Table created.
SQL > desc employee;
Q2. Alter the NOT NULL constraint for the employee table
Ans:
SQL > ALTER TABLE CUSTOMERS MODIFY SALARY DECIMAL (18, 2) NOT NULL;
Table altered.
SQL > desc employee;
Q3.Create the employee table using Default constraint and insert values into the table.
Ans:
SQL > CREATE TABLE EMPLOYEE (ID INT NOT NULL, NAME VARCHAR (20) NOT
NULL, AGE INT NOT NULL, ADDRESS CHAR (25) , SALARY DECIMAL (18, 2)
DEFAULT 5000.00, PRIMARY KEY (ID));
Table created.
SQL > INSERT into employee values ('&ID ',‟&NAME‟, &AGE , '&ADDRESS', &SALARY);
Old 1: insert into employee values ('&id ',‟&name‟, &age, '&address', &salary);
31
New 1: insert into employee values (01,‟Arav‟, 24,‟New street‟, 5000);
SQL > INSERT into employee values ('&ID ',‟&NAME‟, &AGE, '&ADDRESS', &SALARY);
Old 1: insert into employee values ('&id ',‟&name‟, &age, '&address', &salary);
SQL > /
Enter value for ID: 02
Old 1: insert into employee values ('&id ',‟&name‟, &age, '&address', &salary);
ERROR at line 1:
Q6.Create the employee database in which the age of the employee should be above 25
Ans:
SQL > CREATE TABLE EMPLOYEE (ID INT NOT NULL, NAME VARCHAR (20)
UNIQUE, AGE INT NOT NULL CHECK (AGE>25), ADDRESS CHAR (25), SALARY
DECIMAL (18, 2), PRIMARY KEY (ID));
Table created.
SQL > INSERT into employee values ('&ID ',‟&NAME‟, &AGE, '&ADDRESS', &SALARY);
Old 1: insert into employee values ('&id ',‟&name‟, &age, '&address', &salary);
33
ERROR at line 1:
AGGREGATE FUNCTIONS:
Functions that take a collection of values as input and return a single value.
SQL offers five built-in aggregate functions
1. Average : avg
2. Minimum :min
3. Maximum : max
4. Total : sum
5. Count : count
1) Avg
Syntax: avg([Distinct | All | n)
Purpose : Returns average value of n,ignoring null values.
Example :
SQL > select avg(salary) as Average Salary
from employee;
Sample Output:
AVERAGE SALARY
---------------------------
16000
2) Min
Syntax: min ([Distinct | All | expression)
34
Purpose : Returns minimum value of expression
Q2: Determine the minimum salary and rename the column as min_salary.
SQL > select min(salary) as Minimum Salary
from employee;
Sample Output:
MINIMUM SALARY
---------------------------
10000
3) Max
Q3: Determine the maximum salary and rename the column as max_salary.
Syntax: max ([Distinct | All | expression)
Purpose : Returns maximum value of expression
Example :
SQL > select max (salary) as Maximum Salary
from employee;
Sample Output:
MAXIMUM SALARY
---------------------------
30000
4) Sum
Syntax: sum ([Distinct | All | n)
Purpose : Returns sum of values of n
Example :
SQL > select sum (salary) as Total
from employee;
Sample Output:
TOTAL
---------------------------
80000
35
count(*) – It counts all, inclusive of duplicates and nulls.
count(col_name)– It avoids null value.
count(distinct col_name) – It avoids the repeated and null values.
NO.OF DEPT
--------------------------
4
COUNT(*)
-------------
4
SET OPERATIONS
CREATE PRODUCT TABLE
SQL> create table product(prodname varchar2(30), prodno varchar2(10));
Table created.
SQL> select * from product;
PRODNAME PRODNO
------------------------------ ----------
table 10001
chair 10010
desk 10110
cot 11110
sofa 10010
36
tvstand 11010
PRODNAME
------------------------------
chair
sofa
INTERSECT
SQL> select prodname from product where prodno=11110 intersect
select prodname from sale where prodno=11110;
PRODNAME
------------------------------
cot
NESTED QUERIES
37
SQL> select * from sstud1;
SNAME PLACE
-------------------- --------------------
prajan chennai
anand chennai
kumar chennai
ravi Chennai
SQL> select sname from sstud1 where sstud1.sname in ( select sstud2.sname from sstud2 );
SNAME
--------------------
anand
prajan
ravi
SQL> select sname from sstud1 where sstud1.sname not in ( select sstud2.sname from sstud2 );
SNAME
--------------------
Kumar
38
SQL> select sname from sstud2 where marks > some(select marks from sstud2 where
dept='cse');
SNAME
--------------------
prajan
SQL> select sname from sstud2 where marks >= some (select marks from sstud2 where
dept='cse' );
SNAME
--------------------
prajan
vasu
SQL> select sname from sstud2 where marks > any ( select marks from sstud2 where dept='cse'
);
SNAME
--------------------
Prajan
SQL> select sname from sstud2 where marks >= any ( select marks from sstud2 where dept='cse'
);
SNAME
--------------------
prajan
vasu
SQL> select sname from sstud2 where marks > all ( select marks from sstud2 where dept='cse' );
no rows selected
39
SQL> select sname from sstud2 where marks < all ( select marks from sstud2 where dept='cse' );
SNAME
--------------------
anand
ravi
SQL> select sname from sstud1 where exists ( select sstud2.sname from sstud2 where
sstud1.sname=sstud2.sname );
SNAME
--------------------
prajan
anand
ravi
SQL> select sname from sstud1 where not exists ( select sstud2.sname from sstud2 where
sstud1.sname=sstud2.sname );
SNAME
--------------------
kumar
40
EX.NO:3
Date:
AIM:
1. VIEWS:
A view is a “virtual table” or a “stored query” which takes the Sample Output of a query
and treats it as a table. The table upon which a view is created is called as base table.
2. SYNONYMS:
A synonym is an alias, that is, a form of shorthand used to simplify the task of
referencing a database object.
Creating Synonym:
Syntax:
CREATE [PUBLIC] SYNONYM synonym_name FOR object_name;
Drop Synonym:
Syntax:
DROP SYNONYM synonym_name;
41
DROP PUBLIC SYNONYM synonym_name;
Rename Synonym:
Syntax:
RENAME old_synonym_name TO new_synonym_name;
3. SEQUENCES:
Sequences are used to generate unique, sequential integer values that are used as primary
key values in database tables. The sequence of numbers can be generated in either
ascending or descending order.
Creating Sequences:
Syntax:
CREATE SEQUENCE <sequence name>
[INCREMENT BY <number>]
[START WITH <start value number>]
[MAXVALUE <MAXIMUM VLAUE NUMBER>]
[NOMAXVALUE]
[MINVALUE <minimum value number>]
[CYCLE]
[NOCYCLE]
[CACHE <number of sequence value to cache>]
[NOCACHE]
[ORDER]
[NOORDER];
Drop Sequences:
Syntax:
DROP SEQUENCE <sequence name>;
4. INDEXES
42
An index can be created in a table to find data more quickly and efficiently. The users
cannot see the indexes; they are just used to speed up searches/queries.
Create Index:
Syntax:
CREATE INDEX index_name
ON table_name(column_name)
Q1: The organization wants to display only the details of the employees those who are ASP.
(Horizontal portioning)
45
Q10. Alter the maximum value of the order number.
Ans:
SQL> ALTER SEQUENCE order_number_sequence MAXVALUE 200000000;
Sequence altered.
Q11. Display the names and properties of the Sequences.
Ans:
SQL> SELECT * from USER_SEQUENCES;
SEQUENCE_NAME MIN_VALUE MAX_VALUE INCRE C O CACHE_SIZE LAST_N
-------------------------- ----------------- ------------------ --------- -- --- ------------------- -------------
ORDER_NUMBER_ 1 200000000 1 Y N 10 3
SEQUENCE
47
EX.NO.4
Date:
CURSORS
A cursor is a pointer to this context area. PL/SQL controls the context area through a
cursor.
A cursor holds the rows (one or more) returned by a SQL statement. The set of rows the
cursor holds is referred to as the active set.
There are two types of cursors −
1. Implicit cursors
2. Explicit cursors
1. IMPLICIT CURSORS
Implicit cursors are automatically created by Oracle whenever an SQL statement is
executed, when there is no explicit cursor for the statement. Programmers cannot control
the implicit cursors and the information in it.
Whenever a DML statement (INSERT, UPDATE and DELETE) is issued, an implicit
cursor is associated with this statement.
For INSERT operations, the cursor holds the data that needs to be inserted. For
UPDATE and DELETE operations, the cursor identifies the rows that would be
affected.
48
UPDATE, or DELETE statement affected no rows, or a SELECT INTO
statement returned no rows. Otherwise, it returns FALSE.
%ISOPEN
3 Always returns FALSE for implicit cursors, because Oracle closes the SQL
cursor automatically after executing its associated SQL statement.
%ROWCOUNT
4 Returns the number of rows affected by an INSERT, UPDATE, or
DELETE statement, or returned by a SELECT INTO statement.
Q1: Write SQL query to increase the salary of each customer by 500 using cursors.
DECLARE
total_rows number(2);
BEGIN
UPDATE customers
IF sql%notfound THEN
total_rows := sql%rowcount;
49
dbms_Sample Output.put_line( total_rows || ' customers selected ');
END IF;
END;
Sample Output:
6 customers selected
2.EXPLICIT CURSORS
Explicit cursors are programmer-defined cursors for gaining more control over
the context area.
An explicit cursor should be defined in the declaration section of the PL/SQL Block. It is
created on a SELECT Statement which returns more than one row.
The syntax for creating an explicit cursor is −
CURSOR cursor_name IS select_statement;
50
3. Fetching the cursor for retrieving the data
4. Closing the cursor to release the allocated memory
2.1 Declaring the Cursor
Declaring the cursor defines the cursor with a name and the associated SELECT statement.
Example −
CURSOR c_customers IS
OPEN c_customers;
2.3 Fetching the Cursor
Fetching the cursor involves accessing one row at a time.
Example
CLOSE c_customers;
Q2: Write query for displaying customer details using explicit cursors
DECLARE
c_id customers.id%type;
c_name customerS.No.ame%type;
c_addr customers.address%type;
CURSOR c_customers is
51
BEGIN
OPEN c_customers;
LOOP
END LOOP;
CLOSE c_customers;
END;
Ouput:
1 Ramesh Ahmedabad
2 Khilan Delhi
3 kaushik Kota
4 Chaitali Mumbai
5 Hardik Bhopal
6 Komal MP
SQL> create table bill (name varchar2(10), address varchar2(20), city varchar2(20), unit
number(10));
Table created.
SQL> /
Enter value for name: nithya
Enter value for addess: Lakshmi nagar
Enter value for city: sivakasi
Enter value for unit: 200
old 1: insert into bill values('&name','&addess','&city','&unit')
new 1: insert into bill values('nithya','Lakshmi nagar','sivakasi','200')
1 row created.
SQL> /
Enter value for name: maya
Enter value for addess: housing board
Enter value for city: sivakasi
Enter value for unit: 300
old 1: insert into bill values('&name','&addess','&city','&unit')
new 1: insert into bill values('maya','housing board','sivakasi','300')
1 row created.
SQL> /
Enter value for name: jeeva
Enter value for addess: RRR nagar
Enter value for city: sivaganagai
Enter value for unit: 400
old 1: insert into bill values('&name','&addess','&city','&unit')
new 1: insert into bill values('jeeva','RRR nagar','sivaganagai','400')
1 row created.
3 b bill %ROWTYPE;
4 begin
5 open c;
7 loop
8 fetch c into b;
10 exit;
11 else
12 if(b.unit<=100) then
20 else
22 end if;
54
23 end if;
24 end loop;
25 close c;
26 end;
27 /
Sample Output:
55
EX.NO.5
Date:
PL/SQL
Syntax:
A procedure is a block that can take parameters (sometimes referred to as
arguments) and be invoked.
Procedures promote reusability and maintainability. Once validated, they can be used
in number of applications. If the definition changes, only the procedure are affected, this
greatly simplifies maintenance.
Modularized program development:
· Group logically related statements within blocks.
· Nest sub-blocks inside larger blocks to build powerful programs.
· Break down a complex problem into a set of manageable well defined logical
modules and implement the modules with blocks.
56
environment after execution.
RETURN: It is the data type of the function‟s return value because every function must
return a value, this clause is required.
PROCEDURES
Syntax:
create or replace procedure <procedure name> (argument {in,out,inout}
datatype ) {is,as} variable declaration;
constant declaration;
begin
PL/SQL subprogram body;
exception
exception
PL/SQL block;
end;
EXECUTION
SETTING SERVERSAMPLE OUTPUT ON:
SQL> SET SERVERSAMPLE OUTPUT ON
57
Q2) Procedure Using Notational Parameters:
Sample Output:
Procedure created.
SQL> VARIABLE T NUMBER
SQL> EXEC PROC2(33,66,:T)
PL/SQL procedure successfully completed.
SQL> PRINT T
T
----------
99
58
c:=mod(a,b);
if(c=0) then
dbms_Sample Output.put_line('GCD is');
dbms_Sample Output.put_line(b);
else
dbms_Sample Output.put_line('GCD is');
dbms_Sample Output.put_line(c);
end if;
else
d:=mod(b,a);
if(d=0) then
dbms_Sample Output.put_line('GCD is');
dbms_Sample Output.put_line(a);
else
dbms_Sample Output.put_line('GCD is');
dbms_Sample Output.put_line(d);
end if;
end if;
end;
/
SAMPLE OUTPUT:
Enter value for a: 8
old 8: a:=&a;
new 8: a:=8;
Enter value for b: 16
old 9: b:=&b;
new 9: b:=16;
Procedure created.
SQL> set serverSample Output on;
SQL> execute pro;
59
GCD is
8
PL/SQL procedure successfully completed.
TABLES USED:
SQL> select * from items;
ITEMID ACTUALPRICE ORDID PRDID
--------- ----------- -------- ---------
101 2000 500 201
102 3000 1600 202
103 4000 600 202
Q4. Selected Record’s Price Is Incremented By 500, Executing the Procedure Created And
Displaying The Updated Table
PROGRAM:
SQL> create procedure itsum(identity number, total number) is price number;
2 null_price exception;
3 begin
4 select actualprice into price from items where itemid=identity;
5 if price is null then
6 raise null_price;
7 else
8 update items set actualprice=actualprice+total where itemid=identity;
9 end if;
10 exception
11 when null_price then
12 dbms_Sample Output.put_line('price is null');
13 end;
14 /
Procedure created.
60
SQL> exec itsum(101, 500);
PL/SQL procedure successfully completed.
SQL> declare
2 a number;
3 b number;
4 begin
5 zzz(101,b);
6 dbms_Sample Output.put_line('The value of b is '|| b);
7 end;
8 /
The value of b is 100
PL/SQL procedure successfully completed.
SQL> declare
2 a number:=7;
62
3 begin
4 itit(a);
5 dbms_Sample Output.put_line(„The updated value is „||a);
6 end;
7 /
The updated value is 8
PL/SQL procedure successfully completed.
Q8. Write a procedure to calculate total for the all the students and pass regno, mark1, &
mark2 as arguments.
PROCEDURE:
1 Develop a query to create a table named itstudent2 and insert values into them
2 Develop a procedure p1 with regno, mark1, & mark2 as arguments.
3 Calculate the total and update the total value into the itstudent2 table
SQL> /
Enter value for a: 112
Enter value for b: siva
63
Enter value for c: 99
Enter value for d: 90
Old 2: values(&a,'&b',&c,&d)
New 2: values(112,'siva',99,90)
1 row created.
SQL> declare
2 cursor c1 is select * from itstudent2;
3 rec itstudent2 % rowtype;
4 begin
64
5 open c1;
6 loop
7 fetch c1 into rec;
8 exit when c1%notfound;
9 p1(rec.regno,rec.mark1,rec.mark2);
10 end loop;
11 close c1;
12 end;
13 /
SAMPLE OUTPUT:
Q9: Write a PL/SQL procedure called MULTI_TABLE that takes two numbers as parameter and
displays the multiplication of the first parameter till the second parameter.
PROGRAM :
//p2.sql
create or replace procedure multi_table (a number, b number)
as mul number;
begin
for i in 1. .b loop
mul : = a * i;
dbms_Sample Output.put_line (a || „*‟ || i || „=‟ ||
mul);
end loop;
65
end;
//pq2.sql
declare
a number; b number;
begin
a:=&a;
b:=&b;
multi_table(a,b);
end;
SAMPLE OUTPUT:
SQL> @p2.sql;
Procedure created.
SQL> @pq2.sql;
Enter value for a: 4
old 5: a:=&a; new 5: a:=4;
Enter value for b: 3
old 6: b:=&b; new 6: b:=3;
4*1=4
4*2=8
4*3=12
66
mempno; end;
/
//pq3.sql
declare
cursor c1 is select * from emp;
rec emp % rowtype;
begin
open c1;
loop
fetch c1 into rec;
exit when c1%notfound;
raisal(rec.empno,10);
end loop;
close
c1;
end;
/
SAMPLE OUTPUT:
SQL> @p3.sql;
Procedure created.
SQL> @pq3.sql;
67
PL/SQL procedure successfully completed.
FUNCTIONS
Syntax:
create or replace function <function name> (argument in datatype,……) return datatype
{is,as} variable declaration;
constant declaration;
begin
PL/SQL subprogram body;
exception
exception
PL/SQL block;
end;
TABLES USED:
SQL>select * from ittrain;
TNO TFARE
--------- ------------
1001 550
68
1002 600
SQL> declare
2 total number;
3 begin
4 total:=trainfn (1001);
5 dbms_Sample Output.put_line('Train fare is Rs. '||total);
6 end;
7 /
Sample Output:
Function created.
SQL> declare
2 a number:=7;
3 f number(10);
4 begin
5 f:=itfact(a);
6 dbms_Sample Output.put_line(„The factorial of the given number is‟||f);
7 end;
8 /
Q3: Write a PL/SQL function CheckDiv that takes two numbers as arguments and returns the
values 1 if the first argument passed to it is divisible by the second argument, else will return the
value 0;
PROGRAM:
//p.sql
create or replace function checkdiv (n1 number, n2 number) return number as
res number;
70
begin
if mod (n1, n2) = 0
then res := 1;
else
res:= 0;
end if;
return res;
end;
/
//pq4.sql
declare
a number;
b number;
begin
a:=&a; b:=&b; dbms_Sample
Output.put_line(„result=‟||checkdiv(a,b)); end;
/
SAMPLE OUTPUT:
SQL> @p4.sql;
Function created.
SQL> @pq4.sql;
Enter value for a: 4
old 5: a:=&a; new 5: a:=4;
Q4: Write a PL/SQL function called POW that takes two numbers as argument and return
the value of the first number raised to the power of the second .
71
PROGRAM:
//p5.sql
create or replace function pow (n1 number, n2 number) return number as
res number;
begin
select power ( n1, n2) into res from dual; return res; end;
or
create or replace function pow (n1 number, n2 number) return number as
res number : =1;
begin
for res in
1..n2 loop
res : = n1 * res;
end loop;
return res;
end;
//pq5.sql
declare
a number;
b number;
begin
a:=&a; b:=&b; dbms_Sample
Output.put_line('power(n1,n2)='||pow(a,b)); end;
/
SAMPLE OUTPUT:
SQL> @p5.sql;
Function created.
SQL> @ pq5.sql;
72
Enter value for a: 2
old 5: a:=&a; new
5: a:=2; Enter
value for b: 3 old
6: b:=&b; new 6:
b:=3;
power(n1,n2)=8
Q5: Write a PL/SQL function ODDEVEN to return value TRUE if the number passed to it
is EVEN else will return FALSE.
PROGRAM:
//p6.sql
create or replace function oddeven (n number) return boolean as
begin
if mod (n, 2) = 0 then return true;
else
return false;
end if;
end;
/
//pq6.sql
declare
a number; b boolean;
begin
a:=&a; b:=oddeven(a);
if b then
dbms_Sample Output.put_line('The given number
is Even'); else
dbms_Sample Output.put_line('The given number is Odd');
end if;
end;
73
/
SAMPLE OUTPUT:
SQL> @p6.sql;
Function created.
SQL> @pq6.sql;
Enter value for a: 5
74
EX.NO.6
Date:
CREATION OF TRIGGERS
AIM:
To create triggers for various events such as insertion, updation, etc.,
TRIGGER
A Trigger is a stored procedure that defines an action that the database automatically take
when some database-related event such as Insert, Update or Delete occur.
TYPES OF TRIGGERS
The various types of triggers are as follows,
Before: It fires the trigger before executing the trigger statement.
After: It fires the trigger after executing the trigger statement.
For each row: It specifies that the trigger fires once per row.
For each statement: This is the default trigger that is invoked. It specifies that the
trigger fires once per statement.
Syntax:
Create or replace trigger <trg_name> Before /After Insert/Update/Delete
[of column_name, column_name….]
on <table_name>
[for each row]
[when
75
condition] begin
---statement
end;
Q1: Create a trigger that insert current user into a username column of an existing table
PROCEDURE:
1 Create a table itstudent4 with name and username as arguments
2 Create a trigger for each row that insert the current user as user name into a table
3 Execute the trigger by inserting value into the table
PROGRAM:
SQL> create table itstudent4(name varchar2(15),username varchar2(15));
Table created.
SQL> create or replace trigger itstudent4 before insert on itstudent4 for each row
2 declare
3 name varchar2(20);
4 begin
5 select user into name from dual;
6 :new.username:=name;
7 end;
8 /
Trigger created.
SAMPLE
OUTPUT:
76
SQL> /
Enter value for name: suji
Enter value for username: priya
old 1: insert into itstudent4 values('&name','&username')
new 1: insert into itstudent4 values('suji','priya')
1 row created.
SQL> select * from itstudent4;
NAME USERNAME
--------------- ---------------
akbar SCOTT
suji SCOTT
Q2: Create a Simple Trigger that does not allow Insert Update and Delete Operations on
the Table
PROGRAM:
Table used:
SQL> select * from itempls;
ENAME EID SALARY
---------- --------- ---------
xxx 11 10000
yyy 12 10500
zzz 13 15500
TRIGGER
SQL> create trigger ittrigg before insert or update or delete on itempls for each row
2 begin
3 raise_application_error(-20010,'You cannot do manipulation');
4 end;
5 /
Trigger created.
77
SAMPLE OUTPUT:
SQL> insert into itempls values('aaa',14,34000);
insert into itempls values('aaa',14,34000)
*
ERROR at line 1:
ORA-20010: You cannot do manipulation
ORA-06512: at "STUDENT.ITTRIGG", line 2
ORA-04088: error during execution of trigger 'STUDENT.ITTRIGG'
Q3: Create a Trigger that raises an User Defined Error Message and does not allow
updating and Insertion
PROGRAM:
Table used:
SQL> select * from itempls;
78
ENAME EID SALARY
---------- --------- ---------
xxx 11 10000
yyy 12 10500
zzz 13 15500
TRIGGER:
SQL> create trigger ittriggs before insert or update of salary on itempls for each row
2 declare
3 triggsal itempls.salary%type;
4 begin
5 select salary into triggsal from itempls where eid=12;
6 if(:new.salary>triggsal or :new.salary<triggsal) then
7 raise_application_error(-20100,'Salary has not been changed');
8 end if;
9 end;
10 /
Trigger created.
SAMPLE OUTPUT:
79
*
ERROR at line 1:
ORA-04298: trigger 'STUDENT.ITTRIGGS' is invalid and failed re-validation
80
EX.NO.7
Date:
EXCEPTION HANDLING
AIM:
To create a PL/SQL program for exception handling.
PL/SQL - EXCEPTIONS
1.System-defined exceptions
2.User-defined exceptions
Syntax:
DECLARE
<declarations section>
BEGIN
<executable command(s)>
EXCEPTION
<exception handling goes here >
WHEN exception1 THEN
exception1-handling-statements
WHEN exception2 THEN
exception2-handling-statements
WHEN exception3 THEN
exception3-handling-statements
........
WHEN others THEN
exception3-handling-statements
81
END;
ID NAME ADDRESS
---------- ----------------- ------------------
1 Arun Kalyan Nagar
2 Vijay Fifth cross
PROGRAM:
DECLARE
c_id customer.id%type := 8;
c_name customer.name%type;
c_addr customer.address%type;
BEGIN
SELECT name, address INTO c_name, c_addr
FROM customer
WHERE id = c_id;
DBMS_SAMPLE OUTPUT.PUT_LINE ('Name: '|| c_name);
DBMS_SAMPLE OUTPUT.PUT_LINE ('Address: ' || c_addr);
EXCEPTION
WHEN no_data_found THEN
dbms_Sample Output.put_line('No such customer!');
WHEN others THEN
dbms_Sample Output.put_line('Error!');
END;
/
OUPTUT:
No such customer!
PL/SQL procedure successfully completed.
82
Q2 . Program for User defined Exception Handling.
DECLARE
c_id customers.id%type := &cc_id;
c_name customers.name%type;
c_addr customers.address%type;
-- user defined exception
ex_invalid_id EXCEPTION;
BEGIN
IF c_id <= 0 THEN
RAISE ex_invalid_id;
ELSE
SELECT name, address INTO c_name, c_addr
FROM customers
WHERE id = c_id;
DBMS_SAMPLE OUTPUT.PUT_LINE ('Name: '|| c_name);
DBMS_SAMPLE OUTPUT.PUT_LINE ('Address: ' || c_addr);
END IF;
EXCEPTION
WHEN ex_invalid_id THEN
dbms_Sample Output.put_line('ID must be greater than zero!');
WHEN no_data_found THEN
dbms_Sample Output.put_line('No such customer!');
WHEN others THEN
dbms_Sample Output.put_line('Error!');
END;
/
SAMPLE OUTPUT:
83
old 2: c_id customers.id%type := &cc_id;
new 2: c_id customers.id%type := -6;
ID must be greater than zero!
84
EX.NO:8
Date:
EMPLOYEE DATABASE
1.CREATE EMPLOYEE TABLE
SQL> CREATE TABLE Employees (ssn CHAR(11), name CHAR(20), lot NUMBER(20),
PRIMARY KEY (ssn) )
Table Created.
SQL> /
Enter value for SSN: 2
Enter value for NAME: B
Enter value for LOT: 200
old 1: insert into employee values(„&SSN‟,‟&NAME‟,&LOT);
new 1: insert into emp values(2,‟B‟,200)
1 row created.
SQL> /
Enter value for SSN: 3
Enter value for NAME: C
Enter value for LOT: 300
old 1: insert into employee values(„&SSN‟,‟&NAME‟,&LOT);
new 1: insert into emp values(3,‟C‟,300)
1 row created.
SQL> /
Enter value for SSN: 4
Enter value for NAME: D
Enter value for LOT: 400
old 1: insert into employee values(„&SSN‟,‟&NAME‟,&LOT);
new 1: insert into emp values(4,‟D‟,400)
1 row created.
SQL> /
Enter value for DID: 15
Enter value for DNAME: ACCOUNTING
Enter value for BUDGET: 20000
old 1: insert into employee values („&DID‟,‟&DNAME‟,&BUDGET);
new 1: insert into emp values(15,‟ACCOUNTING‟,20000)
1 row created.
SQL> /
Enter value for DID: 20
Enter value for DNAME: IT
Enter value for BUDGET: 30000
old 1: insert into employee values („&DID‟,‟&DNAME‟,&BUDGET);
new 1: insert into emp values(20,‟IT‟,30000)
1 row created.
87
E-R DIAGRAM FOR EMPLOYEE TABLE
Relationship
A relationship is an association between several entities.
Relationship Set
It is a set of relationships of the same type.
SQL> CREATE TABLE Works_In (ssn CHAR(1), did NUMBER(20), since DATE, PRIMARY
KEY (ssn, did), FOREIGN KEY (ssn) REFERENCES Employee, FOREIGN KEY (did)
REFERENCES Department)
88
Relationship sets can also have descriptive attributes (e.g., the since attribute of
Works_In).
In translating a relationship set to a relation, attributes of the relation must
include:
Keys for each participating entity set (as foreign keys).This set of attributes
forms superkey for the relation.
All descriptive attributes.
CONSTRAINTS
An E-R enterprise schema may define certain constraints to which the contents of a database
must conform.
1. Mapping Cardinalities
2. Key Constraints
3. Participation Constraints
KEY CONSTRAINTS
Consider Works_In: An employee can work in many departments; a dept can have many
employees.
In contrast, each dept has at most one manager, according to the key constraint on
Manages.
SQL> CREATE TABLE Manages (ssn CHAR(10), did number(20), since DATE, PRIMARY
KEY (did), FOREIGN KEY (ssn) REFERENCES Employee, FOREIGN KEY (did)
REFERENCES Department)
PARTICIPATION CONSTRAINTS
89
Every department have a manager is a participation constraint: the participation of
Departments in Manages is said to be total (vs. partial).
Every did value in Departments table must appear in a row of the Manages table (with a
non-null ssn value!)
NORMALIZATION
1.FIRST NORMAL FORM
The First normal form (1NF) sets basic rules for an organized database −
Define the data items required, because they become the columns in a table.
But as per the 1NF, we need to ensure that there are no repeating groups of data. So, let us break
the above table into two parts and then join them using a key as shown in the following program
CUSTOMERS table
CREATE TABLE CUSTOMERS(
ID INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR (25),
PRIMARY KEY (ID)
);
This table would have the following record −
ID NAME AGE ADDRESS
ORDERS table
CREATE TABLE ORDERS(
ID INT NOT NULL,
CUSTOMER_ID INT NOT NULL,
ORDERS VARCHAR(155),
PRIMARY KEY (ID)
);
This table would have the following records −
91
ID CUSTOMER_ID ORDERS
The Second Normal Form states that it should meet all the rules for 1NF and there must be no
partial dependences of any of the columns on the primary key −
Consider a customer-order relation and you want to store customer ID, customer name, order ID
and order detail and the date of purchase −
CREATE TABLE CUSTOMERS(
CUST_ID INT NOT NULL,
CUST_NAME VARCHAR (20) NOT NULL,
ORDER_ID INT NOT NULL,
ORDER_DETAIL VARCHAR (20) NOT NULL,
SALE_DATE DATETIME,
PRIMARY KEY (CUST_ID, ORDER_ID)
);
This table is in the first normal form; in that it obeys all the rules of the first normal
form. In this table, the primary key consists of the CUST_ID and the ORDER_ID.
However, the table is not in the second normal form because there are partial
dependencies of primary keys and columns. CUST_NAME is dependent on CUST_ID
The order detail and purchase date are also dependent on the ORDER_ID, but they are
not dependent on the CUST_ID, because there is no link between a CUST_ID and an
ORDER_DETAIL or their SALE_DATE.
To make this table comply with the second normal form, you need to separate the
columns into three tables.
First, create a table to store the customer details as shown in the code block below −
CREATE TABLE CUSTOMERS(
CUST_ID INT NOT NULL,
CUST_NAME VARCHAR (20) NOT NULL,
PRIMARY KEY (CUST_ID)
);
The next step is to create a table to store the details of each order −
92
CREATE TABLE ORDERS(
ORDER_ID INT NOT NULL,
ORDER_DETAIL VARCHAR (20) NOT NULL,
PRIMARY KEY (ORDER_ID)
);
Finally, create a third table storing just the CUST_ID and the ORDER_ID to keep a track of all
the orders for a customer −
CREATE TABLE CUSTMERORDERS(
CUST_ID INT NOT NULL,
ORDER_ID INT NOT NULL,
SALE_DATE DATETIME,
PRIMARY KEY (CUST_ID, ORDER_ID)
);
The dependency between the zip code and the address is called as a transitive
dependency.
To comply with the third normal form, all you need to do is to move the Street, City and
the State fields into their own table, which you can call as the Zip Code table.
93
The next step is to alter the CUSTOMERS table as shown below −
CREATE TABLE CUSTOMERS(
CUST_ID INT NOT NULL,
CUST_NAME VARCHAR (20) NOT NULL,
DOB DATE,
ZIP VARCHAR(12),
EMAIL_ID VARCHAR(256),
PRIMARY KEY (CUST_ID)
);
94
EX.NO.9
Date:
96
Microsoft Visual C++ (often abbreviated as MSVC or VC++) is a commercial (free
version available), integrated development environment (IDE) product from Microsoft
for the C, C++, and C++/CLI programming languages.
It has tools for developing and debugging C++ code, especially code written for the
Microsoft Windows API, the DirectX API, and the Microsoft .NET Framework.
3. JAVA
97
4.1 HTML Documents = Web Pages
• HTML documents describe web pages
• HTML documents contain HTML tags and plain text
• HTML documents are also called web pages
The purpose of a web browser (like Internet Explorer or Firefox) is to read HTML
documents and display them as web pages.
The browser does not display the HTML tags, but uses the tags to interpret the content of
the page:
4.2 Editing HTML
HTML can be written and edited using many different editors like Dreamweaver and
Visual Studio.
However, in this tutorial we use a plain text editor (like Notepad) to edit HTML.
Using a plain text editor is the best way to learn HTML.
Table created.
1 row created.
SQL> /
Enter value for sname:Hari
Enter value for dept: cse
Enter value for mark1: 76
Enter value for mark2: 75
Enter value for mark3: 74
Enter value for gender: M
Enter value for address: North Street
Enter value for total: 279
Enter value for avg: 77
Enter value for grade: a
old 1: insert into stuinfo
values('&sname','&dept','&mark1','&mark2','&mark3','&total','&avg','&gr
new 1: insert into stuinfo values('rama','cse','76','75','74','279','77','a')
SNAME DEPT MARK1 MARK2 MARK3 GENDER ADDRESS TOTAL AVG GRADE
99
--------------- ------------- --------- --------- ------------ --------- ------------ ----------- ------ ------------
Bharathi IT 67 78 67 M Kalyan nagar 134 69 B
Hari CSE 76 75 74 M North street 279 77 A
begin
:stuinfo.total:=:stuinfo.mark1+:stuinfo.mark2+:stuinfo.mark3;
end;
begin
:stuinfo.avg:=(:stuinfo.total/3);
end;
To Find Grade:
ITEM NAME :GRADE
TRIGGERNAME :When_mouse_click
begin
if :stuinfo.mark1>35 and :stuinfo.mark2>35 then
if :stuinfo.avg>80 then
:stuinfo.grade:='A';
else
:stuinfo.grade:='B';
end if;
else
:stuinfo.grade:='C';
end if;
end;
To Append:
ITEM NAME : APPEND
TRIGGERNAME : When_mouse_click
100
begin
create_record;
end;
To Delete:
ITEM NAME : DELETE
TRIGGERNAME : When_mouse_click
begin
delete_record;
end;
begin
commit_form;
end;
To Exit:
ITEM NAME : EXIT
TRIGGERNAME : When_mouse_click
begin
exit_form;
end;
To Clear:
ITEM NAME : CLEAR
TRIGGERNAME : When_mouse_click
begin
clear_form;
end;
SNAME DEPT MARK1 MARK2 MARK3 GENDER ADDRESS TOTAL AVG GRADE
--------------- ------------- --------- --------- ------------ --------- ------------ ---------- -------- -----------
101
Bharathi IT 67 78 67 M Kalyan nagar 134 69 B
Hari CSE 76 75 74 M North street 279 77 A
Sudhakar IT 89 76 67 M East street 232 77 A
Ramarajan CSE 65 54 60 M First cross 179 59 C
FORM CODING
LOGIN FORM
102
Private Sub insert_Click()
Adodc1.Recordset.AddNew
End Sub
Private Sub movefirst_Click()
Adodc1.Recordset.movefirst
End Sub
103
FORM DESIGN
104
SAMPLE OUTPUT
105
REPORT GENERATION
106
107
108
109
110
111
112
113
EX.NO:10
Date:
DATABASE APPLICATIONS
Database applications are software programs designed to collect, manage and disseminate
information efficiently.
Many home and small business owners create simple databases such as customer contact
and mailing lists with easy to use software such as Microsoft "Access" and "FileMaker
Pro." "Oracle," "SQL Server," and "FoxPro" are examples of advanced database
applications with programming languages that can be used to build custom business
solutions in networked environments.
1. Data processing drove growth of computer processor speed.Punched cards were used in
the US for collecting data for census during beginning of 20th century. Earliest data
processing was done by punched cards on mechanical devices. The real development in
data processing speed, storage of data and development of DB applications started much
later i.e. from 1950s.
2. Magnetic tapes were used to store data and being read from it. These database
applications had hierarchical structure and used network systems. They were extremely
efficient when used with the original query, exactly developed for them, but the DB was
not designed to handle new queries or transactions. Also the magnetic tapes must be in
same sorted order so as to retrieve the authentic data.
3. Later in 60s Hard Disks came about and data retrieval was faster and did not need be
stored sequentially. This period was also remarkable in terms of advancement in DB
Systems.
4. Later in 1970 Edgar Codd, father or Relational Database Model, conceptualized a new
structure for Database construction and wrote a groundbreaking paper „A Relational
Model of Data for Large Shared Data Banks‟. He freed database from procedural ways of
querying and marked the beginning of Data Abstraction i.e. hiding details of how
Database is implemented to application programmers and end users. System R, based on
Codd‟s concept was developed by IBM and it was first to have a language for querying
called SQL or Structured Query Language.
114
5. Later, System R was further developed to a mainstream commercial DBMS product
known as DB2.
6. Object oriented programming was rapidly developing in the 80s and it also helped
break into what we know as Object Oriented Databases. The idea was to treat data as
objects and it became easier to conceptualize and program using this idea. Another great
development which happened was processing speed of processors and also
conceptualization of indexing which greatly increased data access times, and
performances of DB.
7. 90s was a time of a World Wide Web, so unprecedented like world had never seen
before. The data was here on the internet. Databases to which links were forwarded were
varied and different and it needed a technique to interchange data efficiently. Also the
database had to be of very high availability working 24x7.
8. XML or Extended Markup Language is a standard for providing data exchange among
different databases and WebPages.
9. More recently, there has been a growing trend of NoSQL database. These are different
from so called classical databases and do not rely on Relational Model for their structure.
They do not query data using Structured Query Language but UnQL or Unstructured
Query Language which is still in development stage (it is similar to XQuery).
TYPES OF DATABASES
There are several types of databases that can be used in real-world scenarios.
Flat-file databases are generally plain text files that can be used by local applications to
store data. Flat files are not as popular as relational databases.
Relational database are databases with related tables of information. Each table has a
number of columns or attributes and a set of records or rows. Relational databases are
popular because of their scalability, performance and ease of use.
BENEFITS OF DATABASES
1. Databases are stored digitally, multiple users in different locations can view the data in
more than once place. Banks store their customer information and balances in a database,
so can use any branch for deposits and withdrawals.
2. Databases allow more flexibility because they are in a digital format. Companies use
databases for inventory and item pricing. A retail chain can see when stores are low in
inventory and automatically order more. Prices can be updated across the country
instantly as compared to having to manually do it at each store.
3. Databases are used to distribute data quickly and easily because they are only updated
once and can be read by many users.
115
Due the evolution of Database management system, companies are getting more from
their work because they can keep records of everything.
Also it makes them faster to search information and records about any people or product
that makes them more effective in work.
3.Banking
We make thousands of transactions through banks daily and we can do this without going
to the bank. So how banking has become so easy that by sitting at home we can send or
get money through banks. That is all possible just because of DBMS that manages all the
bank transactions.
116
"Microsoft Money," "Quicken," "QuickBooks" and "Peachtree" are accounting systems
built upon database applications.
7.CRM Applications
A customer relationship management system (CRM) is to manage the marketing, sales,
and support relationships between a business and it's customers. The ultimate goal is to
maximize sales, minimize costs and foster strategic customer relationships.
"SAP," "Salesforce.com," and Oracle's "Siebel" are robust CRM database applications
suitable for larger enterprises.
8.Web Applications
Many contemporary web sites are built using several database applications
simultaneously as core components.
Most retail store Web sites including "Bestbuy.com," and "Amazon.com" use database
systems to store, update and present data about products for sale. These Web sites also
combine an accounting database system to record sales transactions and a CRM database
application to incorporate feedback and drive a positive customer experience.
The popular Web-based "Facebook" application is essentially a database built upon the
"MySQL" database system and is an indication of the increasing usage of database
applications as foundations for Web-based applications.
9.Telecom:
There is a database to keeps track of the information regarding calls made, network
usage, customer details etc. Without the database systems it is hard to maintain that huge
amount of data that keeps updating every millisecond.
10.Industry:
11.Airlines:
To travel though airlines, we make early reservations, this reservation information along
with flight schedule is stored in database.
117
The online shopping websites such as Amazon, Flipkart etc., store the product
information, your addresses and preferences, credit details and provide you the relevant
list of products based on your query. All this involves a Database management system.
118