Bcsccs 505 r01 Dbms-Lab Manual-2010
Bcsccs 505 r01 Dbms-Lab Manual-2010
( SASTRA UNIVERSITY )
Tirumalaisamudram
Thanjavur – 613 402
Additional experiment
Table Name: PC
Column Name Purpose
Model_No The unique identifier for each PC
Speed Clock Speed of the PC
RAM RAM in MB
HD The hard-disk capacity of the PC in GB
CD The speed of the CD Drive
Price Price of the PC
The product_info table serves as a master table containing the list of all models of pc, laptop
and printers manufactured by all makers. The PC, Laptop and the printer table give specific
details about each product in that class.
1. Create the 4 tables mentioned above
a. Check if the table is created successfully (tab table)
6. Insert a tuple such that the model value is PC100, it is manufactured by HCL and has
a speed of 3 GHz, RAM of 256 MB, HD of 40 GB and CD of speed 52x. The price is
50000.
9. For each PC double the amount of RAM and add 10 gb to the HDD.
10. For the printer whose modelno=pr124 subtract Rs. 4000 from the price.
2. KEY CONSTRAINTS
1. Alter the table product_info to make the type column NOT NULL.
3. Create suitable primary keys for all the tables of the above database schema
a. Check if the primary keys are created successfully (User_Constraints table)
4. Create suitable foreign keys for all the tables of the above database schema
a. Check if the foreign keys are created successfully (User_Constraints table)
b. Demonstrate the usage of On delete cascade
5. Check Constraints:
a. Apply a check constraint on the product_info table such that the only permitted
values for the type column are ‘pc’, ‘lp’ and ‘pr’.
b. Apply a check constraint such that the prices of pc, laptop and printer are all
positive.
c. Check if the check constraints are created successfully (User_Constraints
table)
6. What are the different values for constraint_type in the user_constraints table and
what is the meaning of each of those values?
7. Create a table named ‘Type_info’ with the columns model , type from ProductInfo
table ( Use the “create table yyy as select” construct )
a. Initially no rows should be present in the dummy table
b. Insert all the rows from product_info into ‘Type_Info’ (only selected columns)
11. Without removing the table definition from the database remove all the rows from the
table ‘Type_info’.
Name Age
DICK JONES 33
WILLIAM SWING 30
BART SARJEANT 32
SUMA RANGANATH 21
RICHARD WILLIAMS 29
BHARTH KUMAR 36
JOHN PEARSON 28
JACKSON 34
MEENA KUMARI 29
ADAH TALBOT 27
1. List those rows of the table PC where RAM sizes are either ‘128’ or ‘256’ and the
capacity of HD is greater than or equal to 50.
2. List all the rows from PRINTER except the printers ‘pr112’ or ‘pr124’.
3. List all the rows from LAPTOP in ascending and descending order of the screen size.
4. List the makers of PC’s. Use ‘like’ operator in the model field (don’t use type).
5. List the laptop details where the screen size is not 17.
6. List the printers whose price is between 5000 and 10000. (Use between).
7. Give examples for any one arithmetic , logical operator , between … and & in.
4. BUILT- IN FUNCTIONS
1. Find the difference between the highest and lowest price from laptop.
Workername age
4. a. Update the PC table such that, the price for all PC models is increased by 12.33%.
b. Display the PC model in lowercase and price rounded to the hundredths for all the
PCs.
5. List the names in the ascending order of the length of names from WORKER table.
6. List the phone number (eliminate area code like 91-0437) of all employees from
WORKERSKILL table.
7. Find the location of letter ‘A’ in the employee name of WORKERSKILL table.
(Hint: use INSTR ( )).
10a. List the employee name from WORKERSKILL table with lastname first and firstname
next in single column. (using CONCAT (str1,str2) function).
b. List the employee name from WORKERSKILL table with lastname first and firstname
next in single column. (using || operator).
c. List the employee name from WORKERSKILL table with lastname first and firstname
next in single column. (without using CONCAT () function and || operator).
11a. Alter the table worker skill to add a new column called “date-of-joining” (date data type).
b. Update the table to include the values for date-of-joining for each worker.
c. List the name of each worker along with his experience in number of years and
months.
13. Display the equivalent GMT and EST, for the given date and time.
15. Apply formatting on price column of table PRINTER to display like Rs. 50,000
and $50,000 ( using to_char , format command ).
1. Display the printer information whose price is equal to any one of the printer
manufactured by ‘IBM’.
2. List the laptop details whose screen size is equal to the screen size of ‘lp114’.
3. Give an example for a correlated sub-query using any of the tables above.
4. List the printer details whose price is greater than any other printer.(use any, all or in).
6. For each value of RAM, list the number of PCs (use group by function).
7. For each value of HD, list the number of PCs (use group by function).
8. List the HD values for which the number of PCs is more than 2. (Use group by and
Having clause).
9. List the details of the senior most worker and junior most worker.
6. UPDATE OPERATIONS
1. Update all the rows of the printer table, such that the price is increased by 12% for Ink
Jet Printers, 14% for Dot Matrix Printers, 10% for Laser Printers.( using separate
Update as well as single update statements)
2. Update the Laptop table to increase the price by 12.33% for only those laptops with a
speed of >= 2 and manufactured by HCL or IBM
3. Insert into Laptop table, all the rows from the PC table with the following considerations:
a. If the model number for the PC row is PCxxx, the model number in the Laptop
table should be LPxxx. ( Hint : Omit the CD column )
4. The above query can be solved using a single “Insert statement” as well. Try that.
5. Give an example of an update statement that uses any of the built-in functions
7. JOINS
3. List the name, age, skill from the worker and worker skill tables for workers whose age is
greater than 30 (use equi join).
5. List the distinct combinations of PC models whose HD capacities are same (use self
join).
6. Display the manufacturers of PC along with the details model, price (use inner join).
7. List the laptop and pc pairs whose price is same (list the model numbers, use inner join).
8. Give an example for left outer, right outer and full outer joins.
9. Give an example of how NVL function can be used effectively in outer joins.
8. INDEX, VIEWS, SEQUENCES & SYNONYMS
1. Create a view Price_info to include the columns model, maker and price for the PCs.
2. Create a view Price6000 on the table PRINTER to include only rows with price > 6000.
3. Modify one row in both the views and check whether it is reflected in the table and vice
versa.
5. Create a unique index on the worker name column of the worker table.
7. Create a function based index on the city column of the worker table (Use upper, lower
or initcap function and test)
10. Use the system variables currval, nextval to pick values from these sequences and
demonstrate their usage in insert, update, delete and select statements
11. Create a synonym object for worker skill with the name ‘G20K’.
a. Input_Value
b. Circle_Area
c. Square_Area
d. Sphere_Area
e. Sphere_Volume
f. Cube_Volume
Write a procedure to declare a character & constant number and do the following:
a. If the character is ‘R’ assuming that the constant number is a radius, calculate the
area of the circle , sphere and the volume of the sphere it will form.
b. If the character is ‘L’ assuming that the constant number is the length of the side
of a square, calculate the area of the square it will form and the volume of the
cube it will form.
Constant_1 (Integer)
Constant_2 (Integer)
a. Input_Value1
b. Input_Value2
c. Circle_Area
d. Square_Area
e. Cylinder_Volume
f. Rectangle_Area
g. Sphere_Area
h. Sphere_Volume
i. Cube_Volume
a. Declare a cursor
b. Read the rows one by one into the cursor ROWTYPE variable
c. If both the constants have a value in that row,
i) Assume them to be the length and breadth of a rectangle and calculate the
area.
ii) Assume them to be the radius and height of a cylinder and calculate the
volume.
iii) Assuming the 1st value to be the radius, do as in the prior exercise
iv) Assuming the 1st value to be the side of the square, do as in the prior
exercise
After calculation, insert the values into the “Areas” table. Repeat the process for all the rows
in the “Constant_Values” table. Close the cursor.
PART - 2 : Developer 2000 (Forms)
10. Student Information Systems
Problem Description :
d. Use appropriate interface items like radio group for gender column, list box for
branch of study.
Academic details:
Validation :
Use appropriate items like LOVs, push buttons, text items, display items, radio group etc.
Note: Calculate age of each student from his or her date of birth.
11. Payroll System
Problem Description:
Validations:
1. Payroll Reports
Problem Description:
2. Student Reports
Problem Description:
Sales_Transaction
VAT_Calculation
1. Whenever an insert happens to the Sales_Transaction table, the VAT for the price
should be calculated and inserted into the VAT_Calculation table.
UPDATE tablename
SET columnname = expression, columnname = expression
WHERE columnname = expression;
Deletion:
SELECT columnname,columnname
FROM tablename
ORDERBY columnname,columnname;
SELECT columnname,columnname
FROM tablename,
GROUPBY columnname,columnname;
Indexes:
Dropping Indexes:
Destroying a View:
Cursors:
Declaration :
Cursor Handling :
1. OPEN <CURSOR_NAME>;
2. FETCH <CURSOR_NAME> INTO <COLUMN-NAME(S)>;
3. CLOSE <CURSOR_NAME>;
Explicit cursor is one in which cursor name is explicitly assigned to the select statement.
Implicit cursor is used for all other SQL statement.
Subprograms :
(i) procedures:
(ii) Functions:
A function should return a value to the called block whereas a procedure will not return any
value.
Triggers :
Trigger is a stored procedure that is fired when a DML statement is issued against the
associated table.
****************************