Professional Documents
Culture Documents
Lab Manual
of
Database Management System (3330703)
Semester – 3
Enrollment No :_________________________________________________________________________
PRACTICAL – 1
Queries to
create a table
3 [Database Management System - 3330703]
PRACTICAL – 1
Create table command is used to create a table. Create table defines column of a table
uniquely.
Each column has minimum three attributes: -
1. Name
2. Data type
3. Size
Each table column is separated from other by a comma (,).
SYNTAX: -
EXAMPLE : -
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
6 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
7 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
8 [Database Management System - 3330703]
PRACTICAL – 2
SQL DDL COMMANDS
– ALTER, RENAME,
TRUNCATE, DROP &
DESC
9 [Database Management System - 3330703]
PRACTICAL – 2
SYNTAX: -
EXAMPLE: -
SYNTAX: -
EXAMPLE: -
SYNTAX: -
EXAMPLE: -
SYNTAX: -
EXAMPLE: -
(3).DROP COMMAND: -
Drop table statement with table name can destroy specific table
SYNTAX: -
EXAMPLE: -
Truncate table empties a table completely. Logically it is equivalent to delete stmt that
deletes all rows , but there are practical differences under some circumstances.
Truncate operations drop & re-create table which is much faster than deleting rows one
by one.
Write SQL Statement to perform the given task: -
11 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
13 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
14 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
15 [Database Management System - 3330703]
PRACTICAL – 3
SQL QUERIES TO
INSERT, SELECT,
UPDATE & DELETE
DATA
16 [Database Management System - 3330703]
PRACTICAL – 3
SYNTAX: -
INSERT INTO <TABLE NAME> (<COLUMN NAME1>, <COLUMN NAME2>,
<COLUMN NAME3>) VALUES (<EXPRESSION1>, <EXPRESSION2>,
<EXPRESSION3>);
EXAMPLE: -
E3 Kaushik Analyst
E4 Amit Programmer
E5 Chandra Programmer
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
19 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
20 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
21 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
22 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
23 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
24 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
25 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
26 [Database Management System - 3330703]
SELECT STATEMENT: -
Once data is inserted and user need to view the data then use select command.
SYNTAX: -
SYNTAX: -
EXAMPLE: -
SYNTAX: -
EXAMPLE: -
SYNTAX: -
EXMAPLE: -
A table could hold duplicate rows. In such case, if user wants to view only unique
rows distinct clause is used.
SYNTAX: -
EXAMPLE: -
Oracle allows data from a table to be viewed in a sorted order. The rows retrieved will be
either in ascending order or descending order depending on condition specified.
SYNTAX: -
EXAMPLE: -
__________________________________________________________________
29 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
30 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
31 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
UPDATE STATEMENT: -
Update command is used to change or modify data values in a table. It is used to update
all rows or selected rows.
Set clause here indicates which column data should be modified and new values that they
should hold.
SYNTAX: -
32 [Database Management System - 3330703]
SYNTAX: -
EXAMPLE: -
UPDATE STUDENT SET CITY = „RAJKOT‟ WHERE STUDID = „S101‟ AND NAME
= „ABC‟;
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
34 [Database Management System - 3330703]
DELETE STATEMENT: -
Delete Command deletes rows from table that specifies the condition provided by where
clause and returns number of records deleted.
SYNTAX: -
SYNTAX: -
________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
35 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
36 [Database Management System - 3330703]
PRACTICAL – 4
SQL COMMANDS
to demonstrate
various
functions.
27
37 [Database Management System - 3330703]
PRACTICAL – 4
A single row function or scalar function returns only one value for every row queried in
the table. Single row functions can be broadly classified as……………..
Date function
Numeric function
Character function
Conversion function
Miscellaneous function
38 [Database Management System - 3330703]
DATE FUNCTION: -
Date functions operate on the date values producing output which also belongs to date
data type.
(7). WAQ to display sale date and date after 2 months from sale date.
(8). WAQ to display system date, sale date and months between two dates.
(9). WAQ to display the greatest date between sale date and system date. Name it as BIG
also display sale date and SYSDATE.
(10). WAQ to display the least date between sale date and system date. Name it as
SMALL also display sale date and SYSDATE.
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
40 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
41 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
42 [Database Management System - 3330703]
NUMERIC FUNCTION: -
(4). WAQ to display product name along with truncated value of product cost to 0, 1, -1
decimal places for PEN.
(5). WAQ to display product cost along with MOD value if divided by 5.
(6). WAQ to find absolute value of -12.
(7). WAQ to find power of (4,2).
(8). WAQ to find square root of 49.
(9). WAQ to find exponent of 7.
(10). WAQ to extract month and year from SYSDATE.
(11). WAQ to find greatest value from 35, 40, 42.
(12). WAQ to find least value from 35, 40, 42.
(13). WAQ to find FLOOR value of 20.15
(14). WAQ to find CEIL value of 20.15
44 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
45 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
46 [Database Management System - 3330703]
CHARACTER FUNCTION: -
Character functions accept data as input and can return both character and number values.
(1). WAQ to display all concatenated value of CNAME, CITY by converting CNAME
into title case and CITY into uppercase.
(2). WAQ to display the first three characters of CNAME.
(3). WAQ to display the position of character „M‟ in the CNAME of the customer whose
name id “ANUMITA”.
(4). WAQ to display the length of all customer names.
(5). PAD# character in left of product cost to a total width of 5 character positions.
(6). PAD# character in right of product cost to a total width of 5 character positions.
WAQ to display along with PNAME.
(7). WAQ to display PNAME by trimming „P‟ if it is first character in PNAME.
(8). WAQ to display the customer name, product name and sale details from
CUSTOMER, PRODUCT and SALE_DETAIL table using „||‟ operator.
(9). WAQ to find ASCII value of C.
(10). WAQ for string ABC123XYZ to replace 123 with PQR.
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
48 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
49 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
CONVERSION FUNCTION: -
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
51 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
52 [Database Management System - 3330703]
AGGEGRATE FUNCTION: -
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
53 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
54 [Database Management System - 3330703]
PRACTICAL – 5
Queries to use
SET Operators.
55 [Database Management System - 3330703]
PRACTICAL – 5
☼ UNION CLAUSE:-
Multiple queries can be put together and their output can be combined using the UNION
clause.
The UNION clause merges the output of two or more queries into a single set of two or
more queries into a single set of rows and columns.
The number of column and data type of column being selected must be identical in all
the SELECT statement used in the query. The name of column need not be identical.
NULL values are ignored during duplicate checking.
By default, output is stored in ascending order of first column of the SELECT clause.
EXAMPLE:-
To find all customer having a loan and an account, or both in bank is written as…
☼ INTERSECT CLAUSE:-
Multiple queries can be put together and their output can be combined using the
INTERSECT clause.
The INTESECT clause outputs the rows produced by both the queries intersected i.e. the
Output in an intersect clause will include only those rows that are retrieved common to
both the Queries.
Common Records In
Both Tables
EXAMPLE :-
To find all customer who have both a loan and an account in the bank is written as..
►SELECT DISTINCT CUSTOMER_NAME FROM DEPOSITOR
INTERSECT
SELECT CUSTOMER_NAME FROM BORROWER
MINUS CLAUSE:-
Multiple queries can be put together and their output can be combined using the MINUS
clause.
The MINUS clause outputs the rows produced by first query,after filtering the rows
retrived by the second query.
EXAMPLE:-
To find all customer who have an account but no loan in the bank is written as…
► SELECT DISTINCT CUSTOMER_NAME FROM DEPOSITOR
MINUS
SELECT CUSTOMER_NAME FROM BORROWER
MINUS automatically eliminates duplicates.IF user want to retain duplicate values write
MINUS ALL in place of UNION.
Create the table specified below and insert data into it.
PRACTICAL – 6
To apply all
constraints
using at least
two tables.
61 [Database Management System - 3330703]
PRACTICAL – 6
To apply all constraints using at least two
tables.
Oracle permits data constraint to be attached to table columns via SQL syntax that checks
for integrity prior storage.
Once data constraint are part of a table column, the oracle database engine checks data
being entered into table column against the data constraint.
If data passes this check, it is stored in table column, else data is rejected.
Even if single column of record being entered into table fails a constraint, the entire
record is rejected and not stored in table.
There are two types of data constraint that can be applied to data inserted into table.
(1). I/O constraint
(2). Business Constraint
SYNTAX: -
<column name> <data type> (<size>) PRIMARY KEY
62 [Database Management System - 3330703]
EXAMPLE: -
SYNTAX: -
<column name> <datatype> (<size>) REFERENCES <table name> <column name>
EXAMPLE: -
EXAMPLE: -
CREATE TABLE CUST_DETAILS
CUSTID VARCHAR2(10) UNIQUE,
NAME VARCHAR2(10),
ADDRESS VARCHAR2(20),
CITY VARCHAR2(15),
PINCODE NUMBER(8));
SYNTAX: -
EXAMPLE: -
At column level: -
SYNTAX: -
EXAMPLE: -
At table level: -
SYNTAX: -
EXAMPLE: -
It is used to assign default value to a column. When a record is loaded into table and
column is empty, Oracle engine will automatically load this column with default value
specified. The data type of default value should match data type of column.
65 [Database Management System - 3330703]
SYNTAX: -
EXAMPLE: -
Now Query…………………
Mgrstrdate Date
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
68 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
69 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
70 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
71 [Database Management System - 3330703]
PRACTICAL – 7
SQL COMMANDS
to perform all
join operations
using at least
two tables.
72 [Database Management System - 3330703]
PRACTICAL – 7
Equi Join as it name suggests is based on equalities. The equi-join combines rows that
have equivalent values for the specified columns.
This is also called simple join or inner join.
This is the most used join among all.
Consider the EMP, DEPT & SALGRADE table given below: -
(1). WAQ to display the name and department name of those employee who works in
department no. 10
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
74 [Database Management System - 3330703]
In case of Non Equi Join column from one table does not directly corresponds to column
of second table.
Non Equi Join is best used with BETWEEN clauses.
This join specifies the relationship between columns belonging to different tables.
In this type of join >, >=, <, <= and != operators can also be used.
(2). WAQ to display the name, salary and grade of those employees whose salary
is greater than 1300 and less than 3000.
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
75 [Database Management System - 3330703]
OUTER JOIN: -
An outer join returns all rows returned by simple join. Equi Join as well as those from
one table that do not match any row from the other table.
This type of join is rarely used in practical implementations.
(3). WAQ to display the name of the subordinate who reports to the boss along with the
name of the boss. Included name of employee who does not report to any one.
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
76 [Database Management System - 3330703]
SELF JOIN: -
Joining a table t itself is known as Self Join. In this type of join different alias is used for
the same table.
This join is used only in very specific cases.
(4). WAQ to display the name of the subordinate who reports to the boss along with
name of the boss.
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
(5). WAQ to display ENAME, SAL and DEPTNO of those employees who are getting
SAL more than the average salary of the DEPTNO in which they are posted.
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
77 [Database Management System - 3330703]
PRACTICAL – 8
Write Queries
using relational
algebra .
78 [Database Management System - 3330703]
PRACTICAL – 8
To solve the query like to select those tuples of the table loan where branch name is
“perryridge”.
Select * from loan where branch_name=”perryridge”;
In relational algebra query is written as
σ branch_name= ”perryridge”(loan)
For example to find data that has amount more than 1200 is written as……
σ amont > 1200 (loan)
We can combine several predicates into larger predicate by using the connectives and (^),
or (\/) and not (¬).
Thus to find those tuples(rows) pertaining to loans of more than $1200 made by
Perryidge branch is written as……………..
σ branch_name = “perryridge” ^ amount > 1200
Now user wants to find loan_number and amount and don‟t require details of branch-
name. Projection is used to produce this relation
Projection is denoted by uppercase Greek letter pi ( )חand is written as…….
חloan-number, amount (loan)
חcustomer-name(σcustomer-city = “Harrison”(customer))
Union Operation
Consider a query to find names of all bank customer who have either an account or loan
or both. To find this information we need depositor relation (table) and borrower relation
(table).
חCustomer-name(borrower)
חCustomer-name(depositor)
חCustomer-name(borrower) Ụ Customer-name(depositor)
Set-Difference Operation
The set – difference operation denoted by - , allows us to find tuples (rows) that are in
one relation but not in another.
The expression r – s produces a relation contining those tuples in r but not in s.
User can find all customer of bank who have an account but not a loan by writing: -
חCustomer-name(depositor) – חcustomer-name(borrower)
80 [Database Management System - 3330703]
If borrower table has 3 rows and loan table has 3 rows then total rows returned by
Cartesian product is 9.
If user wants only that loan number that are in both borrower and loan table & have
branch name = “Perridyge”then it is specified as……………….
σ borrower.loan_number = loan.loan_number
(σbranch_name = “Perridyge” (borrower x loan))
Now to find customer name for condition above stated is written as……..
For example if user want to find all customer who have both a loan and an account then
intersection is written as……………
חCustomer-name(borrower) ∩ customer-name(depositor)
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
82 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
83 [Database Management System - 3330703]
PRACTICAL – 9
SQL Statements to
perform sub queries
and correlate queries.
84 [Database Management System - 3330703]
PRACTICAL – 9
o A SELECT clause
o A FROM clause
o A WHERE clause
The subquery can be nested inside a SELECT, INSERT, UPDATE, or DELETE statement
or inside another subquery.
A subquery is usually added within the WHERE Clause of another SQL SELECT
statement.
You can use the comparison operators, such as >, <, or =. The comparison operator can also
be a multiple-row operator, such as IN, ANY, or ALL.
A subquery is also called an inner query or inner select, while the statement containing a
subquery is also called an outer query or outer select.
The inner query executes first before its parent query so that the results of an inner query
can be passed to the outer query.
You can use a subquery in a SELECT, INSERT, DELETE, or UPDATE statement to perform the
following tasks:
Departments
( DEPARTMENT_ID , DEPARTMENT_NAME , MANAGER_ID , LOCATION_ID )
Locations
(LOCATION_ID,STREET_ADDRESS ,POSTAL_CODE ,CITY, STATE_PROVINCE,
COUNTRY_ID)
1. Write a query to display the name ( first name and last name ) for those employees who gets
more salary than the employee whose ID is 163.
2. Write a query to display the name ( first name and last name ), salary, department id, job id
for those employees who works in the same designation as the employee works whose id is
169.
3. Write a query to display the name ( first name and last name ), salary, department id for
those employees who earn such amount of salary which is the smallest salary of any of the
departments.
4. Write a query to display the department number, name ( first name and last name ), job and
department name for all employees in the Finance department.
5. Write a query to display all the information of an employee whose salary and reporting
person id is 3000 and 121 respectively.
6. Write a query to display all the information of the employees who does not work in those
departments where some employees works whose manager id within the range 100 and 200.
7. Display the employee name( first name and last name ), employee id, and job title for all
employees whose department location is Toronto.
8. Write a query to display the employee number, name( first name and last name ) and job
title for all employees whose salary is smaller than any salary of those employees whose job
title is MK_MAN
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
86 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
87 [Database Management System - 3330703]
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
88 [Database Management System - 3330703]
PRACTICAL – 10
Create simple
report using
Break on, btitle,
Title etc.
89 [Database Management System - 3330703]
PRACTICAL – 10
SET PAGESIZE 22
SET LINESIZE 60
SET FEEDBACK OFF
TITLE „BOMBAY SALES CORPORATION | SALES REPORT‟
BTITLE „CONFIDENTIAL‟
COLUMN MEONTH HEADING „MONTH‟ FORMAT A10
COLUMN SALESMAN HEADING „NAME OF SALESMAN‟
FORMAT A20
COLUMN PRODUCT HEADING „PRODUCT‟ FORMAT A10
COLUMN QUANTITY HEADING „QUANTITY‟ FORMAT 99
SELECT MONTH, SALESMAN, PRODUCT, QUANTITY FROM
SALES WHERE PRODUCT = „PENDRIVE‟;
90 [Database Management System - 3330703]
OUTPUT