Practica3-2 lsbdII 2021 2
Practica3-2 lsbdII 2021 2
Practice 2
Reference 1:
1. Oracle Database 11g: SQL Fundamentals.
Reference 2:
2. Oracle Database SQL Language Reference 11g.
Reference 3:
Initial activity:
Read the entire file first. Write the corresponding report. Start with the Introduction
section.
Activity 1:
Write the section that describes the Work developed in the following activities.
Página 1 de 11
Practice 2
Universidad Autónoma de Zacatecas
Unidad Académica de Ingeniería Eléctrica
Programa Académico de Ingeniería de Software
Read all the choices carefully because there might be more than one correct answer.
Choose all the correct answers for each question. If necessary, investigate some answers.
Explain the reason for your answer.
Categorize the Main Database Objects
1. If a table is created without specifying a schema, in which schema will it be?
(Choose the best answer). Challenge question.
A. It will be an orphaned table, without a schema.
B. The creation will fail.
C. It will be in the SYS schema.
D. It will be in the schema of the user creating it.
E. It will be in the PUBLIC schema.
2. Several object types share the same namespace, and therefore cannot have the
same name in the same schema. Which of the following object types is not in the
same namespace as the others? (Choose the best answer). Challenge question.
A. Index
B. PL/SQL stored procedure
C. Synonym
D. Table
E. View
3. Which of these statements will fail because the table name is not legal? (Choose
two answers.)
A. create table “WHERE” (col1 date);
B. create table “mincase” (col1 date);
C. create table 1var (col1 date);
D. create table var1 (col1 date);
E. create table delete (col1 date);
List the Data Types that Are Available for Columns
4. Which of the following data types are variable length? (Choose all correct
answers.)
A. BLOB
B. CHAR
C. LONG
D. NUMBER
E. RAW
F. VARCHAR2
5. Study these statements:
create table tab1 (c1 number(1), c2 date);
alter session set nls_date_format='dd-mm-yy';
insert into tab1 values (2.2,’29-07-09’);
Will the insert succeed? (Choose the best answer)
A. The insert will fail because the 2.2 is too long.
Página 2 de 11
Practice 2
Universidad Autónoma de Zacatecas
Unidad Académica de Ingeniería Eléctrica
Programa Académico de Ingeniería de Software
B. The insert will fail because the ’29-07-09’ is a string, not a date.
C. The insert will fail for both reasons A and B.
D. The insert will succeed.
6. Which of the following is not supported by Oracle as an internal data type?
(Choose the best answer.)
A. CHAR
B. FLOAT
C. INTEGER
D. STRING
Create a Simple Table
7. Consider this statement:
create table t1 as select * from employees where 9=4;
What will be the result? (Choose the best answer.)
A. There will be an error because of the impossible condition.
B. No table will be created because the condition returns FALSE.
C. The table T1 will be created but no rows inserted because the condition returns
FALSE.
D. The table T1 will be created and every row in EMPLOYEES inserted because the
condition returns a NULL as a row filter.
8. When a table is created with a statement such as the following:
create table newtable as select * from oldtable; will there be any constraints on the
new table? (Choose the best answer.)
A. The new table will have no constraints, because constraints are not copied when
creating tables with a subquery.
B. All the constraints on TAB will be copied to NEWTABLE.
C. Primary key and unique constraints will be copied but not check and not null
constraints.
D. Check and not null constraints will be copied but not unique or primary key.
E. All constraints will be copied, except foreign key constraints.
Explain How Constraints Are Created at the Time of Table Creation
9. Which types of constraint require an index? (Choose all that apply.)
A. CHECK
B. NOT NULL
C. PRIMARY KEY
D. UNIQUE
10. A transaction consists of two statements. The first succeeds, but the second
(which updates several rows) fails partway through because of a constraint
violation. What will happen? (Choose the best answer). Challenge question.
A. The whole transaction will be rolled back.
B. The second statement will be rolled back completely, and the first will be committed.
C. The second statement will be rolled back completely, and the first will remain
uncommitted.
Página 3 de 11
Practice 2
Universidad Autónoma de Zacatecas
Unidad Académica de Ingeniería Eléctrica
Programa Académico de Ingeniería de Software
D. Only the one update that caused the violation will be rolled back; everything else will
be committed.
E. Only the one update that caused the violation will be rolled back; everything else will
remain uncommitted.
Activity 2:
Write the section that describes the Work developed in the following activities.
Create Tables
In this exercise, use SQL Developer to create a heap table, insert some rows with a
subquery, and modify the table. Do some more modifications with SQL*Plus, then drop
the table.
1. Connect to the database as user HR with SQL Developer.
2. Right-click the Tables branch of the navigation tree, and click New Table.
3. Name the new table EMPS, and use the Add Column button to set it up as in the
following illustration:
4. Click the DDL tab to see if the statement that has been constructed. It should look like
this:
CREATE TABLE EMPS(
EMPNO NUMBER,
ENAME VARCHAR2(25),
Página 5 de 11
Practice 2
Universidad Autónoma de Zacatecas
Unidad Académica de Ingeniería Eléctrica
Programa Académico de Ingeniería de Software
SALARY NUMBER,
DEPTNO NUMBER(4, 0));
Return to the Table tab (as in the preceding illustration) and click OK to create the table.
5. Run this statement:
insert into emps select employee_id,last_name,salary,department_id
from employees;
and commit the insert:
commit;
6. Right-click the EMPS table in the SQL Developer navigator, click Column and Add.
7. Define a new column HIRED, type DATE, as in the following illustration below; and
click Apply to create the column.
Página 6 de 11
Practice 2
Universidad Autónoma de Zacatecas
Unidad Académica de Ingeniería Eléctrica
Programa Académico de Ingeniería de Software
Consider this simple analysis of a call record system in a local telephone company:
A subscriber is identified by a customer number and also has a name, last name, date of
birth, address, rfc, 1 or 2 references (friends or relatives) and possibly one or more
telephones. A telephone is identified by its number, which must be a 10-digit integer
beginning with 55, an activation date, and a flag (‘A’ or ‘I’) for whether it is active.
Inactive telephones are not assigned to a subscriber; active telephones are. These
subscribers are associated to physical telephones, and also have a brand, capacity
(memory, cpu, display, camera, …) and serial number. Besides, all telephones are
engaged with a forced plan: 6, 12, 18 or 24 months. It is necessary to store the start and
Página 7 de 11
Practice 2
Universidad Autónoma de Zacatecas
Unidad Académica de Ingeniería Eléctrica
Programa Académico de Ingeniería de Software
final date of it (when this is hired). For every call, it is necessary to record the time it
started and the time it finished.
Activity 4:
Write the section that describes the Work developed in the following activities.
Activity 5:
Write the section that describes the Work developed in the following activities.
Carry out the following steps (capture an image for each statement output):
• Create the EMPLOYEES_2 table based on the EMPLOYEES table from HR
scheme.
Use the CREATE statement that employs a SELECT statement.
• Describe the table structure.
• Alter the EMPLOYEES_2 table status to read-only.
• Try to insert a row the table. Depict the results.
• Revert the EMPLOYEES_2 table to the write status. Now, try to insert the same
row again. Depict the results.
• Drop the EMPLOYEES_ table.
Activity 6:
Write the section that describes the Work developed in the following activities.
Página 8 de 11
Practice 2
Universidad Autónoma de Zacatecas
Unidad Académica de Ingeniería Eléctrica
Programa Académico de Ingeniería de Software
Página 9 de 11
Practice 2
Universidad Autónoma de Zacatecas
Unidad Académica de Ingeniería Eléctrica
Programa Académico de Ingeniería de Software
Another case:
ü ALTER TABLE products DROP CONSTRAINT fk_supplier;
ü ALTER TABLE supplier ADD CONSTRAINT supplier_unique UNIQUE
(supplier_id);
ü ALTER TABLE supplier DISABLE CONSTRAINT supplier_unique;
Activity 7:
Write the section that describes the Work developed in the following activities.
Complete the following ER diagram with the corresponding attributes. The main idea is:
an employee (with their personal data) works on a specific job, which initiated in a
particular date/hour with a description and status. This job is carried out in a branch, in
which the task is located. Thus, a supervisor manages the entire task with a specific date
of assignment.
Taking into account your final E-R diagram of activity 2 of practice 1 (Bank scenario).
Generate the corresponding DDL statements. Don`t forget to consider:
• CREATE table statements are the first to be applied. In this case, the basic
constraints must be performed here: not null, default, …
• Use ALTER table statements to add primary and foreign keys.
• Generate automatically the corresponding relational model using Data Modeler
(dragging tables using GUI).
• Compare the results with practice 1.
Activity 9:
Write the Pre-assessment section.
Final activity:
Write the Conclusion section.
e-mail: [email protected]
Página 11 de 11
Practice 2