Professional Documents
Culture Documents
DBMS Module 3
DBMS Module 3
Stored procedures must have a name; this stored procedure has the
name 'ShowNumberOfOrders.' Otherwise, it just contains an SQL
statement that is precompiled and stored at the server.
Advantages:
1. Easy to maintain and modification is bit easy
2. Communication is faster
Disadvantages:
1. In two tier architecture application performance will be degrade
upon increasing the users.
2. Cost-ineffective
SQLJ JDBC
SQLJ (SQL in Java) is a technology JDBC (Java Database Connectivity) is a
that embeds SQL statements Java API for executing SQL statements
directly into Java code.
It provides a way to execute It provides a standard way for Java
database statements as part of a programs to interact with databases.
Java program without using JDBC.
SQLJ is a more concise and JDBC is a more flexible and powerful
convenient way to interact with way to interact with databases
databases
SQLJ is a higher-level JDBC is a lower-level
SQLJ is more suitable for projects JDBC is more suitable for projects that
that require fast performance and require greater control and portability
concise code. across different databases.
5.Difference between dynamic and embedded SQL.
Static or Embedded SQL are SQL statements in an application that do
not change at runtime and, therefore, can be hard-coded into the
application.
Dynamic SQL is SQL statements that are constructed at runtime; for
example, the application may allow users to enter their own queries.
6.What is CGI? Why was CGI introduced? What are the disadvantages of an
architecture using CGI scripts?
Common Gateway Interface connects HTML forms with application
programs.
It is a protocol that defines how arguments from forms are passed to
programs at the server side.
Programs that communicate with the webserver via CGI are often called
CGI scripts, since many such application programs were written in a
scripting language such Ike.; Perl.
As an example of a program that interfaces with an HTML form via CGI,
consider the sample page shown in Figure 6.1. This webpage contains a
form where a user can fill in the name of an author.
If the user presses the 'Send it' button, the Perl script 'findBooks.cgi'
shown in Figure 7.14 is executed as a separate process.
The CGl protocol defines how the communication between the form and
the script is performed.
Features of CGI:
a) It is a very well defined and supported standard.
b) CGI scripts are generally written in either Perl, C, or maybe just a
simple shell script.
c) CGI is a technology that interfaces with HTML.
d) CGI is the best method to create a counter because it is currently
the quickest
e) CGI standard is generally the most compatible with today's
browsers
Advantages of CGI:
i. The advanced tasks are currently a lot easier to perform in CGI
than in Java.
ii. It is always easier to use the code already written than to write
your own.
iii. CGI specifies that the programs can be written in any language,
and on any platform, as long as they conform to the specification.
iv. CGI-based counters and CGI code to perform simple tasks are
available in plenty.
Disadvantages of CGI:
There are some disadvantages of CGI which are given below:
i. In Common Gateway Interface each page load incurs overhead by
having to load the programs into memory.
ii. Generally, data cannot be easily cached in memory between page
loads.
iii. There is a huge existing code base, much of it in Perl.
iv. CGI uses up a lot of processing time.
7.insert, delete, update, alter, drop, select:
CREATE TABLE
SELECT STATEMENT
The SELECT statement is used to select data from a database.
Syntax:
SELECT column1, column2, ... FROM table_name;
Here, column1, column2, ... are the field names of the table
you want to select from the data.
SELECT * FROM table_name;
If the above query is executed, then all record is displayed.
Example
1. Select EmpId, LastName from Employee;
2. Select * from Employee;
UPDATE TABLE
The UPDATE statement is used to modify the existing records in a table.
Syntax
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Example
UPDATE Employee
SET FirstName= 'KS', City= 'Pune'
WHERE EmpId= 1;
If the above query is executed then for EmpId= 1, "Firstname" and "City"
column data will be updated.
DELETE STATEMENT
The DELETE statement is used to delete existing records in a table for a
particular Record.
Syntax
DELETE FROM table_name WHERE condition;
Example
DELETE FROM Employee WHERE EmpId=1;
In Employee table EmpId = 1 record gets deleted.
DROP STATEMENT:
The DROP TABLE statement is used to drop an existing table in a
database.
Syntax
DROP TABLE table_name;
Example
DROP TABLE Shippers;
TRUNCATE TABLE
The TRUNCATE TABLE command deletes the data inside a table, but not
the table itself.
Syntax
TRUNCATE TABLE table_name;
Example
TRUNCATE TABLE Shippers;
1. COUNT FUNCTION
COUNT function is used to Count the number of rows in a
database table. It can work on both numeric and non-numeric
data types.
COUNT function uses the COUNT (*) that returns the count of all
the rows in a specified table. COUNT (*) considers duplicate and
Null.
Syntax
COUNT (*) or COUNT([ALL\DISTINCT] expression)
Example:
1. Count()
SELECT COUNT (*) FROM PRODUCT;
2. SUM FUNCTION
Sum function is used to calculate the sum of all selected columns.
It works on numeric fields only.
Syntax
SUM () or SUM ([ALL|DISTINCT] expression)
Example:
a) SUM ()
SELECT SUM(COST)
FROM PRODUCT;
b) SUM() with HAVING and GROUP BY
SELECT COMPANY, SUM(COST)
FROM PRODUCT
GROUP BY COMPANY
HAVING SUM(COST)>=170;
3. AVG FUNCTION
The AVG function is used to calculate the average value of the
numeric type. AVG function returns the average of all non-Null
values.
Syntax: AVG( ) or AVG( [ALL|DISTINCT] expression )
Example:
SELECT AVG(COST)
FROM PRODUCT_MAST;
4. MAX FUNCTION
MAX function is used to find the maximum value of a certain
column. This function determines the largest value of all
selected values of a column.
Syntax: MAX() or MAX( [ALL|DISTINCT] expression )
Example:
SELECT MAX(RATE)
FROM PRODUCT;
5. MIN FUNCTION
MIN function is used to find the minimum value of a certain
column. This function determines the smallest value of all
selected values of a column.
Syntax: MIN() or MIN( [ALL|DISTINCT] expression )
Example:
SELECT MIN(RATE)
FROM PRODUCT_MAST;