Professional Documents
Culture Documents
DBMS Module 3
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?
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;
For example, the following command removes the attribute Address from
the EMPLOYEE base table:
ALTER TABLE COMPANY.EMPLOYEE DROP COLUMN Address CASCADE;
It is also possible to alter a column definition by dropping an existing
default clause or by defining a new default clause.
The following examples illustrate this clause:
i. ALTER TABLE COMPANY.DEPARTMENT ALTER COLUMN Mgr_ssn
DROP DEFAULT;
ii. ALTER TABLE COMPANY.DEPARTMENT ALTER COLUMN Mgr_ssn
SET DEFAULT ”333445555‟;
One can also change the constraints specified on a table by adding or
dropping a named constraint.
To be dropped, a constraint must have been given a name when it was
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;