Explore essential concepts and practical uses of sequences, indexes, and synonyms in PL/SQL with this quiz tailored for those seeking to strengthen their foundational understanding. Covered topics include creation, benefits, and syntax details related to database object management for efficient development and querying.
Which best describes the purpose of a sequence in PL/SQL for generating values in a table?
Explanation: Sequences are used to automatically create a unique set of numbers, often for primary keys or other unique identifiers in tables. Sorting table records is handled by queries, not sequences. Creating duplicate rows does not involve sequences. Encryption concerns data security, not value generation.
Which statement correctly creates a sequence named EMP_SEQ that starts at 1 and increments by 1?
Explanation: The correct syntax uses CREATE SEQUENCE followed by the sequence name with START WITH and INCREMENT BY clauses. The option using CREATE INDEX incorrectly refers to indexes, not sequences. The SYNONYM statement defines aliases, and the fourth option uses incorrect keywords for sequence creation.
What is the primary function of an index in a table in PL/SQL databases?
Explanation: Indexes are used to speed up the retrieval of rows by providing fast access paths to the data. Assigning default values involves table or column definitions. Backups concern data safety, not search performance. Unique identifiers are managed by constraints or sequences.
When inserting data, how can you use a sequence named ORD_SEQ to get the next available value?
Explanation: NEXTVAL is the method used to retrieve the next available sequence value, making it suitable for inserting new rows. CURRVAL returns the current value, but only after NEXTVAL is called in the session. LASTVAL and NEXTNUMBER are not valid sequence keywords in PL/SQL.
Which command creates a synonym named EMP for the table EMPLOYEES?
Explanation: CREATE SYNONYM EMP FOR EMPLOYEES creates a public or private synonym EMP for easier referencing of the EMPLOYEES table. SEQUENCE and INDEX keywords do not create synonyms. The last option reverses the table and synonym names, which is incorrect.
Which command correctly removes an index named IDX_DEPT?
Explanation: The DROP INDEX statement is used to remove an index. DROP SEQUENCE is used for sequences, not indexes. DELETE and REMOVE are not valid commands for dropping indexes in PL/SQL.
In which situation can CURRVAL of a sequence be successfully referenced within a session?
Explanation: CURRVAL returns the current value only after NEXTVAL has been used in the session to generate a value. Using CURRVAL before any NEXTVAL results in an error. If the sequence does not exist or has never been used, CURRVAL cannot be referenced.
Which type of index automatically enforces uniqueness on the indexed column(s)?
Explanation: A unique index ensures that no duplicate values exist in the indexed columns. Bitmap and non-unique indexes do not enforce uniqueness, and 'clustered index' is not a standard term in PL/SQL.
What is a key benefit of creating a public synonym for a database object?
Explanation: Public synonyms make it possible for all users to access the object without specifying its owner or schema. They don't restrict access or inherently improve performance. Making an object read-only requires different permissions or constraints.
Which statement about altering an existing sequence’s increment value is correct?
Explanation: ALTER SEQUENCE allows changes to properties like INCREMENT BY for a sequence. Dropping and recreating is unnecessary unless more drastic changes are needed. The value is not permanently fixed. ALTER INDEX has no effect on sequences.