CSE302_Lab02_final
CSE302_Lab02_final
Lab Objective
Familiarize students with intermediate level DDL commands and simple DML statements in SQL.
Lab Outcome
After completing this lab successfully, students will be able to:
1. Understand and execute DDL commands to define integrity constraints and modify the database
schema.
2. Construct DML statements to perform queries involving distinct keyword, generalized projection,
simple multi-table queries and so on.
Psychomotor Learning Levels
This lab involves activities that encompass the following learning levels in psychomotor domain.
Level Category Meaning Keywords
Lab Activities
2. Schema Modification
Adding a new attribute:
ALTER TABLE <table_name> ADD <attribute_name> <datatype>;
Dropping an attribute:
ALTER TABLE <table_name> DROP column <attribute_name>;
Modifying data type of an attribute (Column must be empty/has no values):
ALTER TABLE <table_name> MODIFY <attribute_name> <new_type>;
Renaming an attribute:
ALTER TABLE <table_name> RENAME column <attribute_name> to
<new_attribute_name>;
Renaming a table:
ALTER TABLE <table_name> RENAME TO <new_table_name>;
Adding a constraint into a table (primary key constraint, foreign key constraint): ALTER
TABLE <table_name> ADD CONSTRAINT <constraint_name>
<constraint>;
Deleting a constraint from a table:
ALTER TABLE <table_name> DROP CONSTRAINT <constraint_name>;
Checking all constraints:
SELECT * FROM user_cons_columns WHERE TABLE_NAME =
<table_name>;
Dropping a Table (both data and schema):
DROP TABLE <table_name>;
Multi-table queries
Cartesian product:
select *
from instructor, department;
This generates many tuples which are not meaningful. To get the meaningful tuples, you need to
write:
select *
from instructor, department;
where instructor.dept_name = department.dept_name;
Natural join:
select * from instructor natural join department;
East West University
Department of Computer Science and Engineering
You must write all SQL statements in notepad first and save them with .sql extension.
Then execute your SQL scripts.
Write SQL statements to create the following tables with the given constraints.
i) account
account_no char(5) primary key
ii) customer
customer_no char(5) primary key
customer_city varchar2(10)
iii) depositor
account_no char(5)
customer_no char(5)
After executing each of these SQL statements execute the command – desc <table_name> to confirm the
changes.
i. Write SQL statement to add a new attribute ‘date_of_birth’ (date type) in customer table. ii. Write
SQL statement to drop the attribute ‘date_of_birth’ from customer table. iii. Write SQL statement to
rename the attribute account_no, customer_no from depositor table to a_no and c_no, respectively.
iv. Write SQL statements to add two foreign key constraints ‘depositor_fk1’ and ‘depositor_fk2’ which
identifies a_no and c_no as a foreign key.
Lab Task # 03 (Inserting Records into Tables):
Submission
Take screenshots of the execution and result of your queries in SQLPlus Tool and insert the captured image
in a doc file for each and every question . Submit both doc and sql file in the given submission link in the
Classroom. Submit files separately. Name the file as per the following format: 2022-1-60-001_LAB02.pdf
and 2022-1-60-001.sql_LAB02.